#631 - Partial Response : Add java doc
This commit is contained in:
@@ -24,7 +24,16 @@
|
||||
|
||||
package com.iluwatar.partialresponse;
|
||||
|
||||
/**
|
||||
* Map a video to json
|
||||
*/
|
||||
public class FieldJsonMapper {
|
||||
|
||||
/**
|
||||
* @param video object containing video information
|
||||
* @param fields fields information to get
|
||||
* @return json of required fields from video
|
||||
*/
|
||||
public String toJson(Video video, String[] fields) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -53,15 +53,18 @@ public class Video {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return json representaion of video
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" +
|
||||
"\"id\": \"" + id + "\"," +
|
||||
"\"title\": \"" + title + "\"," +
|
||||
"\"length\": " + length + "," +
|
||||
"\"description\": \"" + description + "\"," +
|
||||
"\"director\": \"" + director + "\"," +
|
||||
"\"language\": \"" + language + "\"," +
|
||||
"}";
|
||||
return "{"
|
||||
+ "\"id\": \"" + id + "\","
|
||||
+ "\"title\": \"" + title + "\","
|
||||
+ "\"length\": " + length + ","
|
||||
+ "\"description\": \"" + description + "\","
|
||||
+ "\"director\": \"" + director + "\","
|
||||
+ "\"language\": \"" + language + "\","
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
@@ -26,15 +26,28 @@ package com.iluwatar.partialresponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The resource class which serves video information.
|
||||
* This class act as server in the demo. Which has all video details.
|
||||
*/
|
||||
public class VideoResource {
|
||||
private FieldJsonMapper fieldJsonMapper;
|
||||
private Map<Integer, Video> videos;
|
||||
|
||||
/**
|
||||
* @param fieldJsonMapper map object to json.
|
||||
* @param videos initialize resource with existing videos. Act as database.
|
||||
*/
|
||||
public VideoResource(FieldJsonMapper fieldJsonMapper, Map<Integer, Video> videos) {
|
||||
this.fieldJsonMapper = fieldJsonMapper;
|
||||
this.videos = videos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id video id
|
||||
* @param fields fields to get information about
|
||||
* @return json of specified fields of particular video by id
|
||||
*/
|
||||
public String getDetails(Integer id, String... fields) {
|
||||
if (fields.length == 0) {
|
||||
return videos.get(id).toString();
|
||||
|
Reference in New Issue
Block a user