Package dsa

Class Alphabet

java.lang.Object
dsa.Alphabet

public class Alphabet extends Object
An immutable data type to represent an alphabet.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static Alphabet
    The ASCII alphabet (0-127).
    static Alphabet
    The base-64 alphabet (64 characters).
    static Alphabet
    The binary alphabet { 0, 1 }.
    static Alphabet
    The decimal alphabet { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.
    static Alphabet
    The DNA alphabet { A, C, T, G }.
    static Alphabet
    The extended ASCII alphabet (0-255).
    static Alphabet
    The hexadecimal alphabet { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }.
    static Alphabet
    The lowercase alphabet { a, b, c, ..., z }.
    static Alphabet
    The octal alphabet { 0, 1, 2, 3, 4, 5, 6, 7 }.
    static Alphabet
    The protein alphabet { A, C, D, E, F, G, H, I, K, L, M, N, P, Q, R, S, T, V, W, Y }.
    static Alphabet
    The Unicode 16 alphabet (0-65,535).
    static Alphabet
    The uppercase alphabet { A, B, C, ..., Z }.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new alphabet using characters 0 through 255.
    Constructs a new alphabet from the string of characters s.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(char c)
    Returns true if c is a character in this alphabet, and false otherwise.
    int
    Returns the binary logarithm (rounded up) of this alphabet's radix.
    static void
    main(String[] args)
    Unit tests the data type.
    int
    Returns the radix of this alphabet, ie, the number of characters in it.
    char
    toChar(int index)
    Returns the character with the given index.
    toChars(int[] indices)
    Returns the characters with the given indices.
    int
    toIndex(char c)
    Returns the index of c.
    int[]
    Returns the indices of the characters in s.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BINARY

      public static Alphabet BINARY
      The binary alphabet { 0, 1 }.
    • OCTAL

      public static Alphabet OCTAL
      The octal alphabet { 0, 1, 2, 3, 4, 5, 6, 7 }.
    • DECIMAL

      public static Alphabet DECIMAL
      The decimal alphabet { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.
    • HEXADECIMAL

      public static Alphabet HEXADECIMAL
      The hexadecimal alphabet { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }.
    • DNA

      public static Alphabet DNA
      The DNA alphabet { A, C, T, G }.
    • LOWERCASE

      public static Alphabet LOWERCASE
      The lowercase alphabet { a, b, c, ..., z }.
    • UPPERCASE

      public static Alphabet UPPERCASE
      The uppercase alphabet { A, B, C, ..., Z }.
    • PROTEIN

      public static Alphabet PROTEIN
      The protein alphabet { A, C, D, E, F, G, H, I, K, L, M, N, P, Q, R, S, T, V, W, Y }.
    • BASE64

      public static Alphabet BASE64
      The base-64 alphabet (64 characters).
    • ASCII

      public static Alphabet ASCII
      The ASCII alphabet (0-127).
    • EXTENDED_ASCII

      public static Alphabet EXTENDED_ASCII
      The extended ASCII alphabet (0-255).
    • UNICODE16

      public static Alphabet UNICODE16
      The Unicode 16 alphabet (0-65,535).
  • Constructor Details

    • Alphabet

      public Alphabet()
      Constructs a new alphabet using characters 0 through 255.
    • Alphabet

      public Alphabet(String s)
      Constructs a new alphabet from the string of characters s.
      Parameters:
      s - the string of characters.
  • Method Details

    • contains

      public boolean contains(char c)
      Returns true if c is a character in this alphabet, and false otherwise.
      Parameters:
      c - the character.
      Returns:
      true if c is a character in this alphabet, and false otherwise.
    • radix

      public int radix()
      Returns the radix of this alphabet, ie, the number of characters in it.
      Returns:
      the radix of this alphabet.
    • lgRadix

      public int lgRadix()
      Returns the binary logarithm (rounded up) of this alphabet's radix.
      Returns:
      the binary logarithm (rounded up) of this alphabet's radix.
    • toIndex

      public int toIndex(char c)
      Returns the index of c.
      Parameters:
      c - the character.
      Returns:
      the index of c.
    • toIndices

      public int[] toIndices(String s)
      Returns the indices of the characters in s.
      Parameters:
      s - the characters.
      Returns:
      the indices of the characters in s.
    • toChar

      public char toChar(int index)
      Returns the character with the given index.
      Parameters:
      index - the index.
      Returns:
      the character with the given index.
    • toChars

      public String toChars(int[] indices)
      Returns the characters with the given indices.
      Parameters:
      indices - the indices.
      Returns:
      the characters with the given indices.
    • main

      public static void main(String[] args)
      Unit tests the data type.
      Parameters:
      args - the command-line arguments.