Skip to content

Commit 6c75538

Browse files
committed
Make BoxResource.Info a subclass of BoxJSONObject
1 parent 988d443 commit 6c75538

File tree

4 files changed

+8
-72
lines changed

4 files changed

+8
-72
lines changed

src/main/java/com/box/sdk/BoxFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void updateInfo(BoxFile.Info info) {
109109
request.setBody(info.getPendingChanges());
110110
BoxJSONResponse response = (BoxJSONResponse) request.send();
111111
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
112-
info.updateFromJSON(jsonObject);
112+
info.update(jsonObject);
113113
}
114114

115115
public Collection<BoxFileVersion> getVersions() {

src/main/java/com/box/sdk/BoxFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void updateInfo(BoxFolder.Info info) {
4848
request.setBody(info.getPendingChanges());
4949
BoxJSONResponse response = (BoxJSONResponse) request.send();
5050
JsonObject jsonObject = JsonObject.readFrom(response.getJSON());
51-
info.updateFromJSON(jsonObject);
51+
info.update(jsonObject);
5252
}
5353

5454
public BoxFolder.Info copy(BoxFolder destination) {

src/main/java/com/box/sdk/BoxItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public String getName() {
5555

5656
public void setName(String name) {
5757
this.name = name;
58-
this.addPendingChange("name", JsonValue.valueOf(name));
58+
this.addPendingChange("name", name);
5959
}
6060

6161
public Date getCreatedAt() {
@@ -72,7 +72,7 @@ public String getDescription() {
7272

7373
public void setDescription(String description) {
7474
this.description = description;
75-
this.addPendingChange("description", JsonValue.valueOf(description));
75+
this.addPendingChange("description", description);
7676
}
7777

7878
public long getSize() {

src/main/java/com/box/sdk/BoxResource.java

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.box.sdk;
22

3-
import java.util.List;
4-
53
import 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

Comments
 (0)