Package beagleutil
Class Samples
- java.lang.Object
-
- beagleutil.Samples
-
public final class Samples extends java.lang.Object
Class
Instances of classSamples
stores a list of samples.Samples
are immutable.
-
-
Constructor Summary
Constructors Constructor Description Samples(int[] idIndices)
Constructs a new instance ofSamples
corresponding to the specified list of sample identifier indices.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Returnstrue
if the specified object is aSamples
object which represents the same ordered list of samples asthis
, and returnsfalse
otherwise.static Samples
fromIds(java.lang.String[] ids)
Constructs and returns aSamples
instance corresponding to the specified list of sample identifiers.int
hashCode()
Returns a hash code value for the object.java.lang.String
id(int index)
Returns the identifier for the sample with the specified index in this list of samples.int
idIndex(int index)
Returns the sample identifier index corresponding to the sample with the specified index in this list of samples.java.lang.String[]
ids()
Returns this list of samples as an array of sample identifiers.int
index(int idIndex)
Returns the index of the sample that corresponds to the specified sample identifier index, or returns-1
if there is no corresponding sample in this list of samples.int
index(java.lang.String id)
Returns the index of the sample that corresponds to the specified sample identifier, or returns-1
if there is no corresponding sample in this list of samples.int
nSamples()
Returns the number of samples in this list.java.lang.String
toString()
Returnsjava.util.Arrays.toString(this.ids())
.
-
-
-
Constructor Detail
-
Samples
public Samples(int[] idIndices)
Constructs a new instance ofSamples
corresponding to the specified list of sample identifier indices.- Parameters:
idIndices
- an array of sample identifier indices- Throws:
java.lang.IllegalArgumentException
- if the specified array has two or more elements that are equaljava.lang.IndexOutOfBoundsException
- if any element of the specified array is negative or greater than or equal tobeagleutil.SampleIds.size()
java.lang.NullPointerException
- ifidIndices == null
-
-
Method Detail
-
fromIds
public static Samples fromIds(java.lang.String[] ids)
Constructs and returns aSamples
instance corresponding to the specified list of sample identifiers.- Parameters:
ids
- an array of sample identifiers.- Returns:
- a
Samples
instance corresponding to the specified list of sample identifiers - Throws:
java.lang.IllegalArgumentException
- if the specified array has two or more elements that are equal as stringsjava.lang.NullPointerException
- ifids == null
-
hashCode
public int hashCode()
Returns a hash code value for the object.
The hash code is defined by the following calculation:
int hash = 1; for (int j, n=this.nSamples(); j<n; ++j) { hash = 31 * hash + this.idIndex(j); }
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code value for the object.
-
equals
public boolean equals(java.lang.Object obj)
Returnstrue
if the specified object is aSamples
object which represents the same ordered list of samples asthis
, and returnsfalse
otherwise.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to be tested for equality withthis
- Returns:
true
if the specified object is aSamples
object which represents the same ordered list of samples asthis
-
idIndex
public int idIndex(int index)
Returns the sample identifier index corresponding to the sample with the specified index in this list of samples.- Parameters:
index
- a sample index- Returns:
- the sample identifier index corresponding to the sample with the specified index in this list of samples
- Throws:
java.lang.IndexOutOfBoundsException
- ifindex < 0 || index >= this.nSamples()
-
index
public int index(int idIndex)
Returns the index of the sample that corresponds to the specified sample identifier index, or returns-1
if there is no corresponding sample in this list of samples.- Parameters:
idIndex
- a sample identifier index- Returns:
- the index of the sample that corresponds to the
specified sample identifier index, or returns
-1
if there is no corresponding sample in this list of samples - Throws:
java.lang.IndexOutOfBoundsException
- ifindex < 0
-
index
public int index(java.lang.String id)
Returns the index of the sample that corresponds to the specified sample identifier, or returns-1
if there is no corresponding sample in this list of samples.- Parameters:
id
- a sample identifier- Returns:
- the index of the sample that corresponds to the
specified sample identifier, or returns
-1
if there is no corresponding sample in this list of samples - Throws:
java.lang.NullPointerException
- ifid == null
-
nSamples
public int nSamples()
Returns the number of samples in this list.- Returns:
- the number of samples in this list
-
id
public java.lang.String id(int index)
Returns the identifier for the sample with the specified index in this list of samples.- Parameters:
index
- a sample index- Returns:
- the identifier for the sample with the specified index in this list of samples
- Throws:
java.lang.IndexOutOfBoundsException
- ifindex < 0 || index >= this.nSamples()
-
ids
public java.lang.String[] ids()
Returns this list of samples as an array of sample identifiers. The returned array has lengththis.nSamples()
, and it satisfiesthis.ids()[j].equals(this.id(j))
for0 <= j && j < this.nSamples()
- Returns:
- this list of samples as an array of sample identifiers
-
toString
public java.lang.String toString()
Returnsjava.util.Arrays.toString(this.ids())
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of
this
-
-