private JsonObject(JsonObject object, boolean unmodifiable) { if (object == null) { throw new NullPointerException("object is null"); } if (unmodifiable) { names = Collections.unmodifiableList(object.names); values = Collections.unmodifiableList(object.values); } else { names = new ArrayList<String>(object.names); values = new ArrayList<JsonValue>(object.values); } table = new HashIndexTable(); updateHashIndex(); }
values.set(index, value); } else { table.add(name, names.size()); names.add(name); values.add(value);
int indexOf(String name) { int index = table.get(name); if (index != -1 && name.equals(names.get(index))) { return index; } return names.lastIndexOf(name); }
values.set( index, value ); } else { table.add( name, names.size() ); names.add( name ); values.add( value );
values.set(index, value); } else { table.add(name, names.size()); names.add(name); values.add(value);
/** * Appends a new member to the end of this object, with the specified name and the specified JSON * value. * <p> * This method <strong>does not prevent duplicate names</strong>. Calling this method with a name * that already exists in the object will append 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, must not be <code>null</code> * @return the object itself, to enable method chaining */ public JsonObject add( String name, JsonValue value ) { if( name == null ) { throw new NullPointerException( "name is null" ); } if( value == null ) { throw new NullPointerException( "value is null" ); } table.add( name, names.size() ); names.add( name ); values.add( value ); return this; }
values.set(index, value); } else { table.add(name, names.size()); names.add(name); values.add(value);
/** * Appends a new member to the end of this object, with the specified name and the specified JSON * value. * <p> * This method <strong>does not prevent duplicate names</strong>. Calling this method with a name * that already exists in the object will append 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, must not be <code>null</code> * @return the object itself, to enable method chaining */ public JsonObject add(String name, JsonValue value) { if (name == null) { throw new NullPointerException("name is null"); } if (value == null) { throw new NullPointerException("value is null"); } table.add(name, names.size()); names.add(name); values.add(value); return this; }
/** * Appends a new member to the end of this object, with the specified name and the specified JSON * value. * <p> * This method <strong>does not prevent duplicate names</strong>. Calling this method with a name * that already exists in the object will append 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, must not be <code>null</code> * @return the object itself, to enable method chaining */ public JsonObject add(String name, JsonValue value) { if (name == null) { throw new NullPointerException("name is null"); } if (value == null) { throw new NullPointerException("value is null"); } table.add(name, names.size()); names.add(name); values.add(value); return this; }
/** * Removes a member with the specified name from this object. If this object contains multiple * members with the given name, only the last one is removed. If this object does not contain a * member with the specified name, the object is not modified. * * @param name * the name of the member to remove * @return the object itself, to enable method chaining */ public JsonObject remove( String name ) { if( name == null ) { throw new NullPointerException( "name is null" ); } int index = indexOf( name ); if( index != -1 ) { table.remove( index ); names.remove( index ); values.remove( index ); } return this; }
/** * Removes a member with the specified name from this object. If this object contains multiple * members with the given name, only the last one is removed. If this object does not contain a * member with the specified name, the object is not modified. * * @param name * the name of the member to remove * @return the object itself, to enable method chaining */ public JsonObject remove(String name) { if (name == null) { throw new NullPointerException("name is null"); } int index = indexOf(name); if (index != -1) { table.remove(index); names.remove(index); values.remove(index); } return this; }
/** * Removes a member with the specified name from this object. If this object contains multiple * members with the given name, only the last one is removed. If this object does not contain a * member with the specified name, the object is not modified. * * @param name * the name of the member to remove * @return the object itself, to enable method chaining */ public JsonObject remove(String name) { if (name == null) { throw new NullPointerException("name is null"); } int index = indexOf(name); if (index != -1) { table.remove(index); names.remove(index); values.remove(index); } return this; }
private JsonObject( JsonObject object, boolean unmodifiable ) { if( object == null ) { throw new NullPointerException( "object is null" ); } if( unmodifiable ) { names = Collections.unmodifiableList( object.names ); values = Collections.unmodifiableList( object.values ); } else { names = new ArrayList<String>( object.names ); values = new ArrayList<JsonValue>( object.values ); } table = new HashIndexTable(); updateHashIndex(); }
private JsonObject(JsonObject object, boolean unmodifiable) { if (object == null) { throw new NullPointerException("object is null"); } if (unmodifiable) { names = Collections.unmodifiableList(object.names); values = Collections.unmodifiableList(object.values); } else { names = new ArrayList<String>(object.names); values = new ArrayList<JsonValue>(object.values); } table = new HashIndexTable(); updateHashIndex(); }
private JsonObject(JsonObject object, boolean unmodifiable) { if (object == null) { throw new NullPointerException("object is null"); } if (unmodifiable) { names = Collections.unmodifiableList(object.names); values = Collections.unmodifiableList(object.values); } else { names = new ArrayList<String>(object.names); values = new ArrayList<JsonValue>(object.values); } table = new HashIndexTable(); updateHashIndex(); }
int get( Object name ) { int slot = hashSlotFor( name ); // subtract 1, 0 stands for empty return ( hashTable[slot] & 0xff ) - 1; }
void add( String name, int index ) { int slot = hashSlotFor( name ); if( index < 0xff ) { // increment by 1, 0 stands for empty hashTable[slot] = (byte)( index + 1 ); } else { hashTable[slot] = 0; } }
int get(Object name) { int slot = hashSlotFor(name); // subtract 1, 0 stands for empty return (hashTable[slot] & 0xff) - 1; }
void add(String name, int index) { int slot = hashSlotFor(name); if (index < 0xff) { // increment by 1, 0 stands for empty hashTable[slot] = (byte)(index + 1); } else { hashTable[slot] = 0; } }
private synchronized void readObject( ObjectInputStream inputStream ) throws IOException, ClassNotFoundException { inputStream.defaultReadObject(); table = new HashIndexTable(); updateHashIndex(); }