public final class Utils extends Object
Modifier and Type | Field and Description |
---|---|
static ConstantNode |
FALSE_NODE
Represents the boolean value
false . |
static ConstantNode |
TRUE_NODE
Represents the boolean value
true . |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
copyOf(T[] original)
Returns a copy of the specified array.
|
static ConstantNode[] |
createEnumConstants(Class<? extends Enum<?>> e,
Type t)
Returns an array consisting of a
ConstantNode instance for each of the possible values of the specified enum. |
static ConstantNode[] |
createIntegerConstants(int minInclusive,
int maxInclusive)
Returns an array consisting of a
ConstantNode instance for each of the integer values in the specified range. |
static Type[] |
createIntegerTypeArray(int size)
Creates an array of the specified size and assigns the result of
Type.integerType() to each element. |
static <K,V> Map<K,List<V>> |
groupBy(V[] values,
Function<V,K> valueToKey)
Returns a map grouping the specified values according to the specified classification function.
|
static <T extends Node> |
groupByType(T[] nodes)
Returns a map grouping the specified nodes by their
Type . |
static int |
selectSubNodeIndex(Random random,
int nodeCount)
Returns a int value between 0 (inclusive) and the specified
nodeCount value minus 1 (exclusive). |
static int |
selectSubNodeIndex(Random random,
Node tree)
Returns randomly selected index of a node from the specified tree.
|
public static final ConstantNode TRUE_NODE
true
.public static final ConstantNode FALSE_NODE
false
.public static ConstantNode[] createEnumConstants(Class<? extends Enum<?>> e, Type t)
ConstantNode
instance for each of the possible values of the specified enum.e
- the enum that the ConstantNode
instances should wrapt
- the Type
that should be associated with the ConstantNode
instancespublic static ConstantNode[] createIntegerConstants(int minInclusive, int maxInclusive)
ConstantNode
instance for each of the integer values in the specified range.minInclusive
- the minimum value (inclusive) to be represented by a ConstantNode
in the returned arraymaxInclusive
- the minimum value (inclusive) to be represented by a ConstantNode
in the returned arraypublic static Type[] createIntegerTypeArray(int size)
Type.integerType()
to each element.public static <T extends Node> Map<Type,List<T>> groupByType(T[] nodes)
Type
.public static <K,V> Map<K,List<V>> groupBy(V[] values, Function<V,K> valueToKey)
values
- the values to groupvalueToKey
- the classification function used to group valuespublic static int selectSubNodeIndex(Random random, Node tree)
public static int selectSubNodeIndex(Random random, int nodeCount)
nodeCount
value minus 1 (exclusive).public static <T> T[] copyOf(T[] original)
OakGP Genetic Programming Framework