java.lang.Object
org.cicirello.search.representations.SingleInteger
- All Implemented Interfaces:
IntegerValued,Copyable<SingleInteger>
A simple class for representing the input to a univariate function, such that the input is an
integer.
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes this function input to 0.SingleInteger(int x) Initializes this function input to a specified value.SingleInteger(SingleInteger other) Initializes this function input as a copy of another. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates an identical copy of this object.booleanIndicates whether some other object is "equal to" this one.final intget()Accesses the current value of this function input.final intget(int i) Accesses the current value of this function input.inthashCode()Returns a hash code value.final intlength()Gets the number of parameters.voidset(int x) Sets this function input to a specified value.final voidset(int[] values) Sets this function input to a specified value.final voidset(int i, int x) Sets this function input to a specified value.final int[]toArray(int[] values) Accesses the current values of all of the parameters.
-
Constructor Details
-
SingleInteger
public SingleInteger()Initializes this function input to 0. -
SingleInteger
public SingleInteger(int x) Initializes this function input to a specified value.- Parameters:
x- The initial value for this function input.
-
SingleInteger
Initializes this function input as a copy of another.- Parameters:
other- The other function input to copy.
-
-
Method Details
-
length
public final int length()Description copied from interface:IntegerValuedGets the number of parameters.- Specified by:
lengthin interfaceIntegerValued- Returns:
- The number of parameters for this function.
-
get
public final int get()Accesses the current value of this function input.- Returns:
- The current value of this function input.
-
toArray
public final int[] toArray(int[] values) Description copied from interface:IntegerValuedAccesses the current values of all of the parameters.- Specified by:
toArrayin interfaceIntegerValued- Parameters:
values- An array to hold the result. If values is null or if values.length is not equal to this.length(), then a new array is constructed for the result.- Returns:
- An array containing the current values of all of the parameters.
-
get
public final int get(int i) Accesses the current value of this function input. This method originates with theIntegerValuedinterface. Since this is a univariate function, there is only 1 input variable by definition. Rather than throw an exception for values of i other than 0, this method ignores the i parameter and is equivalent to theget()method regardless of value passed for i.- Specified by:
getin interfaceIntegerValued- Parameters:
i- The input to get (ignored by this implementation since this is an input for a univariate function).- Returns:
- The current value of this function input.
-
set
public void set(int x) Sets this function input to a specified value.- Parameters:
x- The new value for this function input.
-
set
public final void set(int i, int x) Sets this function input to a specified value. This method originates with theIntegerValuedinterface. Since this is a univariate function, there is only 1 input variable by definition. Rather than throw an exception for values of i other than 0, this method ignores the i parameter and is equivalent to theset(int)method regardless of value passed for i.This method delegates work to the
set(int)method, so the behavior of this method will be consistent with any subclasses that overrideset(int).- Specified by:
setin interfaceIntegerValued- Parameters:
i- The input variable to set (ignored by this implementation since this is an input for a univariate function).x- The new value for this function input.
-
set
public final void set(int[] values) Sets this function input to a specified value. This method originates with theIntegerValuedinterface. Since this is a univariate function, there is only 1 input variable by definition. Rather than throw an exception for values.length greater than 1, this method simply uses values[0] and ignores any extra values.This method delegates work to the
set(int)method, so the behavior of this method will be consistent with any subclasses that overrideset(int).- Specified by:
setin interfaceIntegerValued- Parameters:
values- The values to set.
-
copy
Creates an identical copy of this object.- Specified by:
copyin interfaceCopyable<SingleInteger>- Returns:
- an identical copy of this object
-
equals
Indicates whether some other object is "equal to" this one. To be equal, the other object must be of the same runtime type and contain the same value of the function input. -
hashCode
public int hashCode()Returns a hash code value.
-