Class IrCoreUtils

java.lang.Object
org.harctoolbox.ircore.IrCoreUtils

public final class IrCoreUtils extends Object
Some useful static functions and constants.
  • 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

      public static final String LINE_SEPARATOR
    • DEFAULT_ABSOLUTE_TOLERANCE

      public static final double DEFAULT_ABSOLUTE_TOLERANCE
      Default absolute tolerance in micro seconds.
      See Also:
    • DEFAULT_RELATIVE_TOLERANCE

      public static final double DEFAULT_RELATIVE_TOLERANCE
      Default relative tolerance as a number between 0 and 1.
      See Also:
    • DEFAULT_FREQUENCY_TOLERANCE

      public static final double DEFAULT_FREQUENCY_TOLERANCE
      Default absolute tolerance for frequency comparison.
      See Also:
    • DEFAULT_DUTYCYCLE_TOLERANCE

      public static final double DEFAULT_DUTYCYCLE_TOLERANCE
      Default absolute tolerance for duty cycles.
      See Also:
    • DEFAULT_MINIMUM_LEADOUT

      public static final double DEFAULT_MINIMUM_LEADOUT
      Default threshold value for lead-out in microseconds.
      See Also:
    • DEFAULT_MIN_REPEAT_LAST_GAP

      public static final double DEFAULT_MIN_REPEAT_LAST_GAP
      Default value for least value in a repeat in microseconds.
      See Also:
    • DUMB_CHARSET_NAME

      public static final String DUMB_CHARSET_NAME
      "Dumb" Charset name
      See Also:
    • DUMB_CHARSET

      public static final Charset DUMB_CHARSET
      "Dumb" Charset
    • EXTENDED_LATIN1_NAME

      public static final String EXTENDED_LATIN1_NAME
      "Extended Latin 1" Encoding
      See Also:
    • EXTENDED_LATIN1

      public static final Charset EXTENDED_LATIN1
      "Extended Latin 1" Charset
    • UTF8_NAME

      public static final String UTF8_NAME
      UTF-8 encoding name
      See Also:
    • UTF8

      public static final Charset UTF8
    • WHITESPACE

      public static final String WHITESPACE
      See Also:
    • LINEFEED

      public static final String LINEFEED
      See Also:
  • Method Details

    • setRadixPrefixes

      public static void setRadixPrefixes(Map<String,Integer> map)
    • getRelativeTolerance

      public static double getRelativeTolerance(Double userValue)
    • getAbsoluteTolerance

      public static double getAbsoluteTolerance(Double userValue)
    • getFrequencyTolerance

      public static double getFrequencyTolerance(Double userValue)
    • getMinimumLeadout

      public static double getMinimumLeadout(Double userValue)
    • getMinRepeatLastGap

      public static double getMinRepeatLastGap(Double userValue)
    • 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

      public static double l1Norm(Double[] sequence)
    • l1Norm

      public static double l1Norm(Iterable<Double> sequence)
    • l1Norm

      public static double l1Norm(double[] sequence)
    • l1Norm

      public static double l1Norm(double[] sequence, int beg, int length)
    • l1Norm

      public static double l1Norm(List<Double> list, int beg)
    • l1Norm

      public static int l1Norm(int[] sequence, int beg, int length)
    • l1Norm

      public static int l1Norm(int[] sequence)
    • chars

      public static String chars(int length, char ch)
    • chars

      public static String chars(int length, byte value)
    • spaces

      public static String spaces(int length)
      Returns a string consisting of length spaces.
      Parameters:
      length -
      Returns:
      String of the requested length.
    • tabs

      public static String tabs(int length)
      Returns a string consisting of length number of tabs.
      Parameters:
      length -
      Returns:
    • ones

      public static long ones(Number numOnes)
    • toCName

      public static String toCName(String name)
      Makes a C identifier of the argument.
      Parameters:
      name -
      Returns:
      its argument made C friendly
    • numberTrue

      public static int numberTrue(Boolean... args)
    • 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 does
      UnsupportedEncodingException
    • getPrintStream

      public static PrintStream getPrintStream(String filename) throws FileNotFoundException
      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

      public static InputStream getInputStream(String filename) throws FileNotFoundException, IOException
      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

      public 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. Respects linefeeds, tabs, etc.
      Parameters:
      out - PrintStream to print on.
      string - String to print
      lineLength - Break after this position.
    • formatIntegerWithLeadingZeros

      public static String formatIntegerWithLeadingZeros(long x, int radix, int length)
    • padString

      public static String padString(String s, int length)
    • power

      public static long power(long x, long y)
      The power function for long arguments.
      Parameters:
      x - long
      y - 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

      public static String radixPrefix(int radix)
    • prefixRadix

      public static int prefixRadix(String prefix)
    • parseLong

      public static long parseLong(String str, boolean special, int defaultRadix)
      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 parsed
      special - If the special stuff should be interpreted ('*', '+', intervals).
      defaultRadix -
      Returns:
      long integer.
    • parseWithPrefix

      public static long parseWithPrefix(String s, int defaultRadix)
    • parseLong

      public static long parseLong(String str, boolean special)
      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 parsed
      special - If the special stuff should be interpreted ('*', '+', intervals).
      Returns:
      long integer.
    • parseLong

      public static long parseLong(String str, int defaultRadix)
      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 parsed
      defaultRadix - fallback radix
      Returns:
      long integer.
    • parseLong

      public static long parseLong(String str)
      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

      public static long parseUpper(String str)
    • reverse

      public static long reverse(long x, int width)
      Reverses the bits, living in a width-bit wide world.
      Parameters:
      x - data
      width - 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 - data
      width - width in bits
      Returns:
      bitreversed
    • reverse

      public static BigInteger reverse(BigInteger x, int width)
    • approximatelyEquals

      public static boolean approximatelyEquals(Double x, Double y, double absoluteTolerance, double relativeTolerance)
      Tests for approximate equality.
      Parameters:
      x - first argument
      y - second argument
      absoluteTolerance -
      relativeTolerance -
      Returns:
      true if either absolute or relative requirement is satisfied.
    • approximatelyEquals

      public static boolean approximatelyEquals(Double x, Double y)
    • approximatelyEquals

      public static boolean approximatelyEquals(int x, int y, int absoluteTolerance, double relativeTolerance)
      Tests for approximate equality.
      Parameters:
      x - first argument
      y - second argument
      absoluteTolerance -
      relativeTolerance -
      Returns:
      true if either absolute or relative requirement is satisfied.
    • maskTo

      public static long maskTo(long data, int width)
    • capitalize

      public static String capitalize(String s)
    • javaifyString

      public static String javaifyString(String s)
    • hasDuplicatedElements

      public static boolean hasDuplicatedElements(List<?> list)
    • approximateGreatestCommonDivider

      public static int approximateGreatestCommonDivider(List<Integer> args, double relTolerance)
    • approximateGreatestCommonDivider

      public static int approximateGreatestCommonDivider(int first, int second, double relTolerance)
    • maxLength

      public static int maxLength(Iterable<String> strings)
    • maxLength

      public static int maxLength(String[] strings)
    • main

      public static void main(String[] args)
    • filesInDirMatchingRegExp

      public static File[] filesInDirMatchingRegExp(File dir, String regexp)
    • minDiff

      public static double minDiff(TreeSet<Double> numbers)
    • basename

      public static String basename(String filename)
    • addExtensionIfNotPresent

      public static String addExtensionIfNotPresent(String filename, String extension)
    • hashForDouble

      public static int hashForDouble(Double d)
    • lexicalCompare

      public static int lexicalCompare(int... compare)
      Support function for lexicographic compareTos
      Parameters:
      compare -
      Returns:
    • checkEncoding

      public static void checkEncoding(String encoding) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException