gov.usda.gdpc
Class AbstractDBElement

java.lang.Object
  extended bygov.usda.gdpc.AbstractDBElement
All Implemented Interfaces:
java.lang.Comparable, DBElement, java.util.Map
Direct Known Subclasses:
EnvironmentExperiment, Genotype, GenotypeExperiment, Locality, Locus, Phenotype, PhenotypeOntology, Taxon

public abstract class AbstractDBElement
extends java.lang.Object
implements DBElement

This class provides a skeletal implementation of the DBElement interface to minimize the effort required to implement this interface.

Author:
terryc

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  java.util.Map myProperties
          Defined properties for this database element
 
Constructor Summary
AbstractDBElement(java.util.Map properties, java.lang.String key)
          AbstractDBElement constructor.
AbstractDBElement(Property[] keys, java.util.Map properties, java.lang.String key)
           
 
Method Summary
 void clear()
          This operation is not supported.
 int compareTo(java.lang.Object o)
          Compares two database elements to determine there order based on the alphabetical order of the string returned by getName().
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(java.lang.Object value)
          Returns true if this map maps one or more keys to the specified value.
 java.util.Set entrySet()
          Returns a read-only set view of the mappings contained in this map.
 boolean equals(java.lang.Object obj)
          This determines if two database elements are equal.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 java.lang.String getDataSource()
          Returns the data source of this element.
 Identifier getID()
          Returns identifier of this element.
 java.lang.String getKey()
          Get the unique key for the element.
 java.lang.String getName()
          Returns the name of this database element.
 java.lang.Object getProperty(Property property)
          Returns the value of the specified property.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 java.util.Set keySet()
          Returns a read-only set view of the keys contained in this map.
 int numProperties()
          Returns the number of properties defined for this element.
 java.util.List properties()
          Return list of properties defined for this database element.
 boolean propsEqual(java.util.Map properties)
          Returns whether given properties exactly match properties of this instance.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          This operation is not supported.
 void putAll(java.util.Map t)
          This operation is not supported.
 java.lang.Object remove(java.lang.Object key)
          This operation is not supported.
 int size()
          Returns the number of key-value mappings in this map.
 java.lang.String toString()
          Returns the string representation of this database element.
 java.util.Collection values()
          Returns a read-only collection view of the values contained in this map.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.usda.gdpc.DBElement
getType
 
Methods inherited from interface java.util.Map
hashCode
 

Field Detail

myProperties

protected final java.util.Map myProperties
Defined properties for this database element

Constructor Detail

AbstractDBElement

public AbstractDBElement(java.util.Map properties,
                         java.lang.String key)
AbstractDBElement constructor.

Parameters:
properties - properties of this database element. The keys are the properties (type: Property) and the values are the corresponding value. Properties can not have a value equal to null. It is not allowed to have two keys that are the same.
key - unique key

AbstractDBElement

public AbstractDBElement(Property[] keys,
                         java.util.Map properties,
                         java.lang.String key)
Method Detail

getProperty

public java.lang.Object getProperty(Property property)
Returns the value of the specified property.

Specified by:
getProperty in interface DBElement
Parameters:
property - property to retrieve
Returns:
property value. null if not defined.

properties

public java.util.List properties()
Return list of properties defined for this database element.

Specified by:
properties in interface DBElement
Returns:
list of properties

getName

public java.lang.String getName()
Returns the name of this database element.

Specified by:
getName in interface DBElement
Returns:
the name

getDataSource

public java.lang.String getDataSource()
Returns the data source of this element.

Specified by:
getDataSource in interface DBElement
Returns:
data source

getID

public Identifier getID()
Returns identifier of this element.

Specified by:
getID in interface DBElement
Returns:
identifier

toString

public java.lang.String toString()
Returns the string representation of this database element.

Returns:
string representation

getKey

public java.lang.String getKey()
Get the unique key for the element.

Specified by:
getKey in interface DBElement
Returns:
key

compareTo

public int compareTo(java.lang.Object o)
Compares two database elements to determine there order based on the alphabetical order of the string returned by getName().

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the object to be compared
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this Object.

numProperties

public int numProperties()
Returns the number of properties defined for this element.

Specified by:
numProperties in interface DBElement
Returns:
number of properties

propsEqual

public final boolean propsEqual(java.util.Map properties)
Returns whether given properties exactly match properties of this instance.

Specified by:
propsEqual in interface DBElement
Parameters:
properties - properties to match.
Returns:
true if given properties exactly match this instance's properties.

equals

public final boolean equals(java.lang.Object obj)
This determines if two database elements are equal.

Specified by:
equals in interface java.util.Map
Parameters:
obj - object to test
Returns:
true if equal

clear

public void clear()
This operation is not supported.

Specified by:
clear in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException - this operation is not supported.

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains at a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)

Specified by:
containsKey in interface java.util.Map
Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.
Throws:
java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
java.lang.NullPointerException - if the key is null and this map does not not permit null keys (optional).

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations of the Map interface.

Specified by:
containsValue in interface java.util.Map
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.
Throws:
java.lang.ClassCastException - if the value is of an inappropriate type for this map (optional).
java.lang.NullPointerException - if the value is null and this map does not not permit null values (optional).

entrySet

public java.util.Set entrySet()
Returns a read-only set view of the mappings contained in this map.

Specified by:
entrySet in interface java.util.Map
Returns:
a set view of the mappings contained in this map.

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

Specified by:
get in interface java.util.Map
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
Throws:
java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
java.lang.NullPointerException - key is null and this map does not not permit null keys (optional).
See Also:
containsKey(Object)

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in interface java.util.Map
Returns:
true if this map contains no key-value mappings.

keySet

public java.util.Set keySet()
Returns a read-only set view of the keys contained in this map.

Specified by:
keySet in interface java.util.Map
Returns:
a set view of the keys contained in this map.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
This operation is not supported.

Specified by:
put in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException - this operation is not supported.

putAll

public void putAll(java.util.Map t)
This operation is not supported.

Specified by:
putAll in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException - this operation is not supported.

remove

public java.lang.Object remove(java.lang.Object key)
This operation is not supported.

Specified by:
remove in interface java.util.Map
Throws:
java.lang.UnsupportedOperationException - this operation is not supported.

size

public int size()
Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface java.util.Map
Returns:
the number of key-value mappings in this map.

values

public java.util.Collection values()
Returns a read-only collection view of the values contained in this map.

Specified by:
values in interface java.util.Map
Returns:
a collection view of the values contained in this map.