de.fhstralsund.vinets.structure
Class DefaultNetElement

java.lang.Object
  extended by de.fhstralsund.vinets.structure.DefaultNetElement
All Implemented Interfaces:
NetElement, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
AbstractGraph, SimpleGraph.SimpleEdge, SimpleGraph.SimpleNode

public abstract class DefaultNetElement
extends java.lang.Object
implements NetElement

The standard implementation for NetElements in VinetS.

See Also:
Serialized Form

Field Summary
protected  NetElement host
          The NetElement containing this NetElement (its parent in hierarchy).
protected  java.util.Map labelMap
          A container of (key, label)-pairs for all properties of this NetElement.
protected  NetElement original
          A NetElement from which this one was copied.
 
Constructor Summary
protected DefaultNetElement()
           
protected DefaultNetElement(NetElement host)
           
protected DefaultNetElement(java.lang.String name, NetElement host)
           
protected DefaultNetElement(java.lang.String name, NetElement host, java.lang.Object data)
           
 
Method Summary
 void clearLabels()
          Clears all labels of this NetElement.
 java.lang.Object clone()
          Creates and returns a special copy of this NetElement.
 boolean containsLabel(java.lang.Object key)
          Returns true if the label contains a mapping for the specified key.
 boolean getBooleanLabel(java.lang.Object key)
          Returns the label value associated with the passed key as boolean value.
 java.lang.Object getData()
          Delivers application specific data stored by this NetElement which have no relation to the network algorithms.
 double getDoubleLabel(java.lang.Object key)
          Returns the label value associated with the passed key as double value.
 NetElementGeometry getGeometry()
          Delivers the NetElementGeometry instance containing the position and the size of this NetElement in the relative coordinate system of its host.
 NetElement getHost()
          Delivers the parent of this NetElement in the inclusion hierarchy.
 java.lang.Object getID()
          Delivers the identifier of this NetElement.
 int getIntLabel(java.lang.Object key)
          Returns the label value associated with the passed key as int value.
 java.lang.Object getLabel(java.lang.Object key)
          Returns the label value associated with the passed key, or null if the labelMap does not contain a mapping for this key.
 java.util.Set getLabelKeySet()
          Returns a Set which contains the Keys inside the LabelMap.
 java.lang.String getName()
          Delivers a human readable name of this NetElement.
 NetElement getOriginal()
          Delivers the NetElement from which this one was copied.
 de.fhstralsund.vinets.graphics.NetElementRepresentation getRepresentation()
          Delivers the NetElementRepresentation instance containing information for rendering this NetElement.
 java.lang.Object removeLabel(java.lang.Object key)
          Removes a property stored as label from this NetElement.
 void setBooleanLabel(java.lang.Object key, boolean b)
          Adds to this NetElement a boolean value label or changes it.
 void setData(java.lang.Object info)
          Assigns new application specific data to this NetElement which have no relation to the network algorithms.
 void setDoubleLabel(java.lang.Object key, double x)
          Adds to this NetElement a double value label or changes it.
 void setGeometry(NetElementGeometry geom)
          Assigns a new NetElementGeometry instance containing the position and the size of this NetElement in the relative coordinate system of its host.
 void setIntLabel(java.lang.Object key, int i)
          Adds to this NetElement an integer value label or changes it.
 void setLabel(java.lang.Object key, java.lang.Object value)
          Adds a new property to be stored as a label of this NetElement or changes the value of an existing property.
 void setName(java.lang.String name)
          Sets a human readable name for this NetElement.
 void setRepresentation(de.fhstralsund.vinets.graphics.NetElementRepresentation pres)
          Assigns a new NetElementRepresentation instance containing information for rendering this NetElement.
 java.lang.String toString()
          Returns a string representation of this NetElement.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

host

protected NetElement host
The NetElement containing this NetElement (its parent in hierarchy). This attribute is set during creation.


original

protected NetElement original
A NetElement from which this one was copied. This attribute is set by the clone() method.


labelMap

protected java.util.Map labelMap
A container of (key, label)-pairs for all properties of this NetElement. The corresponding HashMap is created

Constructor Detail

DefaultNetElement

protected DefaultNetElement(java.lang.String name,
                            NetElement host,
                            java.lang.Object data)

