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 marker to represent the paging.
013 */
014public class BoxFileUploadSessionPartList extends BoxJSONObject {
015
016    private List<BoxFileUploadSessionPart> parts;
017    private int marker;
018
019    /**
020     * Constructs an BoxFileUploadSessionPart object using an already parsed JSON object.
021     * @param  jsonObject the parsed JSON object.
022     */
023    BoxFileUploadSessionPartList(JsonObject jsonObject) {
024        super(jsonObject);
025    }
026
027    /**
028     * Returns the list of parts that are already uploaded.
029     * @return the list of parts.
030     */
031    public List<BoxFileUploadSessionPart> getParts() {
032        return this.parts;
033    }
034
035    /**
036     * Returns the paging marker for the list of parts.
037     * @return the paging marker.
038     */
039    public int getMarker() {
040        return this.marker;
041    }
042
043    @Override
044    protected void parseJSONMember(JsonObject.Member member) {
045        String memberName = member.getName();
046        JsonValue value = member.getValue();
047        if (memberName.equals("parts")) {
048            JsonArray array = (JsonArray) value;
049
050            if (array.size() > 0) {
051                this.parts = this.getParts(array);
052            }
053        } else if (memberName.equals("marker")) {
054            this.marker = Double.valueOf(value.toString()).intValue();
055        }
056    }
057
058    /*
059     * Creates List of parts from the JSON array
060     */
061    private List<BoxFileUploadSessionPart> getParts(JsonArray partsArray) {
062        List<BoxFileUploadSessionPart> parts = new ArrayList<BoxFileUploadSessionPart>();
063        for (JsonValue value: partsArray) {
064            BoxFileUploadSessionPart part = new BoxFileUploadSessionPart((JsonObject) value);
065            parts.add(part);
066        }
067
068        return parts;
069    }
070}