Class StructuredTextStringRecord

java.lang.Object
org.eclipse.equinox.bidi.internal.StructuredTextStringRecord

public class StructuredTextStringRecord extends Object
Records strings which contain structured text. Several static methods in this class allow to record such strings in a pool, and to find if a given string is member of the pool.

Instances of this class are the records which are members of the pool.

The pool is managed as a cyclic list. When the pool is full, each new element overrides the oldest element in the list.

A string may be itself entirely a structured text, or it may contain segments each of which is a structured text of a given type. Each such segment is identified by its starting and ending offsets within the string, and by the handler which is appropriate to handle it.

  • Field Details

    • POOLSIZE

      public static final int POOLSIZE
      Number of entries in the pool of recorded strings
      See Also:
  • Method Details

    • addRecord

      public static StructuredTextStringRecord addRecord(String string, int segmentCount, String handlerID, int start, int limit)
      Records a string in the pool. The caller must specify the number of segments in the record (at least 1), and the handler, starting and ending offsets for the first segment.
      Parameters:
      string - the string to record.
      segmentCount - number of segments allowed in this string. This number must be >= 1.
      handlerID - identifier for the handler appropriate to handle the type of structured text present in the first segment. It may be one of the predefined identifiers in StructuredTextTypeHandlerFactory, or it may be an identifier for a type handler created by a plug-in or by the application.
      start - offset in the string of the starting character of the first segment. It must be >= 0 and less than the length of the string.
      limit - offset of the character following the first segment. It must be greater than the start argument and not greater than the length of the string.
      Returns:
      an instance of StructuredTextRecordString which represents this record. This instance may be used to specify additional segments with addSegment.
      Throws:
      IllegalArgumentException - if string is null or if segmentCount is less than 1.
      IllegalArgumentException - if handlerID is null, or if start or limit have invalid values.
      IllegalStateException - if the current segment exceeds the number of segments specified by segmentCount in the call to addRecord which created the StructuredTextStringRecord instance.
    • addSegment

      public void addSegment(String handlerID, int start, int limit)
      Adds a second or further segment to a record.
      Parameters:
      handlerID - identifier for the handler appropriate to handle the type of structured text present in the first segment. It may be one of the predefined identifiers in StructuredTextTypeHandlerFactory, or it may be an identifier for a type handler created by a plug-in or by the application.
      start - offset in the string of the starting character of the segment. It must be >= 0 and less than the length of the string.
      limit - offset of the character following the segment. It must be greater than the start argument and not greater than the length of the string.
      Throws:
      IllegalArgumentException - if handlerID is null, or if start or limit have invalid values.
      IllegalStateException - if the current segment exceeds the number of segments specified by segmentCount in the call to addRecord which created the StructuredTextStringRecord instance.
    • getRecord

      public static StructuredTextStringRecord getRecord(String string)
      Checks if a string is recorded and retrieves its record.
      Parameters:
      string - the string to check.
      Returns:
      null if the string is not recorded in the pool; otherwise, return the StructuredTextStringRecord instance which records this string.
      Once a record has been found, the number of its segments can be retrieved using getSegmentCount, its handler ID can be retrieved using getHandler, its starting offset can be retrieved using getStart, its ending offset can be retrieved using getLimit,
    • getSegmentCount

      public int getSegmentCount()
      Retrieves the number of segments in a record.
      Returns:
      the number of segments in the current record
    • getHandler

      public String getHandler(int segmentNumber)
      Retrieves the handler ID of a given segment.
      Parameters:
      segmentNumber - number of the segment about which information is required. It must be >= 0 and less than the number of segments returned by getSegmentCount().
      Returns:
      the handler ID of the handler appropriate to process the structured text in the segment specified by segmentNumber.
      Throws:
      IllegalArgumentException - if segmentNumber has an invalid value.
    • getStart

      public int getStart(int segmentNumber)
      Retrieves the starting offset of a given segment.
      Parameters:
      segmentNumber - number of the segment about which information is required. It must be >= 0 and less than the number of segments returned by getSegmentCount().
      Returns:
      the starting offset within the string of the segment specified by segmentNumber.
      Throws:
      IllegalArgumentException - if segmentNumber has an invalid value.
    • getLimit

      public int getLimit(int segmentNumber)
      Retrieves the ending offset of a given segment.
      Parameters:
      segmentNumber - number of the segment about which information is required. It must be >= 0 and less than the number of segments returned by getSegmentCount().
      Returns:
      the offset of the position following the segment specified by segmentNumber.
      Throws:
      IllegalArgumentException - if segmentNumber has an invalid value.
    • clear

      public static void clear()
      Clears the pool. All elements of the pool are erased and any associated memory is freed.