DefaultNetElement

protected DefaultNetElement()

DefaultNetElement

protected DefaultNetElement(NetElement host)

DefaultNetElement

protected DefaultNetElement(java.lang.String name,
                            NetElement host)
Method Detail

getID

public java.lang.Object getID()
Delivers the identifier of this NetElement. Within one session of the VinetS application, it is unique.

Specified by:
getID in interface NetElement
Returns:
the identifier of this NetElement.

getName

public java.lang.String getName()
Delivers a human readable name of this NetElement.

Specified by:
getName in interface NetElement
Returns:
a human readable name of this NetElement.

setName

public void setName(java.lang.String name)
Sets a human readable name for this NetElement.

Specified by:
setName in interface NetElement
Parameters:
name - the name.

getGeometry

public NetElementGeometry getGeometry()
Delivers the NetElementGeometry instance containing the position and the size of this NetElement in the relative coordinate system of its host.

Specified by:
getGeometry in interface NetElement
Returns:
a reference to the NetElementGeometry.

setGeometry

public void setGeometry(NetElementGeometry geom)
Assigns a new NetElementGeometry instance containing the position and the size of this NetElement in the relative coordinate system of its host.

Specified by:
setGeometry in interface NetElement
Parameters:
geom - a reference to the new NetElementGeometry.

getRepresentation

public de.fhstralsund.vinets.graphics.NetElementRepresentation getRepresentation()
Delivers the NetElementRepresentation instance containing information for rendering this NetElement.

Specified by:
getRepresentation in interface NetElement
Returns:
a reference to the graphic representation of this NetElement.

setRepresentation

public void setRepresentation(de.fhstralsund.vinets.graphics.NetElementRepresentation pres)
Assigns a new NetElementRepresentation instance containing information for rendering this NetElement.

Specified by:
setRepresentation in interface NetElement
Parameters:
pres - a reference to the graphic representation of this NetElement.

getData

public java.lang.Object getData()
Delivers application specific data stored by this NetElement which have no relation to the network algorithms.

Specified by:
getData in interface NetElement
Returns:
a reference to the external data.

setData

public void setData(java.lang.Object info)
Assigns new application specific data to this NetElement which have no relation to the network algorithms.

Specified by:
setData in interface NetElement
Parameters:
info - a reference to the external information to be stored.

getHost

public NetElement getHost()
Delivers the parent of this NetElement in the inclusion hierarchy. Usually, the host is a container containing this NetElement. Moreover, the host was responsible for creating this NetElement, i.e. the host provides factory methods.

Specified by:
getHost in interface NetElement
Returns:
the NetElement containing this NetElement.

getOriginal

public NetElement getOriginal()
Delivers the NetElement from which this one was copied. The corresponding attribute of this NetElement is set by the clone() method and it is used for maintaining the isomorphism between the copy and its original.

Specified by:
getOriginal in interface NetElement
Returns:
the NetElement from which this one had been copied.

setLabel

public void setLabel(java.lang.Object key,
                     java.lang.Object value)
Adds a new property to be stored as a label of this NetElement or changes the value of an existing property. All labels are stored in a HashMap on each NetElement. The Object used as key should not change in a manner that affects equals comparisons while used for a label. The key should not be null, but for the value this restriction does not hold.

Specified by:
setLabel in interface NetElement
Parameters:
key - an Object with which the specified value is to be associated.
value - an Object to be associated with the specified key.
Throws:
java.lang.IllegalArgumentException - if the key is null.

getLabel

public java.lang.Object getLabel(java.lang.Object key)
Returns the label value associated with the passed key, or null if the labelMap does not contain a mapping for this key. A return value of null does not necessarily indicate that there is no mapping for the key; it is also possible that the labelMap explicitly maps the key to null. The containsLabel method may be used to distinguish these two cases.

Specified by:
getLabel in interface NetElement
Parameters:
key - the key whose associated value is to be returned.
Returns:
the value to which the labelMap maps the specified key or null if there is no mapping for this key.
See Also:
setLabel(Object, Object)

getLabelKeySet

public java.util.Set getLabelKeySet()
Description copied from interface: NetElement
Returns a Set which contains the Keys inside the LabelMap.

