Package com.sun.javatest.util
Class PropertyArray
java.lang.Object
com.sun.javatest.util.PropertyArray
A space-efficient string to string map.
This class is similar to java.util.Properties.
For this class, space is more important than speed. Use this class when
you care much more about wasted space than wasting time doing reference
juggling in memory. Arrays in this class must correspond to this format:
{"key1", "value1", "key2", "value2", ...}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A class used to report problems that may occur when using PropertyArray. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a mutable object.PropertyArray
(int initSize) Create a mutable object.PropertyArray
(Reader in) Create a immutable object, from data read from on a stream in the format of a standard Java properties file.PropertyArray
(String... data) Create a immutable PropertyArray object from data in a compact array of names and values.PropertyArray
(Map<String, String> props) Create a immutable PropertyArray object from a standard Properties object. -
Method Summary
Modifier and TypeMethodDescriptionstatic Enumeration
<String> Enumerate the properties in an array.Get the value of a named property.static String
Get a named value from the array of properties.String[]
getArray()
Get a copy of the data in this PropertyArray.static String[]
Get a compact array containing the names and values of entries from a standard Properties object.Get the data in this PropertyArray as a standard Properties object.getProperties
(String... data) Get a standard Map object from an array of properties.boolean
Check if the property array is mutable.static String[]
Read an array of properties from an input stream.static String[]
Add a mapping to an array, returning a new array.Put a property into the PropertyArray.void
Remove a property.static String[]
Remove an entry from an array of properties.void
Save the properties to a stream.static void
Write an array of properties to a stream.int
size()
Get the number of properties stored in the property array.
-
Constructor Details
-
PropertyArray
public PropertyArray()Create a mutable object. -
PropertyArray
public PropertyArray(int initSize) Create a mutable object.- Parameters:
initSize
- the initial capacity of the array
-
PropertyArray
Create a immutable object, from data read from on a stream in the format of a standard Java properties file.- Parameters:
in
- the stream from which to read the properties- Throws:
IOException
- if a problem occurred while reading the data
-
PropertyArray
Create a immutable PropertyArray object from a standard Properties object.- Parameters:
props
- the object from which to initialize the array
-
PropertyArray
Create a immutable PropertyArray object from data in a compact array of names and values.- Parameters:
data
- an array containing pairs of entries: even-numbered entries identify the names of properties, odd-numbered entries give the value for the preceding property name.
-
-
Method Details
-
getArray
Get a compact array containing the names and values of entries from a standard Properties object.- Parameters:
props
- the Properties object from which to get the data- Returns:
- an array containing the names of the properties in even-numbered entries, and the corresponding values in the adjacent odd-numbered entries
-
put
Add a mapping to an array, returning a new array.- Parameters:
data
- The array to which to the new array is to be added. May be null.key
- the name of the new value to be addedvalue
- the new value to be added- Returns:
- an array with the new element added
- Throws:
PropertyArray.PropertyArrayError
- May be thrown if a null key or value is supplied.
-
get
Get a named value from the array of properties. If the given data array is null or zero length, null is returned. If the key paramter is null, null will be returned, no error will occur.- Parameters:
data
- an array containing sequential name value pairskey
- the name of the property to be returned- Returns:
- the value of the named entry, or null if not found
-
remove
Remove an entry from an array of properties.- Parameters:
data
- an array of sequential name value propertieskey
- the name of the entry to be removed- Returns:
- an array that does not contain the named property
-
getProperties
Get a standard Map object from an array of properties.- Parameters:
data
- an array of sequential name value properties- Returns:
- a Map object containing data from the array
-
save
Write an array of properties to a stream. The data is written using the format for standard Java property files.- Parameters:
data
- an array of sequential name value propertiesout
- a stream to which to write the data- Throws:
IOException
- if a problem occurred while writing to the stream- See Also:
-
load
Read an array of properties from an input stream. The data will be read according to the standard format for Java property files.- Parameters:
in
- the stream from which to read the data- Returns:
- an array of sequential name value properties
- Throws:
IOException
- if an error occurred while reading the data- See Also:
-
enumerate
Enumerate the properties in an array.- Parameters:
props
- an array of sequential name value properties- Returns:
- an enumeration of the properties in the array
-
getProperties
Get the data in this PropertyArray as a standard Properties object.- Returns:
- a Properties object containing the same data as this PropertyArray
-
isMutable
public boolean isMutable()Check if the property array is mutable.- Returns:
- true if data can be stored in this array, and false otherwise
-
size
public int size()Get the number of properties stored in the property array.- Returns:
- the number of properties stored in the property array
-
get
Get the value of a named property.- Parameters:
key
- the name of the desired property- Returns:
- the value of the property, or null if it was not found
-
getArray
Get a copy of the data in this PropertyArray.- Returns:
- a copy of the data, or null if there is no data.
-
put
Put a property into the PropertyArray.- Parameters:
key
- the name of the property to be addedvalue
- the value of the property to be added- Returns:
- the previous value (if any) of this property
- Throws:
PropertyArray.PropertyArrayError
- if a null key or value is supplied.
-
remove
Remove a property.- Parameters:
key
- the name of the property to be removed
-
save
Save the properties to a stream. The data is written using the format for a standard Java properties file.- Parameters:
out
- the stream to which to write the data- Throws:
IOException
- if an error occurred while writing the data
-