net.sourceforge.cilib.type.types
Class Bit

java.lang.Object
  extended by net.sourceforge.cilib.type.types.Numeric
      extended by net.sourceforge.cilib.type.types.Bit
All Implemented Interfaces:
Serializable, Comparable<Numeric>, BoundedType, Randomizable, Resetable, Type, Cloneable

public class Bit
extends Numeric

Implemetantation of the Bit object. The Bit object is the Type system equivalent of a bit.

Author:
Gary Pampara
See Also:
Serialized Form

Constructor Summary
Bit()
          Create a Bit object with a random state value.
Bit(Bit copy)
          Copy constructor.
Bit(boolean state)
          Copy-constructor.
 
Method Summary
 int compareTo(Numeric other)
          
 boolean equals(Object other)
          Compare the specified object with this type for equality.
 boolean getBit()
          Return the state of the curent Bit object.
 Bit getClone()
          Create a cloned copy of the current object and return it.
 int getInt()
          Get the integer representation of the current Bit object.
 double getReal()
          Get the state of the Bit returned as a double value.
 String getRepresentation()
          Get the type representation of this Bit object as a string.
 int hashCode()
          Returns the hash code value for this list.
 void randomize(Random random)
          Randomly choose a new valid for the Bit object.
 void readExternal(ObjectInput ois)
          Externalise the current object to the provided ObjectInput.
 void reset()
          Set the Bit object to an initial value of false.
 void set(boolean value)
          Set the value of the Numeric.
 void set(double value)
          Set the value of the Numeric.
 void set(int value)
          Set the value of the Numeric.
 void set(String value)
          Set the value of the Numeric.
 void setBit(boolean value)
          Set the state of of this Bit object.
 void setBit(String value)
          Set the bit value with the provided value.
 void setBounds(Bounds bounds)
          Set the bounds for the current Bit instance.
 void setBounds(double lower, double upper)
          Set the bounds for the current Bit instance.
 void setInt(int value)
          Set the state of the current Bit object.
 void setInt(String value)
          Set the integer value with the provided value.
 void setReal(double value)
          Set the state of the Bit object using value as input.
 void setReal(String value)
          Set the real value with the provided value.
 String toString()
          Return the String representation of this object's value.
 void writeExternal(ObjectOutput oos)
          Externalise the current object to the provided ObjectOutput.
 
Methods inherited from class net.sourceforge.cilib.type.types.Numeric
getBounds
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Bit

public Bit()
Create a Bit object with a random state value.


Bit

public Bit(boolean state)
Copy-constructor. Create a Bit object with the specified state.

Parameters:
state - The state for the Bit object to be in

Bit

public Bit(Bit copy)
Copy constructor. Create a copy of the provided instance.

Parameters:
copy - The instance to copy.
Method Detail

getClone

public Bit getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface Type
Specified by:
getClone in interface Cloneable
Specified by:
getClone in class Numeric
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

equals

public boolean equals(Object other)
Compare the specified object with this type for equality. Returns true if and only if the specified object is also an instance of the same type.

Specified by:
equals in interface Type
Overrides:
equals in class Numeric
Parameters:
other - The object to compare.
Returns:
true if equality exists, false otherwise.
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:
  int hashCode = 7;
  Iterator<E> i = list.iterator();
  while (i.hasNext()) {
      E obj = i.next();
      hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
  }
 
This ensures that type1.equals(type2) implies that type1.hashCode()==type2.hashCode() for any two types, type1 and type2, as required by the general contract of Object.hashCode().

Specified by:
hashCode in interface Type
Overrides:
hashCode in class Numeric
Returns:
the hash code value for this list
See Also:
Object.equals(Object), Type.equals(Object)

set

public void set(String value)
Set the value of the Numeric.

Specified by:
set in class Numeric
Parameters:
value - The String value to be parsed.

set

public void set(boolean value)
Set the value of the Numeric.

Specified by:
set in class Numeric
Parameters:
value - The boolean value representing the value for this Type.

