Package com.castlabs.sdk.base.subtitles.utilities

# Class Util

java.lang.Object
com.castlabs.sdk.base.subtitles.utilities.Util

public class Util extends Object

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DEVICE`
  Like `Build.DEVICE`, but in a place where it can be conveniently overridden for local testing.
  `static final String`
  `DEVICE_DEBUG_INFO`
  A concise description of the device that it can be useful to log for debugging purposes.
  `static final byte[]`
  `EMPTY_BYTE_ARRAY`
  An empty byte array.
  `static final String`
  `MANUFACTURER`
  Like `Build.MANUFACTURER`, but in a place where it can be conveniently overridden for local testing.
  `static final String`
  `MODEL`
  Like `Build.MODEL`, but in a place where it can be conveniently overridden for local testing.
  `static final int`
  `SDK_INT`
  Like `Build.VERSION.SDK_INT`, but in a place where it can be conveniently overridden for local testing.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Util()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static boolean`
  `areEqual(Object o1, Object o2)`
  Tests two objects for `Object.equals(Object)` equality, handling the case where one or both may be null.
  `static <T> T`
  `castNonNull(T value)`
  Casts a nullable variable to a non-null variable without runtime null check.
  `static String`
  `fromUtf8Bytes(byte[] bytes)`
  Returns a new `String` constructed by decoding UTF-8 encoded bytes.
  `static String`
  `fromUtf8Bytes(byte[] bytes, int offset, int length)`
  Returns a new `String` constructed by decoding UTF-8 encoded bytes in a subarray.
  `static String`
  `getCodecsOfType(String codecs, int trackType)`
  Returns a copy of `codecs` without the codecs whose track type doesn't match `trackType`.
  `static int`
  `getIntegerCodeForString(String string)`
  Returns the integer equal to the big-endian concatenation of the characters in `string` as bytes.
  `static byte[]`
  `getUtf8Bytes(String value)`
  Returns a new byte array containing the code points of a `String` encoded using UTF-8.
  `static boolean`
  `isLinebreak(int c)`
  Returns whether the given character is a carriage return ('\r') or a line feed ('\n').
  `static <T> T[]`
  `nullSafeArrayConcatenation(T[] first, T[] second)`
  Creates a new array containing the concatenation of two non-null type arrays.
  `static String[]`
  `split(String value, String regex)`
  Splits a string using `value.split(regex, -1`).
  `static String[]`
  `splitAtFirst(String value, String regex)`
  Splits the string at the first occurrence of the delimiter `regex`.
  `static String[]`
  `splitCodecs(String codecs)`
  Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings.
  `static long`
  `toLong(int mostSignificantBits, int leastSignificantBits)`
  Return the long that is composed of the bits of the 2 specified integers.
  `static @PolyNull String`
  `toLowerInvariant(@PolyNull String text)`
  Converts text to lower case using `Locale.US`.
  `static long`
  `toUnsignedLong(int x)`
  Converts an integer to a long by unsigned conversion.
  `static @PolyNull String`
  `toUpperInvariant(@PolyNull String text)`
  Converts text to upper case using `Locale.US`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### SDK_INT

    public static final int SDK_INT
    Like `Build.VERSION.SDK_INT`, but in a place where it can be conveniently overridden for local testing.

  - ### DEVICE

    public static final String DEVICE
    Like `Build.DEVICE`, but in a place where it can be conveniently overridden for local testing.

  - ### MANUFACTURER

    public static final String MANUFACTURER
    Like `Build.MANUFACTURER`, but in a place where it can be conveniently overridden for local testing.

  - ### MODEL

    public static final String MODEL
    Like `Build.MODEL`, but in a place where it can be conveniently overridden for local testing.

  - ### DEVICE_DEBUG_INFO

    public static final String DEVICE_DEBUG_INFO
    A concise description of the device that it can be useful to log for debugging purposes.

  - ### EMPTY_BYTE_ARRAY

    public static final byte[] EMPTY_BYTE_ARRAY
    An empty byte array.

- ## Constructor Details

  - ### Util

    public Util()

