Package org.harctoolbox.ircore
Class IrCoreUtils
java.lang.Object
org.harctoolbox.ircore.IrCoreUtils
Some useful static functions and constants.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final doubleDefault absolute tolerance in micro seconds.static final doubleDefault absolute tolerance for duty cycles.static final doubleDefault absolute tolerance for frequency comparison.static final doubleDefault value for least value in a repeat in microseconds.static final doubleDefault threshold value for lead-out in microseconds.static final doubleDefault relative tolerance as a number between 0 and 1.static final Charset"Dumb" Charsetstatic final String"Dumb" Charset namestatic final Charset"Extended Latin 1" Charsetstatic final String"Extended Latin 1" Encodingstatic final longstatic final Stringstatic final Stringstatic final longstatic final Charsetstatic final StringUTF-8 encoding namestatic final String -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddExtensionIfNotPresent(String filename, String extension) static intapproximateGreatestCommonDivider(int first, int second, double relTolerance) static intapproximateGreatestCommonDivider(List<Integer> args, double relTolerance) static booleanapproximatelyEquals(int x, int y, int absoluteTolerance, double relativeTolerance) Tests for approximate equality.static booleanapproximatelyEquals(Double x, Double y) static booleanapproximatelyEquals(Double x, Double y, double absoluteTolerance, double relativeTolerance) Tests for approximate equality.static Stringstatic Stringcapitalize(String s) static Stringchars(int length, byte value) static Stringchars(int length, char ch) static voidcheckEncoding(String encoding) static File[]filesInDirMatchingRegExp(File dir, String regexp) static StringformatIntegerWithLeadingZeros(long x, int radix, int length) static doublegetAbsoluteTolerance(Double userValue) static doublegetFrequencyTolerance(Double userValue) static InputStreamReadergetInputReader(String filename, String encoding) static InputStreamgetInputStream(String filename) Opens a Url, an input file, or returns stdin.static doublegetMinimumLeadout(Double userValue) static doublegetMinRepeatLastGap(Double userValue) static PrintStreamgetPrintStream(String filename) Either opens a file (optionally for appending (if beginning with +)) or returns stdout.static PrintStreamgetPrintStream(String filename, String encoding) Either opens a file (optionally for appending (if beginning with +)) or returns stdout.static doublegetRelativeTolerance(Double userValue) static booleanhasDuplicatedElements(List<?> list) static intstatic doublehz2khz(double frequency) static Stringstatic doublekhz2Hz(double khz) static doublel1Norm(double[] sequence) static doublel1Norm(double[] sequence, int beg, int length) static intl1Norm(int[] sequence) static intl1Norm(int[] sequence, int beg, int length) static doublestatic doublestatic doublestatic intlexicalCompare(int... compare) Support function for lexicographic compareTosstatic longlog2(long x) Computes ceil(log2(x))static voidstatic longmaskTo(long data, int width) static intstatic intstatic doublemicroseconds2milliseconds(double us) static doublemicroseconds2seconds(double us) static doublemilliseconds2microseconds(double ms) static doublestatic intnumberTrue(Boolean... args) static longstatic Stringstatic longParses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static longParses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static longParses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static longParses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static longparseUpper(String str) static longparseWithPrefix(String s, int defaultRadix) static doublepercent2real(double percent) static longpower(long x, long y) The power function for long arguments.static intprefixRadix(String prefix) static StringradixPrefix(int radix) static doublereal2percent(double x) static intreverse(int x, int width) Reverses the bits, living in a width-bit wide world.static longreverse(long x, int width) Reverses the bits, living in a width-bit wide world.static BigIntegerreverse(BigInteger x, int width) static doubleseconds2microseconds(double secs) Convert its argument from seconds to microseconds.static voidsetRadixPrefixes(Map<String, Integer> map) static Stringspaces(int length) Returns a string consisting of length spaces.static Stringtabs(int length) Returns a string consisting of length number of tabs.static StringMakes a C identifier of the argument.static voidtrivialFormatter(PrintStream out, String string, int lineLength) Prints the String in the second argument nicely on the PrintStream in the first argument, nicely chopping after lineLength positions.static doubleus2Periods(double us, double frequency)
-
Field Details
-
INVALID
public static final long INVALID- See Also:
-
ALL
public static final long ALL- See Also:
-
SOME
public static final long SOME- See Also:
-
LINE_SEPARATOR
-
DEFAULT_ABSOLUTE_TOLERANCE
public static final double DEFAULT_ABSOLUTE_TOLERANCEDefault absolute tolerance in micro seconds.- See Also:
-
DEFAULT_RELATIVE_TOLERANCE
public static final double DEFAULT_RELATIVE_TOLERANCEDefault relative tolerance as a number between 0 and 1.- See Also:
-
DEFAULT_FREQUENCY_TOLERANCE
public static final double DEFAULT_FREQUENCY_TOLERANCEDefault absolute tolerance for frequency comparison.- See Also:
-
DEFAULT_DUTYCYCLE_TOLERANCE
public static final double DEFAULT_DUTYCYCLE_TOLERANCEDefault absolute tolerance for duty cycles.- See Also:
-
DEFAULT_MINIMUM_LEADOUT
public static final double DEFAULT_MINIMUM_LEADOUTDefault threshold value for lead-out in microseconds.- See Also:
-
DEFAULT_MIN_REPEAT_LAST_GAP
public static final double DEFAULT_MIN_REPEAT_LAST_GAPDefault value for least value in a repeat in microseconds.- See Also:
-
DUMB_CHARSET_NAME
"Dumb" Charset name- See Also:
-
DUMB_CHARSET
"Dumb" Charset -
EXTENDED_LATIN1_NAME
"Extended Latin 1" Encoding- See Also:
-
EXTENDED_LATIN1
"Extended Latin 1" Charset -
UTF8_NAME
UTF-8 encoding name- See Also:
-
UTF8
-
WHITESPACE
- See Also:
-
LINEFEED
- See Also:
-
-
Method Details
-
setRadixPrefixes
-
getRelativeTolerance
-
getAbsoluteTolerance
-
getFrequencyTolerance
-
getMinimumLeadout
-
getMinRepeatLastGap
-
seconds2microseconds
public static double seconds2microseconds(double secs) Convert its argument from seconds to microseconds.- Parameters:
secs- seconds- Returns:
- Argument converted to microseconds.
-
milliseconds2microseconds
public static double milliseconds2microseconds(double ms) -
microseconds2milliseconds
public static double microseconds2milliseconds(double us) -
microseconds2seconds
public static double microseconds2seconds(double us) -
khz2Hz
public static double khz2Hz(double khz) -
hz2khz
public static double hz2khz(double frequency) -
us2Periods
public static double us2Periods(double us, double frequency) -
percent2real
public static double percent2real(double percent) -
real2percent
public static double real2percent(double x) -
l1Norm
-
l1Norm
-
l1Norm
public static double l1Norm(double[] sequence) -
l1Norm
public static double l1Norm(double[] sequence, int beg, int length) -
l1Norm
-
l1Norm
public static int l1Norm(int[] sequence, int beg, int length) -
l1Norm
public static int l1Norm(int[] sequence) -
chars
-
chars
-
spaces
Returns a string consisting of length spaces.- Parameters:
length-- Returns:
- String of the requested length.
-
tabs
Returns a string consisting of length number of tabs.- Parameters:
length-- Returns:
-
ones
-
toCName
Makes a C identifier of the argument.- Parameters:
name-- Returns:
- its argument made C friendly
-
numberTrue
-
getPrintStream
public static PrintStream getPrintStream(String filename, String encoding) throws FileNotFoundException, UnsupportedEncodingException Either opens a file (optionally for appending (if beginning with +)) or returns stdout.- Parameters:
filename- Either - for stdout, or a file name, or null. If starting with +, the file is opened in append mode, after removing the +-character.encoding-- Returns:
- Open PrintStream
- Throws:
FileNotFoundException- if FileOutputStream doesUnsupportedEncodingException
-
getPrintStream
Either opens a file (optionally for appending (if beginning with +)) or returns stdout.- Parameters:
filename- Either - for stdout, or a file name, or null. If starting with +, the file is opened in append mode, after removing the +-character.- Returns:
- Open PrintStream
- Throws:
FileNotFoundException- if FileOutputStream does
-
getInputStream
Opens a Url, an input file, or returns stdin.- Parameters:
filename-- Returns:
- Open InputStream
- Throws:
FileNotFoundExceptionIOException
-
getInputReader
public static InputStreamReader getInputReader(String filename, String encoding) throws FileNotFoundException, IOException - Throws:
FileNotFoundExceptionIOException
-
trivialFormatter
Prints the String in the second argument nicely on the PrintStream in the first argument, nicely chopping after lineLength positions. Respects linefeeds, tabs, etc.- Parameters:
out- PrintStream to print on.string- String to printlineLength- Break after this position.
-
formatIntegerWithLeadingZeros
-
padString
-
power
public static long power(long x, long y) The power function for long arguments.- Parameters:
x- longy- long, non-negative- Returns:
- x raised to the y'th power
- Throws:
ArithmeticException
-
log2
public static long log2(long x) Computes ceil(log2(x))- Parameters:
x-- Returns:
-
radixPrefix
-
prefixRadix
-
parseLong
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x). If argument special is true, allows intervals 123..456 or 123:456 by ignoring upper part. and translates `*' to the constant "all" = (-2) and `#' to "some" (= -3). If no prefix, use the default given as second argument.- Parameters:
str- String to be parsedspecial- If the special stuff should be interpreted ('*', '+', intervals).defaultRadix-- Returns:
- long integer.
-
parseWithPrefix
-
parseLong
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x). If argument special is true, allows intervals 123..456 or 123:456 by ignoring upper part. and translates `*' to the constant "all" = (-2) and `#' to "some" (= -3).- Parameters:
str- String to be parsedspecial- If the special stuff should be interpreted ('*', '+', intervals).- Returns:
- long integer.
-
parseLong
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x). If no prefix, use the default given as second argument.- Parameters:
str- String to be parseddefaultRadix- fallback radix- Returns:
- long integer.
-
parseLong
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).- Parameters:
str- String to be parsed- Returns:
- long integer.
-
parseUpper
-
reverse
public static long reverse(long x, int width) Reverses the bits, living in a width-bit wide world.- Parameters:
x- datawidth- width in bits- Returns:
- bitreversed
-
reverse
public static int reverse(int x, int width) Reverses the bits, living in a width-bit wide world.- Parameters:
x- datawidth- width in bits- Returns:
- bitreversed
-
reverse
-
approximatelyEquals
public static boolean approximatelyEquals(Double x, Double y, double absoluteTolerance, double relativeTolerance) Tests for approximate equality.- Parameters:
x- first argumenty- second argumentabsoluteTolerance-relativeTolerance-- Returns:
- true if either absolute or relative requirement is satisfied.
-
approximatelyEquals
-
approximatelyEquals
public static boolean approximatelyEquals(int x, int y, int absoluteTolerance, double relativeTolerance) Tests for approximate equality.- Parameters:
x- first argumenty- second argumentabsoluteTolerance-relativeTolerance-- Returns:
- true if either absolute or relative requirement is satisfied.
-
maskTo
public static long maskTo(long data, int width) -
capitalize
-
javaifyString
-
hasDuplicatedElements
-
approximateGreatestCommonDivider
-
approximateGreatestCommonDivider
public static int approximateGreatestCommonDivider(int first, int second, double relTolerance) -
maxLength
-
maxLength
-
main
-
filesInDirMatchingRegExp
-
minDiff
-
basename
-
addExtensionIfNotPresent
-
hashForDouble
-
lexicalCompare
public static int lexicalCompare(int... compare) Support function for lexicographic compareTos- Parameters:
compare-- Returns:
-
checkEncoding
- Throws:
UnsupportedEncodingException
-