Class StructuredTextStringRecord
java.lang.Object
org.eclipse.equinox.bidi.internal.StructuredTextStringRecord
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intNumber of entries in the pool of recorded strings -
Method Summary
Modifier and TypeMethodDescriptionstatic StructuredTextStringRecordRecords a string in the pool.voidaddSegment(String handlerID, int start, int limit) Adds a second or further segment to a record.static voidclear()Clears the pool.getHandler(int segmentNumber) Retrieves the handler ID of a given segment.intgetLimit(int segmentNumber) Retrieves the ending offset of a given segment.static StructuredTextStringRecordChecks if a string is recorded and retrieves its record.intRetrieves the number of segments in a record.intgetStart(int segmentNumber) Retrieves the starting offset of a given segment.
-
Field Details
-
POOLSIZE
public static final int POOLSIZENumber 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 inStructuredTextTypeHandlerFactory, 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 thestartargument 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- ifstringis null or ifsegmentCountis less than 1.IllegalArgumentException- ifhandlerIDis null, or ifstartorlimithave invalid values.IllegalStateException- if the current segment exceeds the number of segments specified bysegmentCountin the call toaddRecordwhich created the StructuredTextStringRecord instance.
-
addSegment
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 inStructuredTextTypeHandlerFactory, 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 thestartargument and not greater than the length of the string.- Throws:
IllegalArgumentException- ifhandlerIDis null, or ifstartorlimithave invalid values.IllegalStateException- if the current segment exceeds the number of segments specified bysegmentCountin the call toaddRecordwhich created the StructuredTextStringRecord instance.
-
getRecord
Checks if a string is recorded and retrieves its record.- Parameters:
string- the string to check.- Returns:
nullif the string is not recorded in the pool; otherwise, return theStructuredTextStringRecordinstance which records this string.
Once a record has been found, the number of its segments can be retrieved usinggetSegmentCount, its handler ID can be retrieved usinggetHandler, its starting offset can be retrieved usinggetStart, its ending offset can be retrieved usinggetLimit,
-
getSegmentCount
public int getSegmentCount()Retrieves the number of segments in a record.- Returns:
- the number of segments in the current record
-
getHandler
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 bygetSegmentCount().- Returns:
- the handler ID of the handler appropriate to process the structured
text in the segment specified by
segmentNumber. - Throws:
IllegalArgumentException- ifsegmentNumberhas 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 bygetSegmentCount().- Returns:
- the starting offset within the string of the segment specified by
segmentNumber. - Throws:
IllegalArgumentException- ifsegmentNumberhas 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 bygetSegmentCount().- Returns:
- the offset of the position following the segment specified by
segmentNumber. - Throws:
IllegalArgumentException- ifsegmentNumberhas an invalid value.
-
clear
public static void clear()Clears the pool. All elements of the pool are erased and any associated memory is freed.
-