Package org.harctoolbox.ircore
Class IrCoreUtils
java.lang.Object
org.harctoolbox.ircore.IrCoreUtils
Some useful static functions and constants.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
static final double
Default absolute tolerance in micro seconds.static final double
Default absolute tolerance for duty cycles.static final double
Default absolute tolerance for frequency comparison.static final double
Default value for least value in a repeat in microseconds.static final double
Default threshold value for lead-out in microseconds.static final double
Default 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 long
static final String
static final String
static final long
static final Charset
static final String
UTF-8 encoding namestatic final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
addExtensionIfNotPresent
(String filename, String extension) static int
approximateGreatestCommonDivider
(int first, int second, double relTolerance) static int
approximateGreatestCommonDivider
(List<Integer> args, double relTolerance) static boolean
approximatelyEquals
(int x, int y, int absoluteTolerance, double relativeTolerance) Tests for approximate equality.static boolean
approximatelyEquals
(Double x, Double y) static boolean
approximatelyEquals
(Double x, Double y, double absoluteTolerance, double relativeTolerance) Tests for approximate equality.static String
static String
capitalize
(String s) static String
chars
(int length, byte value) static String
chars
(int length, char ch) static void
checkEncoding
(String encoding) static File[]
filesInDirMatchingRegExp
(File dir, String regexp) static String
formatIntegerWithLeadingZeros
(long x, int radix, int length) static double
getAbsoluteTolerance
(Double userValue) static double
getFrequencyTolerance
(Double userValue) static InputStreamReader
getInputReader
(String filename, String encoding) static InputStream
getInputStream
(String filename) Opens a Url, an input file, or returns stdin.static double
getMinimumLeadout
(Double userValue) static double
getMinRepeatLastGap
(Double userValue) static PrintStream
getPrintStream
(String filename) Either opens a file (optionally for appending (if beginning with +)) or returns stdout.static PrintStream
getPrintStream
(String filename, String encoding) Either opens a file (optionally for appending (if beginning with +)) or returns stdout.static double
getRelativeTolerance
(Double userValue) static boolean
hasDuplicatedElements
(List<?> list) static int
static double
hz2khz
(double frequency) static String
static double
khz2Hz
(double khz) static double
l1Norm
(double[] sequence) static double
l1Norm
(double[] sequence, int beg, int length) static int
l1Norm
(int[] sequence) static int
l1Norm
(int[] sequence, int beg, int length) static double
static double
static double
static int
lexicalCompare
(int... compare) Support function for lexicographic compareTosstatic long
log2
(long x) Computes ceil(log2(x))static void
static long
maskTo
(long data, int width) static int
static int
static double
microseconds2milliseconds
(double us) static double
microseconds2seconds
(double us) static double
milliseconds2microseconds
(double ms) static double
static int
numberTrue
(Boolean... args) static long
static String
static long
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static long
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static long
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static long
Parses integers of base 2 (prefix "0b" or "%", 8 (leading 0), 10, or 16 (prefix "0x).static long
parseUpper
(String str) static long
parseWithPrefix
(String s, int defaultRadix) static double
percent2real
(double percent) static long
power
(long x, long y) The power function for long arguments.static int
prefixRadix
(String prefix) static String
radixPrefix
(int radix) static double
real2percent
(double x) static int
reverse
(int x, int width) Reverses the bits, living in a width-bit wide world.static long
reverse
(long x, int width) Reverses the bits, living in a width-bit wide world.static BigInteger
reverse
(BigInteger x, int width) static double
seconds2microseconds
(double secs) Convert its argument from seconds to microseconds.static void
setRadixPrefixes
(Map<String, Integer> map) static String
spaces
(int length) Returns a string consisting of length spaces.static String
tabs
(int length) Returns a string consisting of length number of tabs.static String
Makes a C identifier of the argument.static void
trivialFormatter
(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 double
us2Periods
(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:
FileNotFoundException
IOException
-
getInputReader
public static InputStreamReader getInputReader(String filename, String encoding) throws FileNotFoundException, IOException - Throws:
FileNotFoundException
IOException
-
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
-