com.swfm.mica.core
Class MiGeneralAttributes

java.lang.Object
  extended bycom.swfm.mica.core.MiGeneralAttributes
All Implemented Interfaces:
java.lang.Cloneable, MiiCopyable
Direct Known Subclasses:
MiAttributes

public abstract class MiGeneralAttributes
extends java.lang.Object
implements MiiCopyable, java.lang.Cloneable

This class allocates and maintains an arbitrary group of attribute values. The values can be either object-valued, integer-valued, double-valued, or boolean-valued. Each attribute can also be specified as being inherited.

Instances of this class can be immutable (the default) which means modifications wil return a new instance, leaving the original unchanged.

Instances of this class are cached (see MiAttributeCache) to reduce memory requirements.

Version:
%I% %G%
Author:
Michael L. Davis

Constructor Summary
MiGeneralAttributes(boolean immutable, int numberOfAttributes, int startObjIndex, int numObjAttributes, int startIntIndex, int numIntAttributes, int startDblIndex, int numDblAttributes, int startBoolIndex, int numBoolAttributes)
          Constructs a new MiGeneralAttributes.
MiGeneralAttributes(int numberOfAttributes, int startObjIndex, int numObjAttributes, int startIntIndex, int numIntAttributes, int startDblIndex, int numDblAttributes, int startBoolIndex, int numBoolAttributes)
          Constructs a new MiGeneralAttributes.
 
Method Summary
abstract  java.lang.String cacheToString()
          For debugging, return the number and a description of all of the attributes created so far.
 java.lang.String dump()
          For debug.
 boolean equals(java.lang.Object obj)
          Gets whether this MiGeneralAttributes and the given MiGeneralAttributes are equal.
 java.lang.Object getAttribute(int which)
          Gets the value of the object-valued attribute.
 java.lang.String getAttributeValue(java.lang.String name)
          Gets the value of the attribute with the given name as a text string.
 java.lang.Object getAttributeValueAsObject(int index)
          Gets the value of the attribute with the given name as an object.
 boolean getBooleanAttribute(int which)
          Gets the value of the boolean-valued attribute.
 double getDoubleAttribute(int which)
          Gets the value of the double-valued attribute.
 int getIndexOfAttribute(java.lang.String name)
          Gets the index of the attribute with the given name.
 int getIntegerAttribute(int which)
          Gets the value of the integer-valued attribute.
 MiGeneralAttributes getModifiedAttributes(int which, boolean value)
          Sets the value of the attribute with the given index to the given value.
 MiGeneralAttributes getModifiedAttributes(int which, double value)
          Sets the value of the attribute with the given index to the given value.
 MiGeneralAttributes getModifiedAttributes(int which, int value)
          Sets the value of the attribute with the given index to the given value.
 MiGeneralAttributes getModifiedAttributes(int which, java.lang.Object object)
          Sets the value of the attribute with the given index to the given value.
 MiGeneralAttributes getModifiedAttributes(java.lang.String name, java.lang.String value)
          Sets the value of the attribute with the given index to the given value.
