Package 

Class Util


  • 
    public final class Util
    
                        

    Junk drawer of utility methods.

    • Method Detail

      • checkOffsetAndCount

         static void checkOffsetAndCount(long arrayLength, long offset, long count)
      • equal

         static boolean equal(Object a, Object b)

        Returns true if two possibly-null objects are equal.

      • closeQuietly

         static void closeQuietly(Closeable closeable)

        Closes {@code closeable}, ignoring any checked exceptions. Does nothing if {@code closeable} isnull.

      • closeQuietly

         static void closeQuietly(Socket socket)

        Closes {@code socket}, ignoring any checked exceptions. Does nothing if {@code socket} isnull.

      • closeQuietly

         static void closeQuietly(ServerSocket serverSocket)

        Closes {@code serverSocket}, ignoring any checked exceptions. Does nothing if {@code * serverSocket} is null.

      • discard

         static boolean discard(Source source, int timeout, TimeUnit timeUnit)

        Attempts to exhaust {@code source}, returning true if successful. This is useful when reading acomplete source is helpful, such as when doing so completes a cache body or frees a socketconnection for reuse.

      • skipAll

         static boolean skipAll(Source source, int duration, TimeUnit timeUnit)

        Reads until {@code in} is exhausted or the deadline has been reached. This is careful to notextend the deadline if one exists already.

      • immutableList

         static <T> List<T> immutableList(Array<T> elements)

        Returns an immutable list containing {@code elements}.

      • nonEmptyIntersection

         static boolean nonEmptyIntersection(Comparator<String> comparator, Array<String> first, Array<String> second)

        Returns true if there is an element in {@code first} that is also in {@code second}. Thismethod terminates if any intersection is found. The sizes of both arguments are assumed to beso small, and the likelihood of an intersection so great, that it is not worth the CPU cost ofsorting or the memory cost of hashing.

      • isAndroidGetsocknameError

         static boolean isAndroidGetsocknameError(AssertionError e)

        Returns true if {@code e} is due to a firmware bug fixed after Android 4.2.2.https://code.google.com/p/android/issues/detail?id=54072

      • skipLeadingAsciiWhitespace

         static int skipLeadingAsciiWhitespace(String input, int pos, int limit)

        Increments {@code pos} until {@code input[pos]} is not ASCII whitespace. Stops at {@code * limit}.

      • skipTrailingAsciiWhitespace

         static int skipTrailingAsciiWhitespace(String input, int pos, int limit)

        Decrements {@code limit} until {@code input[limit - 1]} is not ASCII whitespace. Stops at {@code pos}.

      • trimSubstring

         static String trimSubstring(String string, int pos, int limit)

        Equivalent to {@code string.substring(pos, limit).trim()}.

      • delimiterOffset

         static int delimiterOffset(String input, int pos, int limit, String delimiters)

        Returns the index of the first character in {@code input} that contains a character in {@code * delimiters}. Returns limit if there is no such character.

      • delimiterOffset

         static int delimiterOffset(String input, int pos, int limit, char delimiter)

        Returns the index of the first character in {@code input} that is {@code delimiter}. Returnslimit if there is no such character.

      • canonicalizeHost

         static String canonicalizeHost(String host)

        If {@code host} is an IP address, this returns the IP address in canonical form.

        Otherwise this performs IDN ToASCII encoding and canonicalize the result to lowercase. Forexample this converts {@code ☃.net} to {@code xn--n3h.net}, and {@code WwW.GoOgLe.cOm} to {@code www.google.com}. {@code null} will be returned if the host cannot be ToASCII encoded orif the result contains unsupported ASCII characters.

      • indexOfControlOrNonAscii

         static int indexOfControlOrNonAscii(String input)

        Returns the index of the first character in {@code input} that is either a control character(like {@code \u0000 or \n}) or a non-ASCII character. Returns -1 if {@code input} has no suchcharacters.

      • verifyAsIpAddress

         static boolean verifyAsIpAddress(String host)

        Returns true if {@code host} is not a host name and might be an IP address.