set

public void set(double value)
Set the value of the Numeric.

Specified by:
set in class Numeric
Parameters:
value - The double value representing the value for this Type.

set

public void set(int value)
Set the value of the Numeric.

Specified by:
set in class Numeric
Parameters:
value - The int value representing the value for this Type.

getBit

public boolean getBit()
Return the state of the curent Bit object.

Specified by:
getBit in class Numeric
Returns:
The state of the current Bit object.

setBit

public void setBit(boolean value)
Set the state of of this Bit object.

Specified by:
setBit in class Numeric
Parameters:
value - The state to be set.

setBit

public void setBit(String value)
Set the bit value with the provided value.

Specified by:
setBit in class Numeric
Parameters:
value - The value to set.

getInt

public int getInt()
Get the integer representation of the current Bit object.

Specified by:
getInt in class Numeric
Returns:
The integer value of the current Bit. Returns 1 if the state of the Bit object is true, else returns 0.

setInt

public void setInt(int value)
Set the state of the current Bit object. If the integer value is 0, the state of false is assigned, else a state of true is set.

Specified by:
setInt in class Numeric
Parameters:
value - The value to be used to set the state.

setInt

public void setInt(String value)
Set the integer value with the provided value.

Specified by:
setInt in class Numeric
Parameters:
value - The value to set.

getReal

public double getReal()
Get the state of the Bit returned as a double value.

Specified by:
getReal in class Numeric
Returns:
The state of this Bit object returned as a double.

setReal

public void setReal(double value)
Set the state of the Bit object using value as input. If the value of value is 0.0, the state of the Bit is set to false, else a state value of true is set.

Specified by:
setReal in class Numeric
Parameters:
value - The double value to be used to set the state.

setReal

public void setReal(String value)
Set the real value with the provided value.

Specified by:
setReal in class Numeric
Parameters:
value - The value to set.

compareTo

public int compareTo(Numeric other)

Specified by:
compareTo in interface Comparable<Numeric>
Specified by:
compareTo in class Numeric

randomize

public void randomize(Random random)
Randomly choose a new valid for the Bit object.

Parameters:
random - The Random to use for the randomization.

reset

public void reset()
Set the Bit object to an initial value of false.


toString

public String toString()
Return the String representation of this object's value.

Overrides:
toString in class Object
Returns:
The String represtnation of this object's value.

getRepresentation

public String getRepresentation()
Get the type representation of this Bit object as a string.

Specified by:
getRepresentation in class Numeric
Returns:
The String representation of this Type object.

writeExternal

public void writeExternal(ObjectOutput oos)
                   throws IOException
Externalise the current object to the provided ObjectOutput.

Parameters:
oos - The provided ObjectOutput
Throws:
IOException - if an error occurs.

readExternal

public void readExternal(ObjectInput ois)
                  throws IOException,
                         ClassNotFoundException
Externalise the current object to the provided ObjectInput.

Parameters:
ois - The provided ObjectInput
Throws:
IOException - if an error occurs.
ClassNotFoundException - if the required class is not found.

setBounds

public void setBounds(Bounds bounds)
Set the bounds for the current Bit instance. This method is not a valid operation and as a result throws a UnsupportedOperationException.

Specified by:
setBounds in interface BoundedType
Overrides:
setBounds in class Numeric
Parameters:
bounds - The bounds to set.
Throws:
UnsupportedOperationException - Bit instances cannot have arbitary bounds.

setBounds

public void setBounds(double lower,
                      double upper)
Set the bounds for the current Bit instance. This method is not a valid operation and as a result throws a UnsupportedOperationException.

Specified by:
setBounds in interface BoundedType
Overrides:
setBounds in class Numeric
Parameters:
lower - The lower bound value.
upper - The upperbound value.
Throws:
UnsupportedOperationException - Bit instances cannot have arbitary bounds.


Copyright © 2009 CIRG. All Rights Reserved.