abstract  java.lang.String getNameOfAttribute(int index)
          Gets the name of the attribute specified by the given index.
 int getNumberOfAttributes()
          Gets the number of attributes values
 int getNumUsing()
           
 boolean hasAttribute(java.lang.String name)
          Gets whether an attribute with the given name exists.
 int hashCode()
          Gets the hopefully unique value identifying this MiGeneralAttributes based on the values of the attributes.
 MiGeneralAttributes inheritFrom(MiGeneralAttributes from)
          Sets the values of any inherited attributes in this MiGeneralAttributes from the non-inherited attributes in the given MiGeneralAttributes .
 MiGeneralAttributes inheritFromAll(MiGeneralAttributes from)
          Sets the values of all inherited attributes from the given attributes.
 void initializeAsInheritedAttributes()
          Sets all attributes to be inherited.
 MiGeneralAttributes initializeAsOverrideAttributes(boolean flag)
          Sets all attributes to be 'not inherited'.
 boolean isImmutable()
          Gets whether this MiGeneralAttributes can be changed.
 boolean isInheritedAttribute(int which)
          Gets whether the value of the attribute with the given index is to be inherited.
 java.lang.Object makeCopy()
          Makes and returns a copy of this class.
 MiGeneralAttributes overrideFrom(MiGeneralAttributes from)
          Sets the values of all attributes in this MiGeneralAttributes for which the corresponding attribute in the given MiGeneralAttributes is not inherited.
 MiGeneralAttributes overrideFromPermanent(MiGeneralAttributes from)
          Sets the values of all attributes in this MiGeneralAttributes for which the corresponding attribute in the given MiGeneralAttributes is not inherited AND the for which the corresponding attribute in this MiGeneralAttributes IS inherited.
 MiGeneralAttributes overrideFromPermanent2(MiGeneralAttributes from)
          Sets the values of all attributes in this MiGeneralAttributes for which the corresponding attribute in the given MiGeneralAttributes is not inherited.
 void setIsImmutable(boolean flag)
          Sets whether this MiGeneralAttributes can be changed.
 MiGeneralAttributes setIsInheritedAttribute(int which, boolean flag)
          Sets whether the value of the attribute with the given index is to be inherited.
 void setStaticAttribute(int which, boolean value)
          Sets the value of the attribute with the given index to the given value.
 void setStaticAttribute(int which, double value)
          Sets the value of the attribute with the given index to the given value.
 void setStaticAttribute(int which, int value)
          Sets the value of the attribute with the given index to the given value.
 void setStaticAttribute(int which, java.lang.Object obj)
          Sets the value of the attribute with the given index to the given value.
 void setStaticAttributeValue(int index, java.lang.String value)
          Sets the attribute with the given index to the given value.
 java.lang.String toString()
          Returns information about this MiPart.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MiGeneralAttributes

public MiGeneralAttributes(boolean immutable,
                           int numberOfAttributes,
                           int startObjIndex,
                           int numObjAttributes,
                           int startIntIndex,
                           int numIntAttributes,
                           int startDblIndex,
                           int numDblAttributes,
                           int startBoolIndex,
                           int numBoolAttributes)
Constructs a new MiGeneralAttributes.

Parameters:
immutable - true if this cannot be changed.
numberOfAttributes - the total number of attributes (which is just the sum of the numbers below)
startObjIndex - the first index for object attributes
numObjAttributes - the number of object attributes
startIntIndex - the first index for int attributes
numIntAttributes - the number of int attributes
startDblIndex - the first index for double attributes
numDblAttributes - the number of double attributes
startBoolIndex - the first index for boolean attributes
numBoolAttributes - the number of boolean attributes

MiGeneralAttributes

public MiGeneralAttributes(int numberOfAttributes,
                           int startObjIndex,
                           int numObjAttributes,
                           int startIntIndex,
                           int numIntAttributes,
                           int startDblIndex,
                           int numDblAttributes,
                           int startBoolIndex,
                           int numBoolAttributes)
Constructs a new MiGeneralAttributes.

Parameters:
numberOfAttributes - the total number of attributes (which is just the sum of the numbers below)
startObjIndex - the first index for object attributes
numObjAttributes - the number of object attributes
startIntIndex - the first index for int attributes
numIntAttributes - the number of int attributes
startDblIndex - the first index for double attributes
numDblAttributes - the number of double attributes
startBoolIndex - the first index for boolean attributes
numBoolAttributes - the number of boolean attributes
Method Detail

cacheToString

public abstract java.lang.String cacheToString()
For debugging, return the number and a description of all of the attributes created so far.

Returns:
a textual description of the attribute cache

getNameOfAttribute

public abstract java.lang.String getNameOfAttribute(int index)
Gets the name of the attribute specified by the given index.

Parameters:
index - the index of an attribute
Returns:
the name of the attribute

isImmutable

public boolean isImmutable()
Gets whether this MiGeneralAttributes can be changed.

Returns:
true if immutable

setIsImmutable

public void setIsImmutable(boolean flag)
Sets whether this MiGeneralAttributes can be changed. This shoudl rarely, if ever, be used outside of Mica.

Parameters:
flag - true if immutable

equals

public boolean equals(java.lang.Object obj)
Gets whether this MiGeneralAttributes and the given MiGeneralAttributes are equal.

Parameters:
obj - the MiGeneralAttributes to compare to
Returns:
true if they are equal

hashCode

public int hashCode()
Gets the hopefully unique value identifying this MiGeneralAttributes based on the values of the attributes. This is used by the attribute cache manager to store and retrieve MiGeneralAttributes.

Returns:
the hash code for this object

makeCopy

public java.lang.Object makeCopy()
Makes and returns a copy of this class.

