Skip to content

Commit

Permalink
Cleaned up methods to create entity ids from JSON (part 2)
Browse files Browse the repository at this point in the history
I forgot two methods in the earlier commit.
  • Loading branch information
mkroetzsch committed Mar 18, 2014
1 parent 0490c47 commit 111e67d
Showing 1 changed file with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private ItemIdValue getItemIdFromTopLevel(JSONObject topLevel)
JSONArray entityJsonArray = topLevel.optJSONArray(KEY_ENTITY);

if (entityJsonArray != null) { // it is an array
itemId = this.getItemId(entityJsonArray);
itemId = this.getItemIdValue(entityJsonArray);
} else { // it is a String
String stringItemId = topLevel.getString(KEY_ENTITY);
itemId = this.getItemIdValue(stringItemId);
Expand Down Expand Up @@ -267,7 +267,7 @@ private PropertyIdValue getPropertyIdFromTopLevel(JSONObject topLevel)
JSONArray entityJsonArray = topLevel.optJSONArray(KEY_ENTITY);

if (entityJsonArray != null) { // it is an array
propertyId = this.getPropertyId(entityJsonArray);
propertyId = this.getPropertyIdValue(entityJsonArray);
} else { // it is a String
String stringItemId = topLevel.getString(KEY_ENTITY);
propertyId = this.getPropertyIdValue(stringItemId);
Expand All @@ -276,17 +276,19 @@ private PropertyIdValue getPropertyIdFromTopLevel(JSONObject topLevel)
}

/**
* Constructs the item id of a JSON array denoting an entity.
* Creates an ItemIdValue from a JSON array that represents an item in JSON.
*
* @param jsonEntity
* a JSON array containing information about the item; The array
* should have the structure ["item", itemId]
* @return an ItemIdValue with the according prefix.
* a JSON array containing information about the item; the array
* should have the structure ["item", itemId] where itemId is an
* integer
* @return the corresponding ItemIdValue
* @throws JSONException
* if the entity does not contain an "item" entry or the entry
* is not followed by an integer denoting the item id
* if the entity does not contain an "item" entry or the id does
* not have the correct format
*/
private ItemIdValue getItemId(JSONArray jsonEntity) throws JSONException {
private ItemIdValue getItemIdValue(JSONArray jsonEntity)
throws JSONException {

String entityTypeIndicator = jsonEntity.getString(0);
if (!entityTypeIndicator.equalsIgnoreCase("item")) {
Expand All @@ -300,17 +302,19 @@ private ItemIdValue getItemId(JSONArray jsonEntity) throws JSONException {
}

/**
* Constructs the property id of a JSON array denoting an entity.
* Creates a PropertyIdValue from a JSON array that represents a property in
* JSON.
*
* @param jsonEntity
* a JSON array containing information about the property; The
* array should have the structure ["property", propertyId]
* @return an PropertyIdValue with the according prefix.
* a JSON array containing information about the property; the
* array should have the structure ["property", propertyId] where
* propertyId is an integer
* @return the corresponding PropertyIdValue
* @throws JSONException
* if the entity does not contain an "property" entry or the
* entry is not followed by an integer denoting the property id
* if the entity does not contain an "property" entry or the id
* does not have the correct format
*/
private PropertyIdValue getPropertyId(JSONArray jsonEntity)
private PropertyIdValue getPropertyIdValue(JSONArray jsonEntity)
throws JSONException {

String entityTypeIndicator = jsonEntity.getString(0);
Expand All @@ -336,7 +340,6 @@ private PropertyIdValue getPropertyId(JSONArray jsonEntity)
* @throws JSONException
*/
private ItemIdValue getItemIdValue(String id) throws JSONException {

try {
return this.factory.getItemIdValue(id.toUpperCase(), this.baseIri);
} catch (IllegalArgumentException e) { // invalid id format
Expand All @@ -355,7 +358,6 @@ private ItemIdValue getItemIdValue(String id) throws JSONException {
* @throws JSONException
*/
private PropertyIdValue getPropertyIdValue(String id) throws JSONException {

try {
return this.factory.getPropertyIdValue(id.toUpperCase(),
this.baseIri);
Expand Down

0 comments on commit 111e67d

Please sign in to comment.