it.could.util.location
Class Parameters

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byit.could.util.location.Parameters
All Implemented Interfaces:
Collection, Encodable, EncodingAware, List

public class Parameters
extends AbstractList
implements Encodable

The Parameters class represents a never empty and immutable List of Parameter instances, normally created parsing a query string.

Author:
Pier Fumagalli

Nested Class Summary
static class Parameters.Parameter
          The Parameter class represents a single parameter either parsed from a query string or a path element.
 
Field Summary
static char DEFAULT_DELIMITER
          The default delimiter for a Parameters instance.
 
Fields inherited from class java.util.AbstractList
modCount
 
Fields inherited from interface it.could.util.encoding.EncodingAware
DEFAULT_ENCODING, PLATFORM_ENCODING
 
Constructor Summary
Parameters(List parameters)
          Create a new Parameters instance from a List of Parameter instances using the default parameter delimiter.
Parameters(List parameters, char delimiter)
          Create a new Parameters instance from a List of Parameter instances using the specified character as the parameters delimiter.
 
Method Summary
static Parameters create(List parameters)
          Utility method to create a new Parameters instance from a List of Parameter instances.
static Parameters create(List parameters, char delimiter)
          Utility method to create a new Parameters instance from a List of Parameter instances.
 boolean equals(Object object)
          Check if the specified Object is equal to this Parameters instance.
 Object get(int index)
          Return the Parameter stored by this\ instance at the specified index.
 Set getNames()
          Return an immutable Set of Strings containing all known Parameter names.
 String getValue(String name)
          Return the first String value associated with the specified parameter name, or null.
 List getValues(String name)
          Return an immutable List of all String values associated with the specified parameter name, or null.
 int hashCode()
          Return the hash code value of this Parameters instance.
static Parameters parse(String parameters)
          Parse the specified parameters String into a Parameters instance using the default parameter delimiter.
static Parameters parse(String parameters, char delimiter)
          Parse the specified parameters String into a Parameters instance using the specified character as the parameters delimiter.
static Parameters parse(String parameters, char delimiter, String encoding)
          Parse the specified parameters String into a Parameters instance using the specified character as the parameters delimiter.
static Parameters parse(String parameters, String encoding)
          Parse the specified parameters String into a Parameters instance using the default parameter delimiter.
 int size()
          Return the number of Parameters contained by this instance.
 String toString()
          Return the URL-encoded String representation of this Parameters instance.
 String toString(String encoding)
          Return the URL-encoded String representation of this Parameters instance using the specified character encoding.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

DEFAULT_DELIMITER

public static final char DEFAULT_DELIMITER

The default delimiter for a Parameters instance.

See Also:
Constant Field Values
Constructor Detail

Parameters

public Parameters(List parameters)

Create a new Parameters instance from a List of Parameter instances using the default parameter delimiter.

Throws:
NullPointerExceptoin - if the List was null.
IllegalArgumentException - if the List was empty.
ClassCastException - if any of the elements in the List was not a Parameter.

Parameters

public Parameters(List parameters,
                  char delimiter)

Create a new Parameters instance from a List of Parameter instances using the specified character as the parameters delimiter.

Throws:
NullPointerExceptoin - if the List was null.
IllegalArgumentException - if the List was empty.
ClassCastException - if any of the elements in the List was not a Parameter.
Method Detail

create

public static Parameters create(List parameters)

Utility method to create a new Parameters instance from a List of Parameter instances.

Returns:
a non-null and not empty Parameters instance or null if the specified List was null, empty or did not contain any Parameter.
Throws:
ClassCastException - if any of the elements in the List was not a Parameter.

create

public static Parameters create(List parameters,
                                char delimiter)

Utility method to create a new Parameters instance from a List of Parameter instances.

Returns:
a non-null and not empty Parameters instance or null if the specified List was null, empty or did not contain any Parameter.
Throws:
ClassCastException - if any of the elements in the List was not a Parameter.

parse

public static Parameters parse(String parameters)

Parse the specified parameters String into a Parameters instance using the default parameter delimiter.

Returns:
a non-null and not empty Parameters instance or null if the specified string was null, empty or did not contain any Parameter.

parse

public static Parameters parse(String parameters,
                               char delimiter)

Parse the specified parameters String into a Parameters instance using the specified character as the parameters delimiter.

Returns:
a non-null and not empty Parameters instance or null if the specified string was null, empty or did not contain any Parameter.

parse

public static Parameters parse(String parameters,
                               String encoding)
                        throws UnsupportedEncodingException

Parse the specified parameters String into a Parameters instance using the default parameter delimiter.

Returns:
a non-null and not empty Parameters instance or null if the specified string was null, empty or did not contain any Parameter.
Throws:
UnsupportedEncodingException

parse

public static Parameters parse(String parameters,
                               char delimiter,
                               String encoding)
                        throws UnsupportedEncodingException

Parse the specified parameters String into a Parameters instance using the specified character as the parameters delimiter.

Returns:
a non-null and not empty Parameters instance or null if the specified string was null, empty or did not contain any Parameter.
Throws:
UnsupportedEncodingException

size

public int size()

Return the number of Parameters contained by this instance.

Specified by:
size in interface List

get

public Object get(int index)

Return the Parameter stored by this\ instance at the specified index.

Specified by:
get in interface List

getNames

public Set getNames()

Return an immutable Set of Strings containing all known Parameter names.


getValue

public String getValue(String name)

Return the first String value associated with the specified parameter name, or null.


getValues

public List getValues(String name)

Return an immutable List of all String values associated with the specified parameter name, or null.


toString

public String toString()

Return the URL-encoded String representation of this Parameters instance.

Specified by:
toString in interface Encodable

toString

public String toString(String encoding)
                throws UnsupportedEncodingException

Return the URL-encoded String representation of this Parameters instance using the specified character encoding.

Specified by:
toString in interface Encodable
Throws:
UnsupportedEncodingException - if the specified encoding is not supported by the platform.

hashCode

public int hashCode()

Return the hash code value of this Parameters instance.

Specified by:
hashCode in interface List

equals

public boolean equals(Object object)

Check if the specified Object is equal to this Parameters instance.

The specified Object is considered equal to this one if it is non-null, it is a Parameters instance, and its string representation equals this one's.

Specified by:
equals in interface List