Specified by:
makeCopy in interface MiiCopyable
Returns:
the copy of this class

setStaticAttribute

public void setStaticAttribute(int which,
                               java.lang.Object obj)
Sets the value of the attribute with the given index to the given value. Note: mutability is not checked.

Parameters:
which - the index of the attribute
obj - the new value of the attribute

setStaticAttribute

public void setStaticAttribute(int which,
                               int value)
Sets the value of the attribute with the given index to the given value. Note: mutability is not checked.

Parameters:
which - the index of the attribute
value - the new value of the attribute

setStaticAttribute

public void setStaticAttribute(int which,
                               double value)
Sets the value of the attribute with the given index to the given value. Note: mutability is not checked.

Parameters:
which - the index of the attribute
value - the new value of the attribute

setStaticAttribute

public void setStaticAttribute(int which,
                               boolean value)
Sets the value of the attribute with the given index to the given value. Note: mutability is not checked.

Parameters:
which - the index of the attribute
value - the new value of the attribute

isInheritedAttribute

public boolean isInheritedAttribute(int which)
Gets whether the value of the attribute with the given index is to be inherited. Whenever a value is assigned to an attribute, it is set to be NOT inherited.

Parameters:
which - the index of the attribute
Returns:
true if the attribute is inherited

setIsInheritedAttribute

public MiGeneralAttributes setIsInheritedAttribute(int which,
                                                   boolean flag)
Sets whether the value of the attribute with the given index is to be inherited. Whenever a value is assigned to an attribute, it is set to be NOT inherited.

Parameters:
which - the index of the attribute
flag - true if the attribute is inherited

inheritFromAll

public MiGeneralAttributes inheritFromAll(MiGeneralAttributes from)
Sets the values of all inherited attributes from the given attributes. The 'inherited flag' is not modified for any of the attributes.

Parameters:
from - the attributes from which we will get the values to assign to this attributes inherited attribute values
Returns:
the resultant attributes

inheritFrom

public MiGeneralAttributes inheritFrom(MiGeneralAttributes from)
Sets the values of any inherited attributes in this MiGeneralAttributes from the non-inherited attributes in the given MiGeneralAttributes . The 'inherited flag' is not modified for any of the attributes.

Parameters:
from - the attributes from which we will get the non-inherited values to assign to this attributes inherited attribute values
Returns:
the resultant attributes

overrideFrom

public MiGeneralAttributes overrideFrom(MiGeneralAttributes from)
Sets the values of all attributes in this MiGeneralAttributes for which the corresponding attribute in the given MiGeneralAttributes is not inherited. The 'inherited flag' is not modified for any of the attributes.

Parameters:
from - the attributes from which we will get the non-inherited values to assign to this attributes attribute values
Returns:
the resultant attributes

overrideFromPermanent

public MiGeneralAttributes overrideFromPermanent(MiGeneralAttributes from)
Sets the values of all attributes in this MiGeneralAttributes for which the corresponding attribute in the given MiGeneralAttributes is not inherited AND the for which the corresponding attribute in this MiGeneralAttributes IS inherited. The 'inherited flag' IS modified for all of the attributes overridden.

Parameters:
from - the attributes from which we will get the non-inherited values to assign to this attributes attribute values
Returns:
the resultant attributes

overrideFromPermanent2

public MiGeneralAttributes overrideFromPermanent2(MiGeneralAttributes from)
Sets the values of all attributes in this MiGeneralAttributes for which the corresponding attribute in the given MiGeneralAttributes is not inherited. The 'inherited flag' IS modified for all of the attributes overridden.

Parameters:
from - the attributes from which we will get the non-inherited values to assign to this attributes attribute values
Returns:
the resultant attributes

initializeAsOverrideAttributes

public MiGeneralAttributes initializeAsOverrideAttributes(boolean flag)
Sets all attributes to be 'not inherited'.

Returns:
the resultant attributes

initializeAsInheritedAttributes

public void initializeAsInheritedAttributes()
Sets all attributes to be inherited.

Returns:
the resultant attributes

getModifiedAttributes

public MiGeneralAttributes getModifiedAttributes(int which,
                                                 java.lang.Object object)
Sets the value of the attribute with the given index to the given value. If mutable then this MiGeneralAttributes is returned after modification, otherwise a new MiGeneralAttributes is created returned with the new attribute value.

Parameters:
which - the index of the attribute
Returns:
the resultant attributes

