Class ImmutableIndividual<T extends Comparable<T>>

java.lang.Object
net.bmahe.genetics4j.core.ImmutableIndividual<T>
All Implemented Interfaces:
Individual<T>

@Generated("org.immutables.processor.ProxyProcessor") public final class ImmutableIndividual<T extends Comparable<T>> extends Object implements Individual<T>
Immutable implementation of Individual.

Use the builder to create immutable instances: ImmutableIndividual.builder(). Use the static factory method to create immutable instances: ImmutableIndividual.of().

  • Field Details

    • genotype

      private final Genotype genotype
    • fitness

      private final T extends Comparable<T> fitness
  • Constructor Details

    • ImmutableIndividual

      private ImmutableIndividual(Genotype genotype, T fitness)
    • ImmutableIndividual

      private ImmutableIndividual(ImmutableIndividual<T> original, Genotype genotype, T fitness)
  • Method Details

    • genotype

      public Genotype genotype()
      Specified by:
      genotype in interface Individual<T extends Comparable<T>>
      Returns:
      The value of the genotype attribute
    • fitness

      public T fitness()
      Specified by:
      fitness in interface Individual<T extends Comparable<T>>
      Returns:
      The value of the fitness attribute
    • withGenotype

      public final ImmutableIndividual<T> withGenotype(Genotype value)
      Copy the current immutable object by setting a value for the genotype attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for genotype
      Returns:
      A modified copy of the this object
    • withFitness

      public final ImmutableIndividual<T> withFitness(T value)
      Copy the current immutable object by setting a value for the fitness attribute. A shallow reference equality check is used to prevent copying of the same value by returning this.
      Parameters:
      value - A new value for fitness
      Returns:
      A modified copy of the this object
    • equals

      public boolean equals(Object another)
      This instance is equal to all instances of ImmutableIndividual that have equal attribute values.
      Overrides:
      equals in class Object
      Returns:
      true if this is equal to another instance
    • equalTo

      private boolean equalTo(int synthetic, ImmutableIndividual<?> another)
    • hashCode

      public int hashCode()
      Computes a hash code from attributes: genotype, fitness.
      Overrides:
      hashCode in class Object
      Returns:
      hashCode value
    • toString

      public String toString()
      Prints the immutable value Individual with attribute values.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the value
    • of

      public static <T extends Comparable<T>> ImmutableIndividual<T> of(Genotype genotype, T fitness)
      Construct a new immutable Individual instance.
      Type Parameters:
      T - generic parameter T
      Parameters:
      genotype - The value for the genotype attribute
      fitness - The value for the fitness attribute
      Returns:
      An immutable Individual instance
    • copyOf

      public static <T extends Comparable<T>> ImmutableIndividual<T> copyOf(Individual<T> instance)
      Creates an immutable copy of a Individual value. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.
      Type Parameters:
      T - generic parameter T
      Parameters:
      instance - The instance to copy
      Returns:
      A copied immutable Individual instance
    • builder

      public static <T extends Comparable<T>> ImmutableIndividual.Builder<T> builder()
      Creates a builder for ImmutableIndividual.
       ImmutableIndividual.&lt;T&gt;builder()
          .genotype(net.bmahe.genetics4j.core.Genotype) // required genotype
          .fitness(T) // required fitness
          .build();
       
      Type Parameters:
      T - generic parameter T
      Returns:
      A new ImmutableIndividual builder