Skip to content

Commit aa82071

Browse files
committed
Pick up minimal-json 0.9.0
Incorporate the latest improvements and the fix for issue 16 [1] in minimal-json. [1] ralfstx/minimal-json#16
1 parent fbd00c5 commit aa82071

File tree

9 files changed

+328
-150
lines changed

9 files changed

+328
-150
lines changed

bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/JsonArray.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ private JsonArray( JsonArray array, boolean unmodifiable ) {
8686

8787
/**
8888
* Reads a JSON array from the given reader.
89+
* <p>
90+
* Characters are read in chunks and buffered internally, therefore wrapping an existing reader in
91+
* an additional <code>BufferedReader</code> does <strong>not</strong> improve reading
92+
* performance.
93+
* </p>
8994
*
9095
* @param reader
9196
* the reader to read the JSON array from
@@ -132,6 +137,18 @@ public static JsonArray unmodifiableArray( JsonArray array ) {
132137
return new JsonArray( array, true );
133138
}
134139

140+
/**
141+
* Adds the JSON representation of the specified <code>int</code> value to the array.
142+
*
143+
* @param value
144+
* the value to add to the array
145+
* @return the array itself, to enable method chaining
146+
*/
147+
public JsonArray add( int value ) {
148+
values.add( valueOf( value ) );
149+
return this;
150+
}
151+
135152
/**
136153
* Adds the JSON representation of the specified <code>long</code> value to the array.
137154
*

bundles/com.eclipsesource.jshint/src/com/eclipsesource/json/JsonObject.java

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ private JsonObject( JsonObject object, boolean unmodifiable ) {
9898

9999
/**
100100
* Reads a JSON object from the given reader.
101+
* <p>
102+
* Characters are read in chunks and buffered internally, therefore wrapping an existing reader in
103+
* an additional <code>BufferedReader</code> does <strong>not</strong> improve reading
104+
* performance.
105+
* </p>
101106
*
102107
* @param reader
103108
* the reader to read the JSON object from
@@ -145,6 +150,28 @@ public static JsonObject unmodifiableObject( JsonObject object ) {
145150
return new JsonObject( object, true );
146151
}
147152

153+
/**
154+
* Adds a new member at the end of this object, with the specified name and the JSON
155+
* representation of the specified <code>int</code> value.
156+
* <p>
157+
* This method <strong>does not prevent duplicate names</strong>. Adding a member with a name that
158+
* already exists in the object will add another member with the same name. In order to replace
159+
* existing members, use the method <code>set(name, value)</code> instead. However, <strong>
160+
* <em>add</em> is much faster than <em>set</em></strong> (because it does not need to search for
161+
* existing members). Therefore <em>add</em> should be preferred when constructing new objects.
162+
* </p>
163+
*
164+
* @param name
165+
* the name of the member to add
166+
* @param value
167+
* the value of the member to add
168+
* @return the object itself, to enable method chaining
169+
*/
170+
public JsonObject add( String name, int value ) {
171+
add( name, valueOf( value ) );
172+
return this;
173+
}
174+
148175
/**
149176
* Adds a new member at the end of this object, with the specified name and the JSON
150177
* representation of the specified <code>long</code> value.
@@ -285,6 +312,28 @@ public JsonObject add( String name, JsonValue value ) {
285312
return this;
286313
}
287314

315+
/**
316+
* Sets the value of the member with the specified name to the JSON representation of the
317+
* specified <code>int</code> value. If this object does not contain a member with this name, a
318+
* new member is added at the end of the object. If this object contains multiple members with
319+
* this name, only the last one is changed.
320+
* <p>
321+
* This method should <strong>only be used to modify existing objects</strong>. To fill a new
322+
* object with members, the method <code>add(name, value)</code> should be preferred which is much
323+
* faster (as it does not need to search for existing members).
324+
* </p>
325+
*
326+
* @param name
327+
* the name of the member to replace
328+
* @param value
329+
* the value to set to the member
330+
* @return the object itself, to enable method chaining
331+
*/
332+
public JsonObject set( String name, int value ) {
333+
set( name, valueOf( value ) );
334+
return this;
335+
}
336+
288337
/**
289338
* Sets the value of the member with the specified name to the JSON representation of the
290339
* specified <code>long</code> value. If this object does not contain a member with this name, a
@@ -444,7 +493,7 @@ public JsonObject remove( String name ) {
444493
}
445494
int index = indexOf( name );
446495
if( index != -1 ) {
447-
table.remove( name );
496+
table.remove( index );
448497
names.remove( index );
449498
values.remove( index );
450499
}
@@ -663,9 +712,14 @@ void add( String name, int index ) {
663712
}
664713
}
665714

666-
void remove( String name ) {
667-
int slot = hashSlotFor( name );
668-
hashTable[slot] = 0;
715+
void remove( int index ) {
716+
for( int i = 0; i < hashTable.length; i++ ) {
717+
if( hashTable[i] == index + 1 ) {
718+
hashTable[i] = 0;
719+
} else if( hashTable[i] > index + 1 ) {
720+
hashTable[i]--;
721+
}
722+
}
669723
}
670724

671725
int get( Object name ) {

0 commit comments

Comments
 (0)