Class CharSet

java.lang.Object
eu.bandm.tools.d2d2.infra.CharSet
All Implemented Interfaces:
CharSet, Serializable, Predicate<Character>

public class CharSet extends Object implements CharSet, Serializable
Implements Character Sets as an ordered sequence of ranges.
Behaves immutable.
See Also:
  • Field Details

    • LOW

      public static final char LOW
      Lowest possible character value, currently 0x0000, needed for the definition of negate().
      See Also:
    • HI

      public static final char HI
      Highest possible character value, needed for the definition of negate().
      See Also:
    • EMPTY_SET

      public static final CharSet EMPTY_SET
      evident
    • ALL_CHARS

      public static final CharSet ALL_CHARS
      All supported characters, currently MORE than unicode ! DOCME
  • Constructor Details

    • CharSet

      public CharSet(char l, char u)
      Construct an instance which ontains the range from l to u.
      Throws:
      IllegalArgumentException - in case l is numerically larger than u.
    • CharSet

      public CharSet(char l)
      Construct a singleton character set.
    • CharSet

      public CharSet(String s)
      Construct an instance which contains the all characters contained in the string argument.
  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(CharSet o)
      Evident
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • makeCharSet

      public static CharSet makeCharSet(String chars)
      Constructs an instance which contains all characters contained in the string argument.
    • contains

      public boolean contains(char c)
      Evident
      Specified by:
      contains in interface CharSet
    • singletonContents

      @Opt public @Opt Character singletonContents()
      Evident.
      Returns:
      the only member of this, if it is a singleton set, otherwise null.
    • and

      public CharSet and(CharSet cs2)
      Calculates the intersection of both sets.
    • negate

      public CharSet negate()
      Calculates the netation of this set, w.r.t. the unversal range from LOW to HI.
      Specified by:
      negate in interface CharSet
      Specified by:
      negate in interface Predicate<Character>
    • or

      public CharSet or(CharSet cs2)
      Calculates the union of the two sets. Implemented by stepping through the ordered list of ranges and "zipping" them.
    • xn

      protected static String xn(char c)
      Generate a numeric representation of a character, whenever sensible.
    • stringRep

      public String stringRep()
      Generate a numeric representation of the character ranges in the set.
      Returns:
      a symbolic string representation, showing characters and decimal values.
    • stringRepD2d

      public String stringRepD2d()
      Returns:
      the un-parsed representation according to D2d module syntax.
    • staticStringRepD2d

      public static String staticStringRepD2d(CharSet cs)
      Static variant of stringRepD2d().