Package pulse.input
Class IndexRange
- java.lang.Object
-
- pulse.input.IndexRange
-
- All Implemented Interfaces:
Serializable
public class IndexRange extends Object implements Serializable
Provides a way to define the indices corresponding to a certain range of data.Essentially, an object of this class contains an ordered pair representing the associated indices. Works in conjunction with the
Rangeclass.- See Also:
Range, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description IndexRange(int start, int end)IndexRange(List<Double> data, Range range)Constructs a new index range fordatabased on the dimensionalrange.IndexRange(IndexRange other)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intclosestLeft(double of, List<Double> in)Searches through the elements contained in the the second argument of this method to find an element belonging toinmost closely resembling the first argument.static intclosestRight(double of, List<Double> in)Searches through the elements contained in the the second argument of this method to find an element belonging toinmost closely resembling the first argument.intgetLowerBound()Gets the integer value representing the index of the lower bound previously set by looking at a certain unspecified data list.intgetUpperBound()Gets the integer value representing the index of the upper bound previously set by looking at a certain unspecified data list.booleanisValid()Checks if this index range is viable.protected voidreset(List<Double> data)Resets the index range by effectively treating thedatalist as bounded by its first and last elements, assuming thatdatais sorted in ascending order.voidset(List<Double> data, Range range)Sets the bounds of this index range using the minimum and maximum values of the segment specified in therangeobject.voidsetLowerBound(List<Double> data, double a)Sets the start index by conducting a primitive binary search usingclosest(...)to find an element indataeither matching or being as close as possible toa(ifais non-negative) or zero.voidsetUpperBound(List<Double> data, double b)Sets the end index by conducting a primitive binary search usingclosest(...)to find an element indataeither matching or being as close as possible tob.StringtoString()
-
-
-
Constructor Detail
-
IndexRange
public IndexRange(IndexRange other)
-
IndexRange
public IndexRange(int start, int end)
-
IndexRange
public IndexRange(List<Double> data, Range range)
Constructs a new index range fordatabased on the dimensionalrange.- Parameters:
data- the list to be analysedrange- the range object used to define the index range- See Also:
set(java.util.List<java.lang.Double>,pulse.input.Range)
-
-
Method Detail
-
reset
protected void reset(List<Double> data)
Resets the index range by effectively treating thedatalist as bounded by its first and last elements, assuming thatdatais sorted in ascending order. Because of this last assumption, the visibility of this method has been set to protected.- Parameters:
data- a list sorted in ascending order
-
setLowerBound
public final void setLowerBound(List<Double> data, double a)
Sets the start index by conducting a primitive binary search usingclosest(...)to find an element indataeither matching or being as close as possible toa(ifais non-negative) or zero.- Parameters:
data- the list to processa- an element representing the lower bound (not necessarily contained indata).- See Also:
closestLeft(double,java.util.List<java.lang.Double>),closestRight(double,java.util.List<java.lang.Double>)
-
setUpperBound
public final void setUpperBound(List<Double> data, double b)
Sets the end index by conducting a primitive binary search usingclosest(...)to find an element indataeither matching or being as close as possible tob. For the above operation, the list is searched through from its last to first element (i.e., in reverse order).- Parameters:
data- the list to processb- an element representing the upper bound (not necessarily contained indata).- See Also:
closestLeft(double,java.util.List<java.lang.Double>),closestRight(double,java.util.List<java.lang.Double>)
-
set
public final void set(List<Double> data, Range range)
Sets the bounds of this index range using the minimum and maximum values of the segment specified in therangeobject. If the minimum bound is negative, it will be ignored and replaced by 0.0.- Parameters:
data- the data list to be processedrange- a range with minimum and maximum values- See Also:
setLowerBound(java.util.List<java.lang.Double>,double),setUpperBound(java.util.List<java.lang.Double>,double)
-
getLowerBound
public final int getLowerBound()
Gets the integer value representing the index of the lower bound previously set by looking at a certain unspecified data list.- Returns:
- the start index
-
getUpperBound
public final int getUpperBound()
Gets the integer value representing the index of the upper bound previously set by looking at a certain unspecified data list.- Returns:
- the end index
-
isValid
public boolean isValid()
Checks if this index range is viable.- Returns:
trueif the upper bound is positive and greater than the lower bound,falseotherwise.
-
closestLeft
public static int closestLeft(double of, List<Double> in)Searches through the elements contained in the the second argument of this method to find an element belonging toinmost closely resembling the first argument. The search is completed onceoflies between any two adjacent elements ofin. The result is then the index of the preceding element.- Parameters:
of- an element which will be compared againstin- a list of data presumably containing an element similar toof- Returns:
any integer greater than 0 and lesser than
in.sizethat matches the above criterion. Ifofis greater than the last element ofin, this will return the latter. Otherwise, if no element matching the criterion is found, returns 0.
-
closestRight
public static int closestRight(double of, List<Double> in)Searches through the elements contained in the the second argument of this method to find an element belonging toinmost closely resembling the first argument. The search utilises a reverse order, i.e. it starts from the last element and goes to the first. The search is completed onceoflies between any two adjacent elements ofin. The result is then the index of the preceding element.- Parameters:
of- an element which will be compared againstin- a list of data presumably containing an element similar toof- Returns:
any integer greater than 0 and lesser than
in.sizethat matches the above criterion. Ifofis greater than the last element ofin, this will return the latter. Otherwise, if no element matching the criterion is found, returns 0.
-
-