Package fr.dyade.aaa.common.stream
Class Properties
- java.lang.Object
-
- fr.dyade.aaa.common.stream.Properties
-
- All Implemented Interfaces:
Encodable,Serializable,Cloneable
public final class Properties extends Object implements Serializable, Cloneable, Encodable
This class implements a set of properties, which maps keys to values. Only string object can be used as a key, all primitives type can be used as a value.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classProperties.EmptyEnumeratorA hashtable enumerator class for empty hash tables, specializes the general Enumeratorprivate static classProperties.EntryProperties collision list.private classProperties.EnumeratorA hashtable enumerator class.
-
Field Summary
Fields Modifier and Type Field Description private intcountThe total number of entries in the hash table.private static Properties.EmptyEnumeratoremptyEnumeratorprivate static intKEYSprivate floatloadFactorThe load factor for the hashtable.private Properties.Entry[]tableThe hash table data.private intthresholdThe table is rehashed when its size exceeds this threshold.private static intVALUES-
Fields inherited from interface fr.dyade.aaa.common.encoding.Encodable
BOOLEAN_ENCODED_SIZE, BYTE_ENCODED_SIZE, DOUBLE_ENCODED_SIZE, FLOAT_ENCODED_SIZE, INT_ENCODED_SIZE, LONG_ENCODED_SIZE, SHORT_ENCODED_SIZE
-
-
Constructor Summary
Constructors Constructor Description Properties()Constructs a new, empty hashtable with a default initial capacity (11) and load factor, which is 0.75.Properties(int initialCapacity)Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is 0.75.Properties(int initialCapacity, float loadFactor)Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this hashtable so that it contains no keys.Objectclone()Creates a shallow copy of this hashtable.booleancontainsKey(String key)Tests if the specified object is a key in this hashtable.voidcopyInto(Map h)voiddecode(Decoder decoder)Decodes the content of this objectEnumerationelements()Returns an enumeration of the values in this hashtable.voidencode(Encoder encoder)Encodes the content of this objectbooleanequals(Object o)Objectget(String key)Returns the value to which the specified key is mapped in this hashtable.intgetEncodableClassId()Returns a unique class identifier.intgetEncodedSize()Returns the size of the byte array that results from the encoding of this object.private EnumerationgetEnumeration(int type)inthashCode()Returns the hash code value for this Map as per the definition in the Map interface.private voidinitialize(int initialCapacity, float loadFactor)booleanisEmpty()Tests if this hashtable maps no keys to values.Enumerationkeys()Returns an enumeration of the keys in this hashtable.static voidobjectToJSon(Object obj, Appendable appendable)Objectput(String key, Object value)Maps the specifiedkeyto the specifiedvaluein this hashtable.static PropertiesreadFrom(InputStream is)The object implements the readFrom method to restore its contents from the input stream.voidreadFrom(InputStream is, int count)private voidreadObject(ObjectInputStream in)protected voidrehash()Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.Objectremove(String key)Removes the key (and its corresponding value) from this hashtable.ObjectsetProperty(String key, Object value)Calls the method put.intsize()Returns the number of keys in this hashtable.voidtoJSon(Appendable appendable)StringtoString()Returns a string representation of this Properties object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space).private voidwriteObject(ObjectOutputStream out)voidwriteTo(OutputStream os)The object implements the writeTo method to write its contents to the output stream.
-
-
-
Field Detail
-
count
private transient int count
The total number of entries in the hash table.
-
table
private transient Properties.Entry[] table
The hash table data.
-
threshold
private transient int threshold
The table is rehashed when its size exceeds this threshold. (The value of this field is (int)(capacity * loadFactor).)
-
loadFactor
private transient float loadFactor
The load factor for the hashtable.
-
KEYS
private static final int KEYS
- See Also:
- Constant Field Values
-
VALUES
private static final int VALUES
- See Also:
- Constant Field Values
-
emptyEnumerator
private static Properties.EmptyEnumerator emptyEnumerator
-
-
Constructor Detail
-
Properties
public Properties(int initialCapacity, float loadFactor)Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.- Parameters:
initialCapacity- the initial capacity of the hashtable.loadFactor- the load factor of the hashtable.- Throws:
IllegalArgumentException- if the initial capacity is less than zero, or if the load factor is nonpositive.
-
Properties
public Properties(int initialCapacity)
Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is 0.75.- Parameters:
initialCapacity- the initial capacity of the hashtable.- Throws:
IllegalArgumentException- if the initial capacity is less than zero.
-
Properties
public Properties()
Constructs a new, empty hashtable with a default initial capacity (11) and load factor, which is 0.75.
-
-
Method Detail
-
initialize
private void initialize(int initialCapacity, float loadFactor)
-
size
public int size()
Returns the number of keys in this hashtable.- Returns:
- the number of keys in this hashtable.
-
isEmpty
public boolean isEmpty()
Tests if this hashtable maps no keys to values.- Returns:
trueif this hashtable maps no keys to values;falseotherwise.
-
keys
public Enumeration keys()
Returns an enumeration of the keys in this hashtable.- Returns:
- an enumeration of the keys in this hashtable.
- See Also:
Enumeration,elements()
-
elements
public Enumeration elements()
Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.- Returns:
- an enumeration of the values in this hashtable.
- See Also:
Enumeration,Map
-
containsKey
public boolean containsKey(String key)
Tests if the specified object is a key in this hashtable.- Parameters:
key- possible key.- Returns:
trueif and only if the specified object is a key in this hashtable, as determined by the equals method;falseotherwise.- Throws:
NullPointerException- if the key isnull.
-
get
public Object get(String key)
Returns the value to which the specified key is mapped in this hashtable.- Parameters:
key- a key in the hashtable.- Returns:
- the value to which the key is mapped in this hashtable;
nullif the key is not mapped to any value in this hashtable. - Throws:
NullPointerException- if the key isnull.
-
rehash
protected void rehash()
Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.
-
setProperty
public Object setProperty(String key, Object value) throws ClassCastException
Calls the method put.Provided to Enforce the use of primitive type for values. The value returned is the result of the call to put.
- Parameters:
key- the key to be placed into this property object.value- the value corresponding to key.- Returns:
- the previous value of the specified key in this property object, or null if it did not have one.
- Throws:
ClassCastException
-
put
public Object put(String key, Object value)
Maps the specifiedkeyto the specifiedvaluein this hashtable. Neither the key nor the value can benull.The value can be retrieved by calling the
getmethod with a key that is equal to the original key. Be careful only primitive type can be used as value, in the other case an exception will be thrown at serialization.- Parameters:
key- the hashtable key.value- the value.- Returns:
- the previous value of the specified key in this hashtable,
or
nullif it did not have one. - Throws:
NullPointerException- if the key or value isnull.- See Also:
Object.equals(Object)
-
remove
public Object remove(String key)
Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.- Parameters:
key- the key that needs to be removed.- Returns:
- the value to which the key had been mapped in this hashtable,
or
nullif the key did not have a mapping. - Throws:
NullPointerException- if the key isnull.
-
clear
public void clear()
Clears this hashtable so that it contains no keys.
-
clone
public Object clone()
Creates a shallow copy of this hashtable. All the structure of the hashtable itself is copied, but the keys and values are not cloned. This is a relatively expensive operation.
-
toString
public String toString()
Returns a string representation of this Properties object in the form of a set of entries, enclosed in braces and separated by the ASCII characters ", " (comma and space). Each entry is rendered as the key, an equals sign =, and the associated element, where the toString method is used to convert the key and element to strings.Overrides to toString method of Object.
-
toJSon
public void toJSon(Appendable appendable) throws IOException
- Throws:
IOException
-
objectToJSon
public static void objectToJSon(Object obj, Appendable appendable) throws IOException
- Throws:
IOException
-
getEnumeration
private Enumeration getEnumeration(int type)
-
hashCode
public int hashCode()
Returns the hash code value for this Map as per the definition in the Map interface.- Overrides:
hashCodein classObject- Since:
- 1.2
- See Also:
Map.hashCode()
-
copyInto
public void copyInto(Map h)
-
writeTo
public void writeTo(OutputStream os) throws IOException
The object implements the writeTo method to write its contents to the output stream.- Parameters:
os- the stream to write the object to.- Throws:
IOException- an error occurs during writing.
-
readFrom
public static Properties readFrom(InputStream is) throws IOException
The object implements the readFrom method to restore its contents from the input stream.- Parameters:
is- the stream to read data from in order to restore the object- Returns:
- the properties object read.
- Throws:
IOException- an error occurs during writing.
-
readFrom
public void readFrom(InputStream is, int count) throws IOException
- Throws:
IOException
-
writeObject
private void writeObject(ObjectOutputStream out) throws IOException
- Throws:
IOException
-
readObject
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- Throws:
IOExceptionClassNotFoundException
-
getEncodedSize
public int getEncodedSize() throws IOExceptionDescription copied from interface:EncodableReturns the size of the byte array that results from the encoding of this object.- Specified by:
getEncodedSizein interfaceEncodable- Returns:
- the size of the encoded byte array
- Throws:
IOException
-
getEncodableClassId
public int getEncodableClassId()
Description copied from interface:EncodableReturns a unique class identifier.- Specified by:
getEncodableClassIdin interfaceEncodable- Returns:
- a unique class identifier
-
encode
public void encode(Encoder encoder) throws Exception
Description copied from interface:EncodableEncodes the content of this object
-
-