- ## Method Details

  - ### splitCodecs

    public static String[] splitCodecs(@Nullable String codecs)
    Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings.
    Parameters:
      `codecs` - A codec sequence string, as defined in RFC 6381.
    Returns:
      The split codecs, or an array of length zero if the input was empty or null.

  - ### split

    public static String[] split(String value, String regex)
    Splits a string using `value.split(regex, -1`). Note: this is is similar to `String.split(String)` but empty matches at the end of the string will not be omitted from the returned array.
    Parameters:
      `value` - The string to split.
      `regex` - A delimiting regular expression.
    Returns:
      The array of strings resulting from splitting the string.

  - ### splitAtFirst

    public static String[] splitAtFirst(String value, String regex)
    Splits the string at the first occurrence of the delimiter `regex`. If the delimiter does not match, returns an array with one element which is the input string. If the delimiter does match, returns an array with the portion of the string before the delimiter and the rest of the string.
    Parameters:
      `value` - The string.
      `regex` - A delimiting regular expression.
    Returns:
      The string split by the first occurrence of the delimiter.

  - ### isLinebreak

    public static boolean isLinebreak(int c)
    Returns whether the given character is a carriage return ('\r') or a line feed ('\n').
    Parameters:
      `c` - The character.
    Returns:
      Whether the given character is a linebreak.

  - ### toLowerInvariant

    public static @PolyNull String toLowerInvariant(@PolyNull String text)
    Converts text to lower case using `Locale.US`.
    Parameters:
      `text` - The text to convert.
    Returns:
      The lower case text, or null if `text` is null.

  - ### toUpperInvariant

    public static @PolyNull String toUpperInvariant(@PolyNull String text)
    Converts text to upper case using `Locale.US`.
    Parameters:
      `text` - The text to convert.
    Returns:
      The upper case text, or null if `text` is null.

  - ### nullSafeArrayConcatenation

    public static <T> T[] nullSafeArrayConcatenation(T[] first, T[] second)
    Creates a new array containing the concatenation of two non-null type arrays.
    Parameters:
      `first` - The first array.
      `second` - The second array.
    Returns:
      The concatenated result.

  - ### castNonNull

    @EnsuresNonNull("#1") public static <T> T castNonNull(@Nullable T value)
    Casts a nullable variable to a non-null variable without runtime null check.

    Use `Assertions.checkNotNull(Object)` to throw if the value is null.

  - ### areEqual

    public static boolean areEqual(@Nullable Object o1, @Nullable Object o2)
    Tests two objects for `Object.equals(Object)` equality, handling the case where one or both may be null.
    Parameters:
      `o1` - The first object.
      `o2` - The second object.
    Returns:
      `o1 == null ? o2 == null : o1.equals(o2)`.

  - ### getCodecsOfType

    @Nullable public static String getCodecsOfType(@Nullable String codecs, int trackType)
    Returns a copy of `codecs` without the codecs whose track type doesn't match `trackType`.
    Parameters:
      `codecs` - A codec sequence string, as defined in RFC 6381.
      `trackType` - One of `Constants``.TRACK_TYPE_*`.
    Returns:
      A copy of `codecs` without the codecs whose track type doesn't match `trackType`. If this ends up empty, or `codecs` is null, return null.

  - ### getIntegerCodeForString

    public static int getIntegerCodeForString(String string)
    Returns the integer equal to the big-endian concatenation of the characters in `string` as bytes. The string must be no more than four characters long.
    Parameters:
      `string` - A string no more than four characters long.

  - ### toLong

    public static long toLong(int mostSignificantBits, int leastSignificantBits)
    Return the long that is composed of the bits of the 2 specified integers.
    Parameters:
      `mostSignificantBits` - The 32 most significant bits of the long to return.
      `leastSignificantBits` - The 32 least significant bits of the long to return.
    Returns:
      a long where its 32 most significant bits are `mostSignificantBits` bits and its 32 least significant bits are `leastSignificantBits`.

  - ### toUnsignedLong

    public static long toUnsignedLong(int x)
    Converts an integer to a long by unsigned conversion.

    This method is equivalent to `Integer.toUnsignedLong(int)` for API 26+.

  - ### fromUtf8Bytes

    public static String fromUtf8Bytes(byte[] bytes)
    Returns a new `String` constructed by decoding UTF-8 encoded bytes.
    Parameters:
      `bytes` - The UTF-8 encoded bytes to decode.
    Returns:
      The string.

  - ### fromUtf8Bytes

    public static String fromUtf8Bytes(byte[] bytes, int offset, int length)
    Returns a new `String` constructed by decoding UTF-8 encoded bytes in a subarray.
    Parameters:
      `bytes` - The UTF-8 encoded bytes to decode.
      `offset` - The index of the first byte to decode.
      `length` - The number of bytes to decode.
    Returns:
      The string.

  - ### getUtf8Bytes

    public static byte[] getUtf8Bytes(String value)
    Returns a new byte array containing the code points of a `String` encoded using UTF-8.
    Parameters:
      `value` - The `String` whose bytes should be obtained.
    Returns:
      The code points encoding using UTF-8.