Specified by:
getLabelKeySet in interface NetElement
Returns:
a Set of Keys

containsLabel

public boolean containsLabel(java.lang.Object key)
Returns true if the label contains a mapping for the specified key.

Specified by:
containsLabel in interface NetElement
Parameters:
key - the key whose presence as label is to be tested.
Returns:
true if the label contains a mapping for the specified key.
See Also:
setLabel(Object, Object)

removeLabel

public java.lang.Object removeLabel(java.lang.Object key)
Removes a property stored as label from this NetElement.

Specified by:
removeLabel in interface NetElement
Parameters:
key - the key of the property to remove.
Returns:
the previous value associated to that key or null.
See Also:
setLabel(Object, Object)

clearLabels

public void clearLabels()
Clears all labels of this NetElement.

Specified by:
clearLabels in interface NetElement

setIntLabel

public void setIntLabel(java.lang.Object key,
                        int i)
Adds to this NetElement an integer value label or changes it. Convenience method - equivalent to setLabel(key, new Integer(i))}.

Specified by:
setIntLabel in interface NetElement
Parameters:
key - an Object with which the integer value is to be associated.
i - an int value to be associated with the specified key.
See Also:
setLabel(Object, Object)

getIntLabel

public int getIntLabel(java.lang.Object key)
Returns the label value associated with the passed key as int value. Convenience method - equivalent to containsLabel(key) ? ((Integer)getLabel(key)).intValue()) : Integer.MAX_VALUE.

Specified by:
getIntLabel in interface NetElement
Parameters:
key - the key whose associated integer value is to be returned.
Returns:
an int to which the label maps the specified key or Integer.MAX_VALUE if there is no mapping for the key.
See Also:
getLabel(Object)

setDoubleLabel

public void setDoubleLabel(java.lang.Object key,
                           double x)
Adds to this NetElement a double value label or changes it. Convenience method - equivalent to setLabel(key, new Double(x)).

Specified by:
setDoubleLabel in interface NetElement
Parameters:
key - an Object with which the double value is to be associated.
x - a double value to be associated with the specified key.
See Also:
setLabel(Object, Object)

getDoubleLabel

public double getDoubleLabel(java.lang.Object key)
Returns the label value associated with the passed key as double value. Convenience method - equivalent to containsLabel(key) ? ((Double)getLabel(key)).doubleValue() : Double.NaN.

Specified by:
getDoubleLabel in interface NetElement
Parameters:
key - the key whose associated double value is to be returned.
Returns:
a double to which the label maps the specified key. or Double.NaN if there is no mapping for the key.
See Also:
getLabel(Object)

setBooleanLabel

public void setBooleanLabel(java.lang.Object key,
                            boolean b)
Adds to this NetElement a boolean value label or changes it. Convenience method - equivalent to setLabel(key, new Boolean(i)).

Specified by:
setBooleanLabel in interface NetElement
Parameters:
key - an Object with which the boolean value is to be associated.
b - true or false to be associated with the specified key.
See Also:
setLabel(Object, Object)

getBooleanLabel

public boolean getBooleanLabel(java.lang.Object key)
Returns the label value associated with the passed key as boolean value. Convenience method - equivalent to containsLabel(key) ? ((Boolean)getLabel(key)).booleanValue() : false.

Specified by:
getBooleanLabel in interface NetElement
Parameters:
key - the key whose associated boolean value is to be returned.
Returns:
a boolean value to which the label maps the specified key.
See Also:
getLabel(Object)

clone

public java.lang.Object clone()
Creates and returns a special copy of this NetElement. The copy has a new ID, its attribute original is set to this NetElement. The attributes name, host and data are shared by the copy and this original. The attributes geometry, representation and labelMap are cloned - but notice that the (key, value)-pairs for properties in the labelMap are shared. So, do not change a value Object associated to a key after cloning. Instead, remove the label and set a new one, if a change is needed.

Overrides:
clone in class java.lang.Object
Returns:
a new DefaultNetElement instance equal to this one.

toString

public java.lang.String toString()
Returns a string representation of this NetElement.

Overrides:
toString in class java.lang.Object
Returns:
the name of this NetElement.