org.rhq.enterprise.communications.command.param
Class ParametersImpl

java.lang.Object
  extended by org.rhq.enterprise.communications.command.param.ParametersImpl
All Implemented Interfaces:
Serializable, Iterable<Parameter>, Collection<Parameter>, Parameters

public class ParametersImpl
extends Object
implements Parameters

A class holding specific information about a set of parameters. It follows the Java Collection interface contract and thus can be used anywhere a Collection can be used.

This collection follows both list and map connotations. It behaves like a list in that items that come out of it are in the same order as when they were added to it. It behaves like a map in that duplicate elements are not allowed and looking up elements have constant time performance that is analogous to java.util.HashMap.

This class is not thread-safe.

Author:
Charles Crouch, John Mazzitelli
See Also:
Serialized Form

Constructor Summary
ParametersImpl()
          Constructor for ParametersImpl that initializes the object with no parameters.
ParametersImpl(Parameters original)
          Copy-constructor for ParametersImpl.
 
Method Summary
 boolean add(Parameter parameter)
           
 boolean addAll(Collection<? extends Parameter> c)
          Adds the elements found in the c collection.
 void applyResourceBundleToParameterRenderingInformation(ResourceBundle resourceBundle)
          This will apply the given resourceBundle to the parameters in this collection.
 void clear()
           
 boolean contains(Object o)
          This is here to satisfy the Collection interface contract.
 boolean contains(Parameter parameter)
          Checks to see if this parameter exists by specifying the parameter - only the name is used when checking.
 boolean contains(String parameterName)
          Checks if this parameter exists by specifying the parameter name.
 boolean containsAll(Collection<?> c)
          Checks to see if all the elements found in the c collection are in this collection.
 boolean equals(Object obj)
           
 Parameters getInternalParameters()
          The returned object is not a copy - changes made to that collection affect this object's internal collection.
 Parameter getParameter(String parameterName)
          Given the name of a parameter, this will return its associated Parameter.
 ParameterDefinition getParameterDefinition(String parameterName)
          Given the name of a parameter, this will return the parameter's definition.
 Object getParameterValue(String parameterName)
          Given the name of a parameter, this will return the parameter's value.
 Parameters getPublicParameters()
          The returned object is not a copy - changes made to that collection affect this object's internal collection.
 int hashCode()
           
 boolean isEmpty()
           
 Iterator<Parameter> iterator()
          The iterator will contain objects of type Parameter.
 boolean remove(Object o)
          This is here to satisfy the Collection interface contract.
 boolean remove(Parameter parameter)
          Removes the parameter whose name is the same as the name in the given parameter.
 boolean remove(String parameterName)
          Removes the parameter stored in this collection whose name matches parameterName.
 boolean removeAll(Collection<?> c)
          Removes the elements found in the c collection.
 boolean retainAll(Collection<?> c)
          Retains only those elements found in the c collection.
 void setParameterValue(String parameterName, Object parameterValue)
          Given the name of a parameter, this will set the parameter's value.
 int size()
          The returned object is not a copy - changes made to that collection affect this object's internal collection.
 Object[] toArray()
          The returned array may be cast to a Parameter array.
<T> T[]
toArray(T[] a)
          Returns an array of Parameter objects.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParametersImpl

public ParametersImpl()
Constructor for ParametersImpl that initializes the object with no parameters.


ParametersImpl

public ParametersImpl(Parameters original)
Copy-constructor for ParametersImpl.

Parameters:
original - the original to copy
Method Detail

getParameter

public Parameter getParameter(String parameterName)
Description copied from interface: Parameters
Given the name of a parameter, this will return its associated Parameter. If it doesn't exist in this collection, null is returned.

Specified by:
getParameter in interface Parameters
Parameters:
parameterName - the name of the parameter to get
Returns:
the parameter definition and value of the named parameter
See Also:
Parameters.getParameter(String)

getParameterDefinition

public ParameterDefinition getParameterDefinition(String parameterName)
                                           throws InvalidParameterDefinitionException
Description copied from interface: Parameters
Given the name of a parameter, this will return the parameter's definition. It is possible that a parameter exists, but its definition is null; in this case, null is returned. If the parameter does not exist in this collection, an exception is thrown.

