Java 11 migrate remaining p (#1122)
* Moves partial-response to Java 11 * Moves pipeline to Java 11 * Moves poison-pill to Java 11 * Moves priority-queue to Java 11 * Moves private-class-data to Java 11 * Moves producer-consumer to Java 11 * Moves promise to Java 11 * Moves property to Java 11 * Moves prototype to Java 11 * Moves proxy to Java 11 * Corrects checkstyle errors * Fixes build for pipeline pattern
This commit is contained in:
committed by
Ilkka Seppälä
parent
1401accb4f
commit
428efc7d53
@@ -44,30 +44,31 @@ public class App {
|
||||
* @param args program argument.
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
Map<Integer, Video> videos = Map.of(
|
||||
var videos = Map.of(
|
||||
1, new Video(1, "Avatar", 178, "epic science fiction film",
|
||||
"James Cameron", "English"),
|
||||
2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|",
|
||||
"Hideaki Anno", "Japanese"),
|
||||
3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi",
|
||||
"Christopher Nolan", "English"));
|
||||
VideoResource videoResource = new VideoResource(new FieldJsonMapper(), videos);
|
||||
"Christopher Nolan", "English")
|
||||
);
|
||||
var videoResource = new VideoResource(new FieldJsonMapper(), videos);
|
||||
|
||||
|
||||
LOGGER.info("Retrieving full response from server:-");
|
||||
LOGGER.info("Get all video information:");
|
||||
String videoDetails = videoResource.getDetails(1);
|
||||
var videoDetails = videoResource.getDetails(1);
|
||||
LOGGER.info(videoDetails);
|
||||
|
||||
LOGGER.info("----------------------------------------------------------");
|
||||
|
||||
LOGGER.info("Retrieving partial response from server:-");
|
||||
LOGGER.info("Get video @id, @title, @director:");
|
||||
String specificFieldsDetails = videoResource.getDetails(3, "id", "title", "director");
|
||||
var specificFieldsDetails = videoResource.getDetails(3, "id", "title", "director");
|
||||
LOGGER.info(specificFieldsDetails);
|
||||
|
||||
LOGGER.info("Get video @id, @length:");
|
||||
String videoLength = videoResource.getDetails(3, "id", "length");
|
||||
var videoLength = videoResource.getDetails(3, "id", "length");
|
||||
LOGGER.info(videoLength);
|
||||
}
|
||||
}
|
||||
|
@@ -38,13 +38,16 @@ public class FieldJsonMapper {
|
||||
* @return json of required fields from video
|
||||
*/
|
||||
public String toJson(Video video, String[] fields) throws Exception {
|
||||
StringBuilder json = new StringBuilder().append("{");
|
||||
var json = new StringBuilder().append("{");
|
||||
|
||||
for (int i = 0, fieldsLength = fields.length; i < fieldsLength; i++) {
|
||||
var i = 0;
|
||||
var fieldsLength = fields.length;
|
||||
while (i < fieldsLength) {
|
||||
json.append(getString(video, Video.class.getDeclaredField(fields[i])));
|
||||
if (i != fieldsLength - 1) {
|
||||
json.append(",");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
json.append("}");
|
||||
return json.toString();
|
||||
@@ -52,7 +55,7 @@ public class FieldJsonMapper {
|
||||
|
||||
private String getString(Video video, Field declaredField) throws IllegalAccessException {
|
||||
declaredField.setAccessible(true);
|
||||
Object value = declaredField.get(video);
|
||||
var value = declaredField.get(video);
|
||||
if (declaredField.get(video) instanceof Integer) {
|
||||
return "\"" + declaredField.getName() + "\"" + ": " + value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user