org.hd.d.pg2k.ai.scorer
Class ScorerParamEnum<E extends java.lang.Enum<E>>

java.lang.Object
  extended by org.hd.d.pg2k.ai.scorer.ScorerParamEnum<E>
All Implemented Interfaces:
ScorerParam, MemoryTools.Internable

public final class ScorerParamEnum<E extends java.lang.Enum<E>>
extends java.lang.Object
implements ScorerParam, MemoryTools.Internable

Immutable (enum) Scorer parameter. The immutablity of this class/instance depends on that of the enum.

Since there will usually be a very small total number of possible distinct instances (no more than the sum of all the sizes of the enums involved, possibly multiplied by a small number of distinct parameter names) we make the class Internable to control instance count and thus save some memory.


Field Summary
 E def
          Default value for this parameter from the enumeration; non-null.
 java.lang.String name
          Parameter name with allowed syntax as for Java variable name; never null.
 E value
          Parameter value from the enumeration; non-null.
 
Constructor Summary
private ScorerParamEnum(E def, java.lang.String name, E value)
          Construct with all components, parameters assumed validated already.
 
Method Summary
static
<E extends java.lang.Enum<E>>
ScorerParamEnum<E>
createScorerParamEnum(E def, java.lang.String name)
          Get instance with the default value, validating the parameters; never null.
static
<E extends java.lang.Enum<E>>
ScorerParamEnum<E>
createScorerParamEnum(E def, java.lang.String name, E value)
          Get instance with default value, name, and value, validating the parameters; never null.
 boolean equals(java.lang.Object obj)
          Equality depends on all elements.
 ScorerParam extract(ScorerParam p)
          Use the supplied parameter if possible (correct name/type/bounds), else return the default; never null.
 java.lang.String getName()
          Get the parameter name; never null or empty.
 int hashCode()
          We include all but the default-value field (assumed highly correlated with the name) in the hash.
 ScorerParam parse(java.lang.String v)
          Parse the String representation of a parameter returning a value of the same type; never null.
 ScorerParam perturb()
          For an enumerated parameter, "perturbing" involves selecting a new value at random.
 boolean similar(ScorerParam p)
          Returns true if the argument is signficantly different in value to this.
 java.lang.String toNameValueString()
          Generate the "name=value" text; never null or empty, though the value part may be empty.
 java.lang.String toString()
          Human-readable representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Parameter name with allowed syntax as for Java variable name; never null.


value

public final E extends java.lang.Enum<E> value
Parameter value from the enumeration; non-null.


def

public final E extends java.lang.Enum<E> def
Default value for this parameter from the enumeration; non-null.

Constructor Detail

ScorerParamEnum

private ScorerParamEnum(E def,
                        java.lang.String name,
                        E value)
Construct with all components, parameters assumed validated already.

Method Detail

createScorerParamEnum

public static <E extends java.lang.Enum<E>> ScorerParamEnum<E> createScorerParamEnum(E def,
                                                                                     java.lang.String name,
                                                                                     E value)
Get instance with default value, name, and value, validating the parameters; never null.


createScorerParamEnum

public static <E extends java.lang.Enum<E>> ScorerParamEnum<E> createScorerParamEnum(E def,
                                                                                     java.lang.String name)
Get instance with the default value, validating the parameters; never null.


getName

public java.lang.String getName()
Get the parameter name; never null or empty.

Specified by:
getName in interface ScorerParam

perturb

public ScorerParam perturb()
For an enumerated parameter, "perturbing" involves selecting a new value at random. Some of the time we return the input value untouched, to stochastically reduce the "jolt" of an average perturbation.

Specified by:
perturb in interface ScorerParam
Returns:
legal value of same type as this, possibly with small perturbation applied

parse

public ScorerParam parse(java.lang.String v)
Parse the String representation of a parameter returning a value of the same type; never null. If the argument is null or unparsable or invalid, then the result has the default value, else an instance with the requested parameter value is returned.

Specified by:
parse in interface ScorerParam
Returns:
legal value of the same type as this, with the parsed input String's value if possible

extract

public ScorerParam extract(ScorerParam p)
Use the supplied parameter if possible (correct name/type/bounds), else return the default; never null. We return this to avoid creating a new instance whenever possible.

Specified by:
extract in interface ScorerParam

toNameValueString

public java.lang.String toNameValueString()
Generate the "name=value" text; never null or empty, though the value part may be empty.

Specified by:
toNameValueString in interface ScorerParam

toString

public java.lang.String toString()
Human-readable representation.

Overrides:
toString in class java.lang.Object

similar

public boolean similar(ScorerParam p)
Description copied from interface: ScorerParam
Returns true if the argument is signficantly different in value to this. The result is false if the argument is null or of a completely different parameter type; no ClassCastException should be thrown (ie behaves like equals() rather than compareTo()).

Specified by:
similar in interface ScorerParam

hashCode

public int hashCode()
We include all but the default-value field (assumed highly correlated with the name) in the hash.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Equality depends on all elements.

Overrides:
equals in class java.lang.Object

DHD Multimedia Gallery V1.53.0

Copyright (c) 1996-2009, Damon Hart-Davis. All rights reserved.