Specified by:
getParameterDefinition in interface Parameters
Parameters:
parameterName - the name of the parameter whose definition is to be returned
Returns:
the parameter definition of the named parameter
Throws:
InvalidParameterDefinitionException - if the parameter does not exist in this collection
See Also:
Parameters.getParameterDefinition(String)

getParameterValue

public Object getParameterValue(String parameterName)
                         throws InvalidParameterDefinitionException
Description copied from interface: Parameters
Given the name of a parameter, this will return the parameter's value. Since a parameter's value is allowed to be null, a return value of null means the parameter exists but its value was null. If the parameter does not exist in this collection, an exception is thrown.

Specified by:
getParameterValue in interface Parameters
Parameters:
parameterName - the name of the parameter whose value is to be returned
Returns:
the parameter value of the named parameter
Throws:
InvalidParameterDefinitionException - if the parameter does not exist in this collection
See Also:
Parameters.getParameterValue(String)

setParameterValue

public void setParameterValue(String parameterName,
                              Object parameterValue)
                       throws InvalidParameterDefinitionException
Description copied from interface: Parameters
Given the name of a parameter, this will set the parameter's value. If the parameter doesn't exist in this collection, an exception is thrown.

Specified by:
setParameterValue in interface Parameters
Parameters:
parameterName - the name of the parameter whose value is to be set
parameterValue - the value of the parameter (may be null)
Throws:
InvalidParameterDefinitionException - if the parameter does not exist in this collection
See Also:
Parameters.setParameterValue(String, Object)

getPublicParameters

public Parameters getPublicParameters()
The returned object is not a copy - changes made to that collection affect this object's internal collection. That means that if you add or remove parameters from the returned object, those parameters are also added or removed from this object.

Specified by:
getPublicParameters in interface Parameters
Returns:
collection of public, non-hidden parameters
See Also:
Parameters.getPublicParameters()

getInternalParameters

public Parameters getInternalParameters()
The returned object is not a copy - changes made to that collection affect this object's internal collection. That means that if you add or remove parameters from the returned object, those parameters are also added or removed from this object.

Specified by:
getInternalParameters in interface Parameters
Returns:
collection of internal (i.e. hidden) parameters
See Also:
Parameters.getInternalParameters()

applyResourceBundleToParameterRenderingInformation

public void applyResourceBundleToParameterRenderingInformation(ResourceBundle resourceBundle)
Description copied from interface: Parameters
This will apply the given resourceBundle to the parameters in this collection. This allows you to localize the parameters.

Specified by:
applyResourceBundleToParameterRenderingInformation in interface Parameters
Parameters:
resourceBundle - the resource bundle that is to be used when rendering the parameters
See Also:
Parameters.applyResourceBundleToParameterRenderingInformation(ResourceBundle)

size

public int size()
The returned object is not a copy - changes made to that collection affect this object's internal collection. That means that if you add or remove parameters from the returned object, those parameters are also added or removed from this object.

Specified by:
size in interface Collection<Parameter>
See Also:
Collection.size()

clear

public void clear()
Specified by:
clear in interface Collection<Parameter>
See Also:
Collection.clear()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<Parameter>
See Also:
Collection.isEmpty()

add

public boolean add(Parameter parameter)
            throws NullPointerException
Specified by:
add in interface Collection<Parameter>
Throws:
NullPointerException
See Also:
Parameters#add(Parameter)

contains

public boolean contains(Object o)
                 throws ClassCastException,
                        NullPointerException
This is here to satisfy the Collection interface contract. Same as if calling contains(String) where the argument is the parameter name or contains(Parameter).

Specified by:
contains in interface Collection<Parameter>
Throws:
ClassCastException
NullPointerException
See Also:
Collection.contains(Object)

contains

public boolean contains(String parameterName)
                 throws NullPointerException
Description copied from interface: Parameters
Checks if this parameter exists by specifying the parameter name.

Specified by:
contains in interface Parameters
Parameters:
parameterName - the parameter name
Returns:
true if there is a parameter in this object identified by the parameterName
Throws:
NullPointerException - if parameterName is null, as per Collection interface contract
See Also:
Parameters.contains(String)

contains

