Package org.passay

Class PassayUtils

java.lang.Object
org.passay.PassayUtils

public final class PassayUtils extends Object
Provides utility methods for this package.
  • Constructor Details

    • PassayUtils

      private PassayUtils()
      Default constructor.
  • Method Details

    • assertNotNullArg

      public static <T> T assertNotNullArg(T o, String msg)
      Throws IllegalArgumentException if the supplied object is null.
      Type Parameters:
      T - type of object
      Parameters:
      o - to check
      msg - to include in the exception
      Returns:
      supplied object
    • assertNotNullArgOr

      public static <T> T assertNotNullArgOr(T o, Predicate<T> predicate, String msg)
      Throws IllegalArgumentException if the supplied object is null or the supplied predicate returns true.
      Type Parameters:
      T - type of object
      Parameters:
      o - to check
      predicate - to test
      msg - to include in the exception
      Returns:
      supplied object
    • codePointCount

      public static int codePointCount(String string)
      Returns the number of code points in the supplied string.
      Parameters:
      string - to count characters
      Returns:
      number of code points
    • toString

      public static String toString(int... codePoints)
      Creates a new string from the supplied code points.
      Parameters:
      codePoints - to create string with
      Returns:
      new string
    • toByteArray

      public static byte[] toByteArray(CharSequence text, Charset charset)
      Converts the supplied text to a byte array using the supplied charset.
      Parameters:
      text - to convert to a byte array
      charset - to use for the conversion
      Returns:
      encoded byte array
    • toByteBuffer

      private static ByteBuffer toByteBuffer(CharSequence text, Charset charset)
      Converts the supplied text to a byte buffer using the supplied charset.
      Parameters:
      text - to convert to a byte array
      charset - to use for the conversion
      Returns:
      encoded byte buffer
    • clear

      public static void clear(Object o)
      Clears the supplied object by writing zeros to its data structure. The following types are supported:
      • char[]
      • byte[]
      • int[]
      • long[]
      • CharBuffer
      • ByteBuffer
      • IntBuffer
      • LongBuffer
      Parameters:
      o - to clear
      Throws:
      IllegalArgumentException - if the supplied object cannot be cleared
    • appendRandomCharacters

      public static void appendRandomCharacters(UnicodeString source, CharBuffer target, int count, Random rand)
      Appends characters to the supplied target with count random characters from source.
      Parameters:
      source - of random characters.
      target - character sequence that will hold characters.
      count - number of random characters.
      rand - to select characters from source.