001package com.box.sdk;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import com.eclipsesource.json.JsonArray;
007import com.eclipsesource.json.JsonObject;
008import com.eclipsesource.json.JsonValue;
009
010/**
011 * Contains the list of parts of a large file that are already uploaded.
012 * It also contains a offset to represent the paging.
013 */
014public class BoxFileUploadSessionPartList extends BoxJSONObject {
015
016    private List<BoxFileUploadSessionPart> entries;
017    private int offset;
018    private int limit;
019    private int totalCount;
020
021    /**
022     * Constructs an BoxFileUploadSessionPart object using an already parsed JSON object.
023     * @param  jsonObject the parsed JSON object.
024     */
025    BoxFileUploadSessionPartList(JsonObject jsonObject) {
026        super(jsonObject);
027    }
028
029    /**
030     * Returns the list of parts that are already uploaded.
031     * @return the list of parts.
032     */
033    public List<BoxFileUploadSessionPart> getEntries() {
034        return this.entries;
035    }
036
037    /**
038     * Returns the paging offset for the list of parts.
039     * @return the paging offset.
040     */
041    public int getOffset() {
042        return this.offset;
043    }
044
045    /**
046     * Returns the limit on number of entires in a response.
047     * @return the limit
048     */
049    public int getLimit() {
050        return this.limit;
051    }
052
053    /**
054     * Returns the total count of entries.
055     * @return the toal count of entries
056     */
057    public int getTotalCount() {
058        return this.totalCount;
059    }
060
061    @Override
062    protected void parseJSONMember(JsonObject.Member member) {
063        String memberName = member.getName();
064        JsonValue value = member.getValue();
065        if (memberName.equals("entries")) {
066            JsonArray array = (JsonArray) value;
067
068            if (array.size() > 0) {
069                this.entries = this.getParts(array);
070            }
071        } else if (memberName.equals("offset")) {
072            this.offset = Double.valueOf(value.toString()).intValue();
073        } else if (memberName.equals("limit")) {
074            this.limit = Double.valueOf(value.toString()).intValue();
075        } else if (memberName.equals("total_count")) {
076            this.totalCount = Double.valueOf(value.toString()).intValue();
077        }
078    }
079
080    /*
081     * Creates List of parts from the JSON array
082     */
083    private List<BoxFileUploadSessionPart> getParts(JsonArray partsArray) {
084        List<BoxFileUploadSessionPart> parts = new ArrayList<BoxFileUploadSessionPart>();
085        for (JsonValue value: partsArray) {
086            BoxFileUploadSessionPart part = new BoxFileUploadSessionPart((JsonObject) value);
087            parts.add(part);
088        }
089        return parts;
090    }
091}