java.lang.Object
org.cicirello.search.representations.SingleInteger
All Implemented Interfaces:
IntegerValued, Copyable<SingleInteger>

public class SingleInteger extends Object implements IntegerValued, Copyable<SingleInteger>
A simple class for representing the input to a univariate function, such that the input is an integer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes this function input to 0.
    Initializes this function input to a specified value.
    Initializes this function input as a copy of another.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates an identical copy of this object.
    boolean
    equals(Object other)
    Indicates whether some other object is "equal to" this one.
    final int
    get()
    Accesses the current value of this function input.
    final int
    get(int i)
    Accesses the current value of this function input.
    int
    Returns a hash code value.
    final int
    Gets the number of parameters.
    void
    set(int x)
    Sets this function input to a specified value.
    final void
    set(int[] values)
    Sets this function input to a specified value.
    final void
    set(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.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • 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

      public SingleInteger(SingleInteger other)
      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: IntegerValued
      Gets the number of parameters.
      Specified by:
      length in interface IntegerValued
      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: IntegerValued
      Accesses the current values of all of the parameters.
      Specified by:
      toArray in interface IntegerValued
      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 the IntegerValued interface. 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 the get() method regardless of value passed for i.
      Specified by:
      get in interface IntegerValued
      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 the IntegerValued interface. 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 the set(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 override set(int).

      Specified by:
      set in interface IntegerValued
      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 the IntegerValued interface. 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 override set(int).

      Specified by:
      set in interface IntegerValued
      Parameters:
      values - The values to set.
    • copy

      public SingleInteger copy()
      Creates an identical copy of this object.
      Specified by:
      copy in interface Copyable<SingleInteger>
      Returns:
      an identical copy of this object
    • equals

      public boolean equals(Object other)
      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.
      Overrides:
      equals in class Object
      Parameters:
      other - The other object to compare.
      Returns:
      true if other is not null, is of the same runtime type as this, and contains the same function input value.
    • hashCode

      public int hashCode()
      Returns a hash code value.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value