public boolean contains(Parameter parameter)
                 throws NullPointerException
Description copied from interface: Parameters
Checks to see if this parameter exists by specifying the parameter - only the name is used when checking. This means as long as the given parameter's name matches one in the collection, this returns true, it doesn't matter if the parameter's value or definition completely match.

Specified by:
contains in interface Parameters
Parameters:
parameter - the parameter to check
Returns:
true if there is a parameter in this object identified by the parameterName
Throws:
NullPointerException - if parameter is null, as per Collection interface contract
See Also:
Parameters.contains(Parameter)

remove

public boolean remove(Object o)
               throws ClassCastException,
                      NullPointerException
This is here to satisfy the Collection interface contract. Same as if calling remove(String) where the argument is the parameter name or remove(Parameter).

Specified by:
remove in interface Collection<Parameter>
Throws:
ClassCastException
NullPointerException
See Also:
Collection.remove(Object)

remove

public boolean remove(String parameterName)
               throws NullPointerException
Removes the parameter stored in this collection whose name matches parameterName.

Specified by:
remove in interface Parameters
Parameters:
parameterName - the name of the parameter to remove from this collection
Returns:
true if the object was removed; false if there was no object in this collection with the given parameter name
Throws:
NullPointerException - if parameterName is null, as per Collection interface contract

remove

public boolean remove(Parameter parameter)
               throws NullPointerException
Removes the parameter whose name is the same as the name in the given parameter. The full definition and value of the given parameter is ignored when determining a match - only the parameter name is used in the comparision.

Specified by:
remove in interface Parameters
Parameters:
parameter - the parameter whose name is used to determine what to remove
Returns:
true if the object was removed
Throws:
NullPointerException - if parameter is null, as per Collection interface contract

addAll

public boolean addAll(Collection<? extends Parameter> c)
               throws ClassCastException,
                      NullPointerException
Adds the elements found in the c collection. If one or more elements in c is not a Parameter, an exception will be thrown.

Specified by:
addAll in interface Collection<Parameter>
Throws:
ClassCastException
NullPointerException
See Also:
Collection.addAll(java.util.Collection)

containsAll

public boolean containsAll(Collection<?> c)
                    throws ClassCastException,
                           NullPointerException
Checks to see if all the elements found in the c collection are in this collection. If one or more elements in c is not a Parameter or String, an exception will be thrown.

Specified by:
containsAll in interface Collection<Parameter>
Throws:
ClassCastException
NullPointerException
See Also:
Collection.containsAll(Collection)

removeAll

public boolean removeAll(Collection<?> c)
                  throws ClassCastException,
                         NullPointerException
Removes the elements found in the c collection. If one or more elements in c is not a Parameter, an exception will be thrown.

Specified by:
removeAll in interface Collection<Parameter>
Throws:
ClassCastException
NullPointerException
See Also:
Collection.removeAll(Collection)

retainAll

public boolean retainAll(Collection<?> c)
                  throws ClassCastException,
                         NullPointerException
Retains only those elements found in the c collection. If one or more elements in c is not a Parameter, an exception will be thrown. The implementation will remove all elements in this collection and then add all the elements in c. Because of this, true is always returned - even if the elements end up being the same in the end.

Specified by:
retainAll in interface Collection<Parameter>
Throws:
ClassCastException
NullPointerException
See Also:
Collection.retainAll(Collection)

iterator

public Iterator<Parameter> iterator()
The iterator will contain objects of type Parameter.

Specified by:
iterator in interface Iterable<Parameter>
Specified by:
iterator in interface Collection<Parameter>
See Also:
Collection.iterator()

toArray

public Object[] toArray()
The returned array may be cast to a Parameter array.

Specified by:
toArray in interface Collection<Parameter>
See Also:
Collection.toArray()

toArray

public <T> T[] toArray(T[] a)
Returns an array of Parameter objects.

Specified by:
toArray in interface Collection<Parameter>
See Also:
java.util.Collection#toArray(T[])

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

equals

public boolean equals(Object obj)
Specified by:
equals in interface Collection<Parameter>
Overrides:
equals in class Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<Parameter>
Overrides:
hashCode in class Object
See Also:
Object.hashCode()


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.