org.quattor.pan.dml.data
Class HashResource

java.lang.Object
  extended by org.quattor.pan.dml.data.Element
      extended by org.quattor.pan.dml.data.PersistentElement
          extended by org.quattor.pan.dml.data.Resource
              extended by org.quattor.pan.dml.data.HashResource
All Implemented Interfaces:
java.lang.Iterable<Resource.Entry>, Operation
Direct Known Subclasses:
ProtectedHashResource

public class HashResource
extends Resource

Represents an nlist or hash that associates a string value (key) to another element. The key must be a string the is a valid term in a pan path.

Author:
loomis

Nested Class Summary
 
Nested classes/interfaces inherited from class org.quattor.pan.dml.data.Resource
Resource.Entry, Resource.Iterator
 
Constructor Summary
  HashResource()
           
protected HashResource(HashResource source)
          This constructor creates a shallow copy of the given HashResource.
 
Method Summary
 void checkRange(Range range)
          Determine if the element satisfies the given range constraint.
 void checkValidReplacement(Element newValue)
          Check that the newValue is a valid replacement for the this value.
 Element duplicate()
          This method does a "clone" of the given Element.
 boolean equals(java.lang.Object o)
          Require that all Elements implement an equals method.
 Element get(Term term)
          Retrieve the Element associated with the given Term (either an index or string key).
protected  java.util.Map<java.lang.String,Element> getBackingMap()
          This method is used to access the underlying map used to store the hash information.
 java.lang.String getTypeAsString()
          All Elements must return a string describing its type.
 int hashCode()
          Require that all Elements implement the hashCode method.
 Resource.Iterator iterator()
          Get an iterator which allows to run over the resources in the Resource.
 java.util.Set<Term> keySet()
           
 java.lang.String locateUndefinedElement()
          Determine if the element contains any undefined (transient) elements.
 Element protect()
          Return a protected version of this Element.
 Element put(Term term, Element newValue)
          Define the mapping between the given Term and given Element.
 int size()
          Get the number of elements in this Resource.
 java.lang.String toString()
          Require that all Elements implement a reasonable toString method.
 
Methods inherited from class org.quattor.pan.dml.data.Resource
rget, rgetList, rput
 
Methods inherited from class org.quattor.pan.dml.data.Element
checkInvalidSelfContext, checkRestrictedContext, defined, execute, exists, isBoolean, isDouble, isList, isLong, isNlist, isPersistent, isProperty, isProtected, isResource, isString, isTransient, writableCopy
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HashResource

public HashResource()

HashResource

protected HashResource(HashResource source)
This constructor creates a shallow copy of the given HashResource. The children of the referenced HashResource are not cloned, but they are protected.

Parameters:
source - HashResource to copy
Method Detail

duplicate

public Element duplicate()
Description copied from class: Element
This method does a "clone" of the given Element. Immutable Elements may return a reference to the same object. Mutable Elements (i.e. Resources) must provide an actual deep-copy of the Element. This method simply returns a reference to the same object and is suitable only for immutable subclasses. Mutable subclasses (i.e. Resources) must override this method to provide an appropriate deep copy. This is not actually named "clone" because it violates the conditions of that method for creating a duplicate of the instance in all cases.

Overrides:
duplicate in class Element
Returns:
deep-copy of Element for mutable elements, self-reference for immutable objects

get

public Element get(Term term)
            throws InvalidTermException
Description copied from class: Resource
Retrieve the Element associated with the given Term (either an index or string key).

Specified by:
get in class Resource
Parameters:
term - Term which acts as the key for the desired Element
Returns:
Element associated with the given Term
Throws:
InvalidTermException - thrown if the term is not of the appropriate type for the resource; the message should contain the string representation of the term

put

public Element put(Term term,
                   Element newValue)
            throws InvalidTermException
Description copied from class: Resource
Define the mapping between the given Term and given Element. The method returns the previous value or null if there was none.

Specified by:
put in class Resource
Parameters:
term - Term which acts as the key for the desired Element
newValue - Element to associate with the given Term
Returns:
previous value if it existed, null otherwise
Throws:
InvalidTermException - thrown if the term is not of the appropriate type for the resource; the message should contain the string representation of the term

size

public int size()
Description copied from class: Resource
Get the number of elements in this Resource.

Specified by:
size in class Resource
Returns:
number of elements in this Resource

keySet

public java.util.Set<Term> keySet()

locateUndefinedElement

public java.lang.String locateUndefinedElement()
Description copied from class: Element
Determine if the element contains any undefined (transient) elements. The call will return null if no undefined elements are found; it will return a string indicating the relative path if an undefined element is found. Subclasses MUST override this method appropriately. This default method will work only for elements which are not containers and not a transient element.

Overrides:
locateUndefinedElement in class Element
Returns:
String representation of the path of the undefined element, null otherwise

checkRange

public void checkRange(Range range)
                throws ValidationException
Description copied from class: Element
Determine if the element satisfies the given range constraint. This is used in the validation of the element. By default, this method with throw a ValidationException indicating that range checking of this element is not appropriate.

Overrides:
checkRange in class Element
Parameters:
range - Range to check Element against
Throws:
ValidationException - if the element cannot be compared to a range or if the element doesn't meet the range requirement

checkValidReplacement

public void checkValidReplacement(Element newValue)
                           throws EvaluationException
Description copied from class: Element
Check that the newValue is a valid replacement for the this value. This implementation will check if the newValue is assignable from the current value or that the newValue is either undef or null. If not, an evaluation exception will be thrown. This implementation should be overridden if more liberal replacements are allowed.

Overrides:
checkValidReplacement in class Element
Parameters:
newValue - the new value for the replacement
Throws:
EvaluationException - if the new value is not a valid replacement of the existing value

protect

public Element protect()
Description copied from class: Element
Return a protected version of this Element. The default implementation just returns to "this". Only unprotected resources will have to override this implementation.

Overrides:
protect in class Element
Returns:
protected version of the resource

getTypeAsString

public java.lang.String getTypeAsString()
Description copied from class: Element
All Elements must return a string describing its type. This value used in the serialization to machine profiles.

Specified by:
getTypeAsString in class Element
Returns:
String representation of Element's type

hashCode

public int hashCode()
Description copied from class: Element
Require that all Elements implement the hashCode method.

Specified by:
hashCode in class Element

equals

public boolean equals(java.lang.Object o)
Description copied from class: Element
Require that all Elements implement an equals method.

Specified by:
equals in class Element

getBackingMap

protected java.util.Map<java.lang.String,Element> getBackingMap()
This method is used to access the underlying map used to store the hash information. This method is used in the equals method to determine if one HashResource is equivalent to another. The map must not be modified by the caller.

Returns:
backing map for hash resource

toString

public java.lang.String toString()
Description copied from class: Element
Require that all Elements implement a reasonable toString method.

Specified by:
toString in class Element

iterator

public Resource.Iterator iterator()
Description copied from class: Resource
Get an iterator which allows to run over the resources in the Resource. Note that concurrent modification of the Resource is not permitted while actively using the iterator. The effects of doing so are undefined.

Specified by:
iterator in interface java.lang.Iterable<Resource.Entry>
Specified by:
iterator in class Resource
Returns:
Iterator which will allow access to the key, value pairs of the Resource


Copyright © 2011 Quattor. All Rights Reserved.