11package com .box .sdk ;
22
3- import java .util .List ;
4-
53import com .eclipsesource .json .JsonObject ;
6- import com .eclipsesource .json .JsonValue ;
74
85/**
96 * The abstract base class for all resource types (files, folders, comments, collaborations, etc.) used by the API.
@@ -79,30 +76,28 @@ public int hashCode() {
7976 *
8077 * @param <T> the type of the resource associated with this info.
8178 */
82- public abstract class Info <T extends BoxResource > {
83- private JsonObject pendingChanges ;
84-
79+ public abstract class Info <T extends BoxResource > extends BoxJSONObject {
8580 /**
8681 * Constructs an empty Info object.
8782 */
8883 public Info () {
89- this . pendingChanges = new JsonObject ();
84+ super ();
9085 }
9186
9287 /**
9388 * Constructs an Info object by parsing information from a JSON string.
9489 * @param json the JSON string to parse.
9590 */
9691 public Info (String json ) {
97- this ( JsonObject . readFrom ( json ) );
92+ super ( json );
9893 }
9994
10095 /**
10196 * Constructs an Info object using an already parsed JSON object.
10297 * @param jsonObject the parsed JSON object.
10398 */
10499 protected Info (JsonObject jsonObject ) {
105- this . updateFromJSON (jsonObject );
100+ super (jsonObject );
106101 }
107102
108103 /**
@@ -113,69 +108,10 @@ public String getID() {
113108 return BoxResource .this .getID ();
114109 }
115110
116- /**
117- * Gets a list of fields that have pending changes that haven't been sent to the API yet.
118- * @return a list of changed fields with pending changes.
119- */
120- public List <String > getChangedFields () {
121- return this .pendingChanges .names ();
122- }
123-
124- /**
125- * Gets a JSON object of any pending changes.
126- * @return a JSON object containing the pending changes.
127- */
128- public String getPendingChanges () {
129- return this .pendingChanges .toString ();
130- }
131-
132111 /**
133112 * Gets the resource associated with this Info.
134113 * @return the associated resource.
135114 */
136115 public abstract T getResource ();
137-
138- /**
139- * Adds a pending field change that needs to be sent to the API. It will be included in the JSON string the next
140- * time {@link #getPendingChanges} is called.
141- * @param key the name of the field.
142- * @param value the new value of the field.
143- */
144- protected void addPendingChange (String key , JsonValue value ) {
145- this .pendingChanges .set (key , value );
146- }
147-
148- /**
149- * Clears all pending changes.
150- */
151- protected void clearPendingChanges () {
152- this .pendingChanges = new JsonObject ();
153- }
154-
155- /**
156- * Updates this Info object using the information in a JSON object.
157- * @param jsonObject the JSON object containing updated information.
158- */
159- protected void updateFromJSON (JsonObject jsonObject ) {
160- for (JsonObject .Member member : jsonObject ) {
161- if (member .getValue ().isNull ()) {
162- continue ;
163- }
164-
165- this .parseJSONMember (member );
166- }
167-
168- this .clearPendingChanges ();
169- }
170-
171- /**
172- * Invoked with a JSON member whenever this Info object is updated or created from a JSON object.
173- *
174- * <p>Subclasses should override this method in order to parse any JSON members it knows about. This method is a
175- * no-op by default.</p>
176- *
177- * @param member the JSON member to be parsed.
178- */
179- protected void parseJSONMember (JsonObject .Member member ) { }
180116 }
181117}
0 commit comments