Skip to content

Commit

Permalink
Pick up minimal-json 0.9.0
Browse files Browse the repository at this point in the history
Incorporate the latest improvements and the fix for issue 16 [1] in
minimal-json.

[1] ralfstx/minimal-json#16
  • Loading branch information
ralfstx committed Oct 11, 2013
1 parent fbd00c5 commit aa82071
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ private JsonArray( JsonArray array, boolean unmodifiable ) {

/**
* Reads a JSON array from the given reader.
* <p>
* Characters are read in chunks and buffered internally, therefore wrapping an existing reader in
* an additional <code>BufferedReader</code> does <strong>not</strong> improve reading
* performance.
* </p>
*
* @param reader
* the reader to read the JSON array from
Expand Down Expand Up @@ -132,6 +137,18 @@ public static JsonArray unmodifiableArray( JsonArray array ) {
return new JsonArray( array, true );
}

/**
* Adds the JSON representation of the specified <code>int</code> value to the array.
*
* @param value
* the value to add to the array
* @return the array itself, to enable method chaining
*/
public JsonArray add( int value ) {
values.add( valueOf( value ) );
return this;
}

/**
* Adds the JSON representation of the specified <code>long</code> value to the array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ private JsonObject( JsonObject object, boolean unmodifiable ) {

/**
* Reads a JSON object from the given reader.
* <p>
* Characters are read in chunks and buffered internally, therefore wrapping an existing reader in
* an additional <code>BufferedReader</code> does <strong>not</strong> improve reading
* performance.
* </p>
*
* @param reader
* the reader to read the JSON object from
Expand Down Expand Up @@ -145,6 +150,28 @@ public static JsonObject unmodifiableObject( JsonObject object ) {
return new JsonObject( object, true );
}

/**
* Adds a new member at the end of this object, with the specified name and the JSON
* representation of the specified <code>int</code> value.
* <p>
* This method <strong>does not prevent duplicate names</strong>. Adding a member with a name that
* already exists in the object will add another member with the same name. In order to replace
* existing members, use the method <code>set(name, value)</code> instead. However, <strong>
* <em>add</em> is much faster than <em>set</em></strong> (because it does not need to search for
* existing members). Therefore <em>add</em> should be preferred when constructing new objects.
* </p>
*
* @param name
* the name of the member to add
* @param value
* the value of the member to add
* @return the object itself, to enable method chaining
*/
public JsonObject add( String name, int value ) {
add( name, valueOf( value ) );
return this;
}

/**
* Adds a new member at the end of this object, with the specified name and the JSON
* representation of the specified <code>long</code> value.
Expand Down Expand Up @@ -285,6 +312,28 @@ public JsonObject add( String name, JsonValue value ) {
return this;
}

/**
* Sets the value of the member with the specified name to the JSON representation of the
* specified <code>int</code> value. If this object does not contain a member with this name, a
* new member is added at the end of the object. If this object contains multiple members with
* this name, only the last one is changed.
* <p>
* This method should <strong>only be used to modify existing objects</strong>. To fill a new
* object with members, the method <code>add(name, value)</code> should be preferred which is much
* faster (as it does not need to search for existing members).
* </p>
*
* @param name
* the name of the member to replace
* @param value
* the value to set to the member
* @return the object itself, to enable method chaining
*/
public JsonObject set( String name, int value ) {
set( name, valueOf( value ) );
return this;
}

/**
* Sets the value of the member with the specified name to the JSON representation of the
* specified <code>long</code> value. If this object does not contain a member with this name, a
Expand Down Expand Up @@ -444,7 +493,7 @@ public JsonObject remove( String name ) {
}
int index = indexOf( name );
if( index != -1 ) {
table.remove( name );
table.remove( index );
names.remove( index );
values.remove( index );
}
Expand Down Expand Up @@ -663,9 +712,14 @@ void add( String name, int index ) {
}
}

void remove( String name ) {
int slot = hashSlotFor( name );
hashTable[slot] = 0;
void remove( int index ) {
for( int i = 0; i < hashTable.length; i++ ) {
if( hashTable[i] == index + 1 ) {
hashTable[i] = 0;
} else if( hashTable[i] > index + 1 ) {
hashTable[i]--;
}
}
}

int get( Object name ) {
Expand Down
Loading

0 comments on commit aa82071

Please sign in to comment.