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