public class IrSequence extends Object implements Cloneable
It consists of a sequence of positive real numbers, each representing a gap (for odd indices) or flash (for even indices). The duration of each flash or gap is the value of the entry in micro seconds."
The length of the IrSequence (as reported by getLength()) is therefore always even. To get the "length in bursts", divide by 2.
The class is (almost) immutable: it can only be constructed and then read from. Also note that there is no modulation frequency herein.
ModulatedIrSequence| Modifier and Type | Field and Description |
|---|---|
static double |
DUMMYGAPDURATION |
static IrSequence |
EMPTY |
| Constructor and Description |
|---|
IrSequence()
Constructs an empty IrSequence,
|
IrSequence(Collection<? extends Number> collection)
Constructs an IrSequence from the parameter data.
|
IrSequence(double[] inData)
Constructs an IrSequence from the parameter data.
|
IrSequence(double[] inData,
Double dummyGapDuration) |
IrSequence(int[] inData)
Constructs an IrSequence from the parameter data.
|
IrSequence(int[] idata,
int offset,
int length)
Constructs an IrSequence from the parameter data.
|
IrSequence(IrSequence src)
Constructs an IrSequence from the parameter data, by cloning.
|
IrSequence(IrSequence src,
int start,
int length) |
IrSequence(String string) |
IrSequence(String[] strings) |
IrSequence(String string,
Double dummyGapDuration)
Constructs an IrSequence from the parameter data.
|
| Modifier and Type | Method and Description |
|---|---|
IrSequence |
addNoise(double max)
Adds a random number in the interval [-max, max) to each flash, and
subtract it from the next gap.
|
IrSequence |
addToFlashes(double amount)
Adds an amount to all flashes.
|
IrSequence |
addToGaps(double amount)
Adds an amount to all flashes, and subtract it from all gaps.
|
IrSequence |
append(double delay)
Appends a delay to the end of the IrSequence.
|
IrSequence |
append(IrSequence tail)
Returns an IrSequence consisting of this sequence, with one
copy of the argument appended.
|
IrSequence |
append(IrSequence tail,
int repetitions)
Returns an IrSequence consisting of this sequence, with repetitions
copies of the first argument appended.
|
boolean |
approximatelyEquals(int beginning,
int compareStart,
int length,
double absoluteTolerance,
double relativeTolerance)
Compares two segments of the current IrSequences for (approximate) equality.
|
boolean |
approximatelyEquals(int beginning,
int compareStart,
int length,
double absoluteTolerance,
double relativeTolerance,
double lastLimit)
Compares two segments of the current IrSequences for (approximate) equality.
|
boolean |
approximatelyEquals(IrSequence irSequence)
Compares two IrSequences for equality.
|
boolean |
approximatelyEquals(IrSequence irSequence,
double absoluteTolerance,
double relativeTolerance)
Compares two IrSequences for (approximate) equality.
|
List<IrSequence> |
chop(double threshold)
Chops a IrSequence in parts.
|
IrSequence |
clone()
Creates and returns a copy of this object.
|
static IrSequence |
concatenate(Collection<IrSequence> sequences)
Concatenates the elements in the argument.
|
static IrSequence |
concatenate(IrSequence... sequences) |
boolean |
containsZeros()
Returns true if and only if the sequence contains durations of zero length.
|
int |
firstBigGap(int start,
double limit) |
IrSequence |
flashExcess(double amount)
Adds an amount to all flashes, and subtract it from all gaps.
|
double |
get(int i)
Returns the i'th value, a duration in micro seconds.
|
Double |
getLastGap()
Return last entry, or
null if the data is empty. |
int |
getLength()
Returns the number of gaps and flashes.
|
double |
getTotalDuration()
Computes the total duration of the IR sequence modeled.
|
double |
getTotalDuration(int begin,
int length)
Computes the total duration of a subsequence of the IR sequence modeled.
|
static void |
initRandom()
Initialize the random number generator of the class (used for addNoise(...)
in a non-predictable way.
|
static void |
initRandom(long seed)
Initialize the random number generator of the class (used for addNoise(...)
in a predictable way, using the seed provided.
|
boolean |
isEmpty() |
static String |
normalize(String in,
Double dummyGap,
boolean useSigns,
String separator) |
boolean |
replaceZeros(double replacement)
Replace all zero durations.
|
static String |
stripDecoratedString(String in)
Removes all "decorations" like signs, commas and semicolons.
|
IrSequence |
subSequence(int start,
int length)
Returns a new IrSequence consisting of the length durations.
|
double[] |
toDoubles()
Returns an array of doubles of durations.
|
static double[] |
toDoublesPreservingSigns(String str) |
static List<Double> |
toInterleavingList(Collection<? extends Number> list) |
int[] |
toInts()
Returns an array of integers of durations.
|
static int[] |
toInts(Iterable<? extends IrSequence> list) |
int[] |
toPulses(double frequency)
For the frequency given as argument, computes an array of durations in number of periods in the given frequency.
|
String |
toString()
Generates a pretty string representing the object.
|
String |
toString(boolean alternatingSigns) |
String |
toString(boolean alternatingSigns,
String separator) |
String |
toString(boolean alternatingSigns,
String separator,
String prefix,
String suffix)
Generates a pretty string representing the object.
|
IrSequence |
truncate(int length)
Returns a new IrSequence consisting of the first length durations.
|
public static final double DUMMYGAPDURATION
public static final IrSequence EMPTY
public IrSequence()
public IrSequence(double[] inData)
throws OddSequenceLengthException
inData - Array of input durations.OddSequenceLengthExceptionpublic IrSequence(double[] inData,
Double dummyGapDuration)
throws OddSequenceLengthException
OddSequenceLengthExceptionpublic IrSequence(int[] inData)
throws OddSequenceLengthException
inData - OddSequenceLengthExceptionpublic IrSequence(Collection<? extends Number> collection) throws OddSequenceLengthException
collection - Collection of numbers representing durations.OddSequenceLengthExceptionpublic IrSequence(String[] strings) throws OddSequenceLengthException
OddSequenceLengthExceptionpublic IrSequence(String string) throws OddSequenceLengthException
OddSequenceLengthExceptionpublic IrSequence(String string, Double dummyGapDuration) throws OddSequenceLengthException
string - String of durations, possibly "decorated".dummyGapDuration - if the string consists of an odd number of
numbers, a gap of this length is silently adding to the sequence.OddSequenceLengthExceptionpublic IrSequence(int[] idata,
int offset,
int length)
throws InvalidArgumentException
idata - Dataoffset - First index to be usedlength - Length of used subset of the idata array.OddSequenceLengthExceptionInvalidArgumentExceptionpublic IrSequence(IrSequence src)
src - Originalpublic IrSequence(IrSequence src, int start, int length) throws InvalidArgumentException
src - start - length - InvalidArgumentExceptionpublic static void initRandom(long seed)
seed - public static void initRandom()
public static IrSequence concatenate(Collection<IrSequence> sequences)
sequences - public static IrSequence concatenate(IrSequence... sequences)
public static List<Double> toInterleavingList(Collection<? extends Number> list)
public static int[] toInts(Iterable<? extends IrSequence> list)
public static double[] toDoublesPreservingSigns(String str)
public static String stripDecoratedString(String in)
in - public static String normalize(String in, Double dummyGap, boolean useSigns, String separator) throws OddSequenceLengthException
OddSequenceLengthExceptionpublic final double get(int i)
i - indexpublic final int[] toInts()
public final double[] toDoubles()
public final int[] toPulses(double frequency)
frequency - Frequency in Hz.public IrSequence append(IrSequence tail, int repetitions)
tail - IrSequence to be appended.repetitions - Number of copies to append.public IrSequence append(IrSequence tail)
tail - IrSequence to be appended.public IrSequence append(double delay) throws InvalidArgumentException
delay - microseconds of silence to be appended to the IrSequence.InvalidArgumentExceptionpublic IrSequence clone()
public IrSequence subSequence(int start, int length) throws InvalidArgumentException
start - Index of first durationlength - Length of new sequenceInvalidArgumentException - if length or start are not even.public IrSequence truncate(int length) throws InvalidArgumentException
length - Length of new sequenceInvalidArgumentException - if length not even.public List<IrSequence> chop(double threshold)
threshold - minimal gap in microseconds to cause a cut.public IrSequence addToFlashes(double amount)
amount - Amount to add in microseconds.public IrSequence addToGaps(double amount)
amount - Amount (positive or negative) to add in microseconds.public IrSequence flashExcess(double amount)
amount - Amount (positive or negative) to add in microseconds.public IrSequence addNoise(double max)
max - max amount to add/subtract, in microseconds.public boolean approximatelyEquals(IrSequence irSequence)
irSequence - to be compared against this. Default tolerances essentially
allows for numerical rounding errors, not much more.public boolean approximatelyEquals(IrSequence irSequence, double absoluteTolerance, double relativeTolerance)
irSequence - to be compared against this.absoluteTolerance - tolerance threshold in microseconds.relativeTolerance - relative threshold, between 0 and 1.public boolean approximatelyEquals(int beginning,
int compareStart,
int length,
double absoluteTolerance,
double relativeTolerance,
double lastLimit)
beginning - start of first subsequencecompareStart - start of second subsequencelength - length to be comparedabsoluteTolerance - tolerance threshold in microseconds.relativeTolerance - relative threshold, between 0 and 1.lastLimit - public boolean approximatelyEquals(int beginning,
int compareStart,
int length,
double absoluteTolerance,
double relativeTolerance)
beginning - start of first subsequencecompareStart - start of second subsequencelength - length to be comparedabsoluteTolerance - tolerance threshold in microseconds.relativeTolerance - relative threshold, between 0 and 1.public final int getLength()
public final Double getLastGap()
null if the data is empty.null if the data is empty.public final boolean isEmpty()
public final boolean containsZeros()
public final boolean replaceZeros(double replacement)
replacement - Duration in micro seconds to replace zero durations with.public final double getTotalDuration()
public double getTotalDuration(int begin,
int length)
begin - start of subsequence.length - length of subsequence.public int firstBigGap(int start,
double limit)
public String toString()
public String toString(boolean alternatingSigns)
public String toString(boolean alternatingSigns, String separator, String prefix, String suffix)
alternatingSigns - if true, generate alternating signs.separator - prefix - suffix - Copyright © 2019. All rights reserved.