Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.metacosm.util
Class LongProperty  view LongProperty download LongProperty.java

java.lang.Object
  extended byorg.metacosm.util.Property
      extended byorg.metacosm.util.LongProperty
All Implemented Interfaces:
java.lang.Cloneable, org.metacosm.framework.persistence.Persistent, java.io.Serializable

public final class LongProperty
extends Property

A Property with long value. TODO: min and max values can be stored in a memory-friendly way. They aren't stored as two long or double * values but as a special immutable Interval object (in fact a * reference to this object). A hashtable links (min, max) couples to IntervalManager objects, so for a given interval, only one Interval exists.


Field Summary
private  java.util.List absList
          AbsoluteModifiers list
private  AbsoluteModifier absModifier
          The first max priority AbsoluteModifier
private  long initialValue
           
private  LongInterval interval
          Domain interval
private  java.util.List randomValues
          RandomAbsoluteModifier values list
private  long relDelta
          RelativeModifiers final effect
private  long value
           
(package private)  int valueIndex
          RandomAbsoluteModifier value index (for the first max priority AbsoluteModifier) -1 if not a RandomAbsoluteModifier
>= 0 otherwise
 
Fields inherited from class org.metacosm.util.Property
name
 
Constructor Summary
  LongProperty(java.lang.String name, long value)
          LongProperty constructor without a specified interval.
private LongProperty(java.lang.String name, long value, LongInterval interval)
          Used by clone() to produce a property with the same name and value, and with the same shared interval.
  LongProperty(java.lang.String name, long value, long min, long max)
          LongProperty constructor with a specified interval.
 
Method Summary
 void applyModifier(AbsoluteModifier absMod)
          Applies an absolute modifier to the property.
 void applyModifier(RelativeModifier relMod)
          Applies a relative modifier to the property.
private  void calculate()
           
 java.lang.Object clone()
          This method may be called to create a new copy of the Object.
 long getLongValue()
           
 long getMaxValue()
           
 long getMinValue()
           
 java.lang.Object getValue()
           
 void load(java.io.InputStream is)
          Loads from the stream.
 void removeModifier(AbsoluteModifier absMod)
          Removes an absolute modifier previously applied to the property.
 void removeModifier(RelativeModifier relMod)
          Removes a relative modifier previously applied to the property.
 void save(java.io.OutputStream os)
          Saves on the stream.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class org.metacosm.util.Property
getName
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

private long value

initialValue

private long initialValue

absList

private java.util.List absList
AbsoluteModifiers list


randomValues

private java.util.List randomValues
RandomAbsoluteModifier values list


absModifier

private AbsoluteModifier absModifier
The first max priority AbsoluteModifier


valueIndex

int valueIndex
RandomAbsoluteModifier value index (for the first max priority AbsoluteModifier) -1 if not a RandomAbsoluteModifier
>= 0 otherwise


relDelta

private long relDelta
RelativeModifiers final effect


interval

private LongInterval interval
Domain interval

Constructor Detail

LongProperty

public LongProperty(java.lang.String name,
                    long value)
             throws java.lang.IllegalArgumentException
LongProperty constructor without a specified interval. Interval is defined as encompassing all long values.


LongProperty

public LongProperty(java.lang.String name,
                    long value,
                    long min,
                    long max)
             throws java.lang.IllegalArgumentException
LongProperty constructor with a specified interval.


LongProperty

private LongProperty(java.lang.String name,
                     long value,
                     LongInterval interval)
Used by clone() to produce a property with the same name and value, and with the same shared interval.

Method Detail

getValue

public java.lang.Object getValue()
Specified by:
getValue in class Property

getLongValue

public long getLongValue()

getMinValue

public long getMinValue()

getMaxValue

public long getMaxValue()

calculate

private void calculate()

applyModifier

public void applyModifier(AbsoluteModifier absMod)
Applies an absolute modifier to the property. If the absolute modifier has the highest priority, property value is computed anew, and then bounded.

Specified by:
applyModifier in class Property

applyModifier

public void applyModifier(RelativeModifier relMod)
Applies a relative modifier to the property. Property value is computed anew, and then bounded.

Specified by:
applyModifier in class Property

removeModifier

public void removeModifier(AbsoluteModifier absMod)
Removes an absolute modifier previously applied to the property. Absolute modifier list is updated, and a new absolute modifier is chosen according to priority. Property value is then computed anew.

Specified by:
removeModifier in class Property

removeModifier

public void removeModifier(RelativeModifier relMod)
Removes a relative modifier previously applied to the property. Property value is computed anew, and then bounded.

Specified by:
removeModifier in class Property

save

public void save(java.io.OutputStream os)
          throws java.io.IOException
Description copied from interface: org.metacosm.framework.persistence.Persistent
Saves on the stream.


load

public void load(java.io.InputStream is)
          throws java.io.IOException
Description copied from interface: org.metacosm.framework.persistence.Persistent
Loads from the stream.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


clone

public java.lang.Object clone()
Description copied from class: java.lang.Object
This method may be called to create a new copy of the Object. The typical behavior is as follows:
  • o == o.clone() is false
  • o.getClass() == o.clone().getClass() is true
  • o.equals(o) is true

However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object)>Object.equals(Object) 55 .

If the Object you call clone() on does not implement java.lang.Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.

Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.

All array types implement Cloneable, and override this method as follows (it should never fail):

 public Object clone()
 {
   try
     {
       super.clone();
     }
   catch (CloneNotSupportedException e)
     {
       throw new InternalError(e.getMessage());
     }
 }
 

Overrides:
clone in class Property