Class CharAssociation

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class CharAssociation
    extends java.lang.Object
    implements java.lang.Cloneable
    A structure class encapsulating an interval of characters expressed as an offset and count of Unicode scalar values (in an IntBuffer). A CharAssociation is used to maintain a backpointer from a glyph to one or more character intervals from which the glyph was derived. Each glyph in a glyph sequence is associated with a single CharAssociation instance. A CharAssociation instance is additionally (and optionally) used to record predication information about the glyph, such as whether the glyph was produced by the application of a specific substitution table or whether its position was adjusted by a specific poisitioning table.

    This work was originally authored by Glenn Adams (gadams@apache.org).

    • Field Detail

      • offset

        private final int offset
      • count

        private final int count
      • subIntervals

        private final int[] subIntervals
      • predications

        private java.util.Map<java.lang.String,​java.lang.Object> predications
      • SORT_INCREMENTS_16

        private static final int[] SORT_INCREMENTS_16
      • SORT_INCREMENTS_03

        private static final int[] SORT_INCREMENTS_03
    • Constructor Detail

      • CharAssociation

        public CharAssociation​(int offset,
                               int count,
                               int[] subIntervals)
        Instantiate a character association.
        Parameters:
        offset - into array of Unicode scalar values (in associated IntBuffer)
        count - of Unicode scalar values (in associated IntBuffer)
        subIntervals - if disjoint, then array of sub-intervals, otherwise null; even members of array are sub-interval starts, and odd members are sub-interval ends (exclusive)
      • CharAssociation

        public CharAssociation​(int offset,
                               int count)
        Instantiate a non-disjoint character association.
        Parameters:
        offset - into array of UTF-16 code elements (in associated CharSequence)
        count - of UTF-16 character code elements (in associated CharSequence)
      • CharAssociation

        public CharAssociation​(int[] subIntervals)
        Instantiate a non-disjoint character association.
        Parameters:
        subIntervals - if disjoint, then array of sub-intervals, otherwise null; even members of array are sub-interval starts, and odd members are sub-interval ends (exclusive)
    • Method Detail

      • getOffset

        public int getOffset()
        Returns:
        offset (start of association interval)
      • getCount

        public int getCount()
        Returns:
        count (number of characer codes in association)
      • getStart

        public int getStart()
        Returns:
        start of association interval
      • getEnd

        public int getEnd()
        Returns:
        end of association interval
      • isDisjoint

        public boolean isDisjoint()
        Returns:
        true if association is disjoint
      • getSubIntervals

        public int[] getSubIntervals()
        Returns:
        subintervals of disjoint association
      • getSubIntervalCount

        public int getSubIntervalCount()
        Returns:
        count of subintervals of disjoint association
      • contained

        public boolean contained​(int offset,
                                 int count)
        Parameters:
        offset - of interval in sequence
        count - length of interval
        Returns:
        true if this association is contained within [offset,offset+count)
      • setPredication

        public void setPredication​(java.lang.String key,
                                   java.lang.Object value)
        Set predication <KEY,VALUE>.
        Parameters:
        key - predication key
        value - predication value
      • getPredication

        public java.lang.Object getPredication​(java.lang.String key)
        Get predication KEY.
        Parameters:
        key - predication key
        Returns:
        predication KEY at OFFSET or null if none exists
      • mergePredication

        public void mergePredication​(java.lang.String key,
                                     java.lang.Object value)
        Merge predication <KEY,VALUE>.
        Parameters:
        key - predication key
        value - predication value
      • mergePredicationValues

        public static java.lang.Object mergePredicationValues​(java.lang.String key,
                                                              java.lang.Object v1,
                                                              java.lang.Object v2)
        Merge predication values V1 and V2 on KEY. Uses registered PredicationMerger if one exists, otherwise uses V2 if non-null, otherwise uses V1.
        Parameters:
        key - predication key
        v1 - first (original) predication value
        v2 - second (to be merged) predication value
        Returns:
        merged value
      • mergePredications

        public void mergePredications​(CharAssociation ca)
        Merge predications from another CA.
        Parameters:
        ca - from which to merge
      • clone

        public java.lang.Object clone()
        Overrides:
        clone in class java.lang.Object
      • setPredicationMerger

        public static void setPredicationMerger​(java.lang.String key,
                                                CharAssociation.PredicationMerger pm)
        Register predication merger PM for KEY.
        Parameters:
        key - for predication merger
        pm - predication merger
      • getPredicationMerger

        public static CharAssociation.PredicationMerger getPredicationMerger​(java.lang.String key)
        Obtain predication merger for KEY.
        Parameters:
        key - for predication merger
        Returns:
        predication merger or null if none exists
      • replicate

        public static CharAssociation[] replicate​(CharAssociation a,
                                                  int repeat)
        Replicate association to form repeat new associations.
        Parameters:
        a - association to replicate
        repeat - count
        Returns:
        array of replicated associations
      • join

        public static CharAssociation join​(CharAssociation[] aa)
        Join (merge) multiple associations into a single, potentially disjoint association.
        Parameters:
        aa - array of associations to join
        Returns:
        (possibly disjoint) association containing joined associations
      • getSubIntervalsStart

        private static int getSubIntervalsStart​(int[] ia)
      • getSubIntervalsLength

        private static int getSubIntervalsLength​(int[] ia)
      • extractIntervals

        private static int[] extractIntervals​(CharAssociation[] aa)
        Extract sorted sub-intervals.
      • sortIntervals

        private static int[] sortIntervals​(int[] sa,
                                           int[] ea)
        Sort sub-intervals using modified Shell Sort.
      • mergeIntervals

        private static int[] mergeIntervals​(int[] ia)
        Merge overlapping and abutting sub-intervals.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object