getModifiedAttributes

public MiGeneralAttributes getModifiedAttributes(int which,
                                                 int value)
Sets the value of the attribute with the given index to the given value. If mutable then this MiGeneralAttributes is returned after modification, otherwise a new MiGeneralAttributes is created returned with the new attribute value.

Parameters:
which - the index of the attribute
value - the new value of the attribute
Returns:
the resultant attributes

getModifiedAttributes

public MiGeneralAttributes getModifiedAttributes(int which,
                                                 double value)
Sets the value of the attribute with the given index to the given value. If mutable then this MiGeneralAttributes is returned after modification, otherwise a new MiGeneralAttributes is created returned with the new attribute value.

Parameters:
which - the index of the attribute
value - the new value of the attribute
Returns:
the resultant attributes

getModifiedAttributes

public MiGeneralAttributes getModifiedAttributes(int which,
                                                 boolean value)
Sets the value of the attribute with the given index to the given value. If mutable then this MiGeneralAttributes is returned after modification, otherwise a new MiGeneralAttributes is created returned with the new attribute value.

Parameters:
which - the index of the attribute
value - the new value of the attribute
Returns:
the resultant attributes

getModifiedAttributes

public MiGeneralAttributes getModifiedAttributes(java.lang.String name,
                                                 java.lang.String value)
Sets the value of the attribute with the given index to the given value. If mutable then this MiGeneralAttributes is returned after modification, otherwise a new MiGeneralAttributes is created returned with the new attribute value. The value is assigned directly for object-valued attributes, otherwise it is parsed to get the value (i.e. Utility.toInteger(value) for integer-valued attributes and if !Utility.isInteger(value) then the value is looked up in MiSystem.getValueOfAttributeValueName(value)).

Parameters:
value - the new value of the attribute
Returns:
the resultant attributes

getAttribute

public java.lang.Object getAttribute(int which)
Gets the value of the object-valued attribute.

Parameters:
which - the index of the attribute
Returns:
the value

getIntegerAttribute

public int getIntegerAttribute(int which)
Gets the value of the integer-valued attribute.

Parameters:
which - the index of the attribute
Returns:
the value

getDoubleAttribute

public double getDoubleAttribute(int which)
Gets the value of the double-valued attribute.

Parameters:
which - the index of the attribute
Returns:
the value

getBooleanAttribute

public boolean getBooleanAttribute(int which)
Gets the value of the boolean-valued attribute.

Parameters:
which - the index of the attribute
Returns:
the value

getNumberOfAttributes

public int getNumberOfAttributes()
Gets the number of attributes values

Returns:
the number of attribute values

hasAttribute

public boolean hasAttribute(java.lang.String name)
Gets whether an attribute with the given name exists.

Returns:
true if such an attribute exists.

getIndexOfAttribute

public int getIndexOfAttribute(java.lang.String name)
Gets the index of the attribute with the given name.

Returns:
the index
Throws:
java.lang.IllegalArgumentException - if the name is not a valid attribute name

setStaticAttributeValue

public void setStaticAttributeValue(int index,
                                    java.lang.String value)
Sets the attribute with the given index to the given value. The value is assigned directly to an object-valued attributes, otherwise it is parsed to get the value (i.e. Utility.toInteger(value) for integer-valued attributes and if !Utility.isInteger(value) then the value is looked up in MiSystem.getValueOfAttributeValueName(value)).

Parameters:
index - the index of an attribute
value - the new value of the attribute
Throws:
java.lang.RuntimeException - attempt to modify immutable attributes

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String name)
Gets the value of the attribute with the given name as a text string. This will be object.toString() for object-value attributes, MiiTypes.Mi_NULL_VALUE_NAME for null valued object-value attributes, otherwise it will be the value in text format.

Returns:
the value as a string

getAttributeValueAsObject

public java.lang.Object getAttributeValueAsObject(int index)
Gets the value of the attribute with the given name as an object. This will be the object for object-value attributes, and the corresponding java.lang class otherwise (i.e. Integer, Double, Boolean).

Returns:
the value as an object

dump

public java.lang.String dump()
For debug. Gets a text description of the names and values of all the attributes in this MiGeneralAttributes.

Returns:
the description

toString

public java.lang.String toString()
Returns information about this MiPart.

Returns:
textual information (class name + unique numerical id)

getNumUsing

public int getNumUsing()