Class CanonicalIterator


  • public final class CanonicalIterator
    extends java.lang.Object
    This class allows one to iterate through all the strings that are canonically equivalent to a given string. For example, here are some sample results: Results for: {A WITH RING ABOVE}{d}{DOT ABOVE}{CEDILLA}
     1: {A}{RING ABOVE}{d}{DOT ABOVE}{CEDILLA}
     2: {A}{RING ABOVE}{d}{CEDILLA}{DOT ABOVE}
     3: {A}{RING ABOVE}{d WITH DOT ABOVE}{CEDILLA}
     4: {A}{RING ABOVE}{d WITH CEDILLA}{DOT ABOVE}
     5: {A WITH RING ABOVE}{d}{DOT ABOVE}{CEDILLA}
     6: {A WITH RING ABOVE}{d}{CEDILLA}{DOT ABOVE}
     7: {A WITH RING ABOVE}{d WITH DOT ABOVE}{CEDILLA}
     8: {A WITH RING ABOVE}{d WITH CEDILLA}{DOT ABOVE}
     9: {ANGSTROM SIGN}{d}{DOT ABOVE}{CEDILLA}
    10: {ANGSTROM SIGN}{d}{CEDILLA}{DOT ABOVE}
    11: {ANGSTROM SIGN}{d WITH DOT ABOVE}{CEDILLA}
    12: {ANGSTROM SIGN}{d WITH CEDILLA}{DOT ABOVE}
    

    Note: the code is intended for use with small strings, and is not suitable for larger ones, since it has not been optimized for that situation.
    • Constructor Summary

      Constructors 
      Constructor Description
      CanonicalIterator​(java.lang.String source)
      Construct a CanonicalIterator object
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      private java.util.Set<java.lang.String> extract​(int comp, java.lang.String segment, int segmentPos, java.lang.StringBuffer buf)
      See if the decomposition of cp2 is at segment starting at segmentPos (with canonical rearrangment!) If so, take the remainder, and return the equivalents
      private java.lang.String[] getEquivalents​(java.lang.String segment)  
      private java.util.Set<java.lang.String> getEquivalents2​(java.lang.String segment)  
      java.lang.String getSource()
      Gets the NFD form of the current source we are iterating over.
      java.lang.String next()
      Get the next canonically equivalent string.
      static void permute​(java.lang.String source, boolean skipZeros, java.util.Set<java.lang.String> output)
      Deprecated.
      This API is ICU internal only.
      private static void permute​(java.lang.String source, boolean skipZeros, java.util.Set<java.lang.String> output, int depth)
      Deprecated.
      This API is ICU internal only.
      void reset()
      Resets the iterator so that one can start again from the beginning.
      void setSource​(java.lang.String newSource)
      Set a new source for this iterator.
      • Methods inherited from class java.lang.Object

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

      • PROGRESS

        private static boolean PROGRESS
      • SKIP_ZEROS

        private static boolean SKIP_ZEROS
      • source

        private java.lang.String source
      • done

        private boolean done
      • pieces

        private java.lang.String[][] pieces
      • current

        private int[] current
      • buffer

        private transient java.lang.StringBuilder buffer
      • SET_WITH_NULL_STRING

        private static final java.util.Set<java.lang.String> SET_WITH_NULL_STRING
    • Constructor Detail

      • CanonicalIterator

        public CanonicalIterator​(java.lang.String source)
        Construct a CanonicalIterator object
        Parameters:
        source - string to get results for
    • Method Detail

      • getSource

        public java.lang.String getSource()
        Gets the NFD form of the current source we are iterating over.
        Returns:
        gets the source: NOTE: it is the NFD form of the source originally passed in
      • reset

        public void reset()
        Resets the iterator so that one can start again from the beginning.
      • next

        public java.lang.String next()
        Get the next canonically equivalent string.
        Warning: The strings are not guaranteed to be in any particular order.
        Returns:
        the next string that is canonically equivalent. The value null is returned when the iteration is done.
      • setSource

        public void setSource​(java.lang.String newSource)
        Set a new source for this iterator. Allows object reuse.
        Parameters:
        newSource - the source string to iterate against. This allows the same iterator to be used while changing the source string, saving object creation.
      • permute

        @Deprecated
        public static void permute​(java.lang.String source,
                                   boolean skipZeros,
                                   java.util.Set<java.lang.String> output)
        Deprecated.
        This API is ICU internal only.
        Simple implementation of permutation.
        Warning: The strings are not guaranteed to be in any particular order.
        Parameters:
        source - the string to find permutations for
        skipZeros - set to true to skip characters with canonical combining class zero
        output - the set to add the results to
      • permute

        @Deprecated
        private static void permute​(java.lang.String source,
                                    boolean skipZeros,
                                    java.util.Set<java.lang.String> output,
                                    int depth)
        Deprecated.
        This API is ICU internal only.
        Simple implementation of permutation.
        Warning: The strings are not guaranteed to be in any particular order.
        Parameters:
        source - the string to find permutations for
        skipZeros - set to true to skip characters with canonical combining class zero
        output - the set to add the results to
        depth - the depth of the recursive call.
      • getEquivalents

        private java.lang.String[] getEquivalents​(java.lang.String segment)
      • getEquivalents2

        private java.util.Set<java.lang.String> getEquivalents2​(java.lang.String segment)
      • extract

        private java.util.Set<java.lang.String> extract​(int comp,
                                                        java.lang.String segment,
                                                        int segmentPos,
                                                        java.lang.StringBuffer buf)
        See if the decomposition of cp2 is at segment starting at segmentPos (with canonical rearrangment!) If so, take the remainder, and return the equivalents