
public final class Util extends Object
de.lmu.ifi.dbs.elki.utilities| Modifier and Type | Class and Description |
|---|---|
static class |
Util.MaskedArrayList<T>
This class is a virtual collection based on masking an array list using a
bit mask.
|
| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
static <O> void |
addToList(List<O> list,
O[] array)
Adds the entries of the specified array to the end of the given list.
|
static int |
arrayFind(String[] arr,
Object ref)
Search an (unsorted) array linearly for an object.
|
static List<Integer> |
convertBitSetToListInt(BitSet b,
int off)
Convert a bit set to a list of integers, representing bits that are set
|
static double[] |
convertToDoubles(float[] values)
Converts the specified array of doubles to an array of floats.
|
static double[] |
convertToDoubles(List<Double> values)
Converts the specified list of Double objects to an array of doubles.
|
static float[] |
convertToFloat(double[] values)
Converts the specified array of doubles to an array of floats.
|
static List<Float> |
convertToFloat(List<Double> values)
Converts the specified list of double objects to a list of float objects.
|
static double[] |
copy(double[] array)
Returns a new double array containing the same objects as are contained in
the given array.
|
static String[] |
copy(String[] array)
Returns a new String array containing the same objects as are contained in
the given array.
|
static String |
getFilePrefix(String fileName)
Returns the prefix of the specified fileName (i.e. the name of the file
without extension).
|
static int |
getIndexOfMaximum(double[] values)
Returns the index of the maximum of the given values.
|
static int |
indexOfNthSetBit(BitSet bitset,
int nthSetBit)
Returns the index of the nth set bit in the given BitSet.
|
static BitSet |
int2Bit(int n)
Converts the specified positive integer value into a bit representation,
where bit 0 denotes 20, bit 1 denotes 21 etc.
|
static <O> void |
intersection(Set<O> s1,
Set<O> s2,
Set<O> result)
Provides the intersection of the two specified sets in the given result
set.
|
static String[] |
joinArray(String[] array1,
String[] array2)
Joins the specified arrays.
|
static int |
mixHashCodes(int... hash)
Mix multiple hashcodes into one.
|
static BitSet |
parseBitSet(char[] s)
Returns a new
BitSet initialized to the values represented by
the specified char array only containing '0' and '1' values. |
static BitSet |
parseBitSet(String s)
Returns a new
BitSet initialized to the values represented by
the specified String only containing 0 and 1 values. |
static double[] |
parseDoubles(String s)
Returns a new
Double array initialized to the values
represented by the specified String and separated by comma, as
performed by the valueOf method of class Double. |
static float[] |
parseFloats(String s)
Returns a new
Float array initialized to the values
represented by the specified String and separated by comma, as
performed by the valueOf method of class Float. |
static String |
parseSelectedBits(BitSet b,
String sep)
Returns a string that represents the selected bits of the specified
BitSet, while the first bit starts with 1. |
static <O> void |
print(List<O> list,
String separator,
PrintStream out)
Prints the given list to the specified PrintStream.
|
static DoubleVector |
project(DoubleVector v,
BitSet selectedAttributes)
Provides a new DoubleVector as a projection on the specified attributes.
|
static SparseFloatVector |
project(SparseFloatVector v,
BitSet selectedAttributes)
Provides a new SparseFloatVector as a projection on the specified
attributes.
|
static BitSet |
randomBitSet(int cardinality,
int capacity,
Random random)
Creates a new BitSet of fixed cardinality with randomly set bits.
|
static double[] |
unbox(Double[] array)
Returns the unboxed double array of the given Object Double array.
|
static double[] |
unbox(Number[] array)
Returns the unboxed double array of the given Object Number array.
|
static float[] |
unboxToFloat(Number[] array)
Returns the unboxed float array of the given Object Number array.
|
public static String getFilePrefix(String fileName)
fileName - the name of the filepublic static String[] copy(String[] array)
array - an array to copypublic static double[] copy(double[] array)
array - an array to copypublic static double[] unbox(Double[] array)
array - the array to be unboxedpublic static double[] unbox(Number[] array)
array - the array to be unboxedpublic static float[] unboxToFloat(Number[] array)
array - the array to be unboxedpublic static double[] parseDoubles(String s)
Double array initialized to the values
represented by the specified String and separated by comma, as
performed by the valueOf method of class Double.s - the string to be parsed.Double array represented by spublic static float[] parseFloats(String s)
Float array initialized to the values
represented by the specified String and separated by comma, as
performed by the valueOf method of class Float.s - the string to be parsed.Float array represented by spublic static List<Float> convertToFloat(List<Double> values)
values - the list of double objects to be convertedpublic static float[] convertToFloat(double[] values)
values - the array of doubles to be convertedpublic static double[] convertToDoubles(float[] values)
values - the array of doubles to be convertedpublic static double[] convertToDoubles(List<Double> values)
values - the list of Double objects to be convertedpublic static <O> void print(List<O> list, String separator, PrintStream out)
O - object classlist - the list to be printedseparator - the separator to separate entries of the listout - the target PrintStreampublic static int getIndexOfMaximum(double[] values)
throws ArrayIndexOutOfBoundsException
values - the values to find the index of the maximumArrayIndexOutOfBoundsException - if values.length==0public static BitSet parseBitSet(String s)
BitSet initialized to the values represented by
the specified String only containing 0 and 1 values.s - the string to be parsed.BitSet represented by spublic static BitSet parseBitSet(char[] s)
BitSet initialized to the values represented by
the specified char array only containing '0' and '1' values.s - the char array to be parsed.BitSet represented by spublic static String parseSelectedBits(BitSet b, String sep)
BitSet, while the first bit starts with 1. The selected bits
are separated by the specified separator sep.
If sep is ",", the result is suitable as a parameter
for an IntListParameter.b - the bit set to be parsedsep - the separatorBitSetpublic static List<Integer> convertBitSetToListInt(BitSet b, int off)
b - Bitsetoff - Offset, set to 0 to start counting at 0, 1 to start counting at
1.public static BitSet randomBitSet(int cardinality, int capacity, Random random)
cardinality - the cardinality of the BitSet to createcapacity - the capacity of the BitSet to create - the randomly
generated indices of the bits set to true will be uniformly
distributed between 0 (inclusive) and capacity (exclusive)random - a Random Object to create the sequence of indices set to true
- the same number occurring twice or more is ignored but the already
selected bit remains truepublic static DoubleVector project(DoubleVector v, BitSet selectedAttributes)
null, the same
ID is set in the returned new DoubleVector. Nevertheless, the returned
DoubleVector is not backed by the given DoubleVector, i.e., any changes
affecting v after calling this method will not affect the
newly returned DoubleVector.v - a DoubleVector to projectselectedAttributes - the attributes selected for projectionIllegalArgumentException - if the given selected attributes specify
an attribute as selected which is out of range for the given
DoubleVector.DoubleVector.doubleValue(int)public static SparseFloatVector project(SparseFloatVector v, BitSet selectedAttributes)
null, the
same ID is set in the returned new SparseFloatVector. Nevertheless, the
returned SparseFloatVector is not backed by the given SparseFloatVector,
i.e., any changes affecting v after calling this method will
not affect the newly returned SparseFloatVector.v - a SparseFloatVector to projectselectedAttributes - the attributes selected for projectionIllegalArgumentException - if the given selected attributes specify
an attribute as selected which is out of range for the given
SparseFloatVector.public static int indexOfNthSetBit(BitSet bitset, int nthSetBit) throws IllegalArgumentException
nthSetBit, following condition is assumed:
1 ≤ nthSetBit ≤ bitset.cardinality(). Otherwise, i.e.,
if the Bitset contains less than nthSetBit set bits or
nthSetBit is not a positive number, the method throws an
IllegalArgumentException.
The worstcase runtime complexity of this method is in O(
bitset.cardinality()).bitset - the BitSet to derive the index of the nth set bit
innthSetBit - which set bit to derive the index ofIllegalArgumentException - if the Bitset contains less than
nthSetBit set bits or nthSetBit is not a
positive numberpublic static <O> void intersection(Set<O> s1, Set<O> s2, Set<O> result)
O - object classs1 - the first sets2 - the second setresult - the result setpublic static BitSet int2Bit(int n)
n - the positive integer value to be convertedpublic static String[] joinArray(String[] array1, String[] array2)
array1 - the first arrayarray2 - the second arrayarray1 and the
array2.public static <O> void addToList(List<O> list, O[] array)
O - object classlist - the listarray - the array containing the objects to be added to the listpublic static int arrayFind(String[] arr, Object ref)
arr - Array to searchref - Object to search forpublic static final int mixHashCodes(int... hash)
hash - Hashcodes to mix