| Constructor and Description |
|---|
Segments() |
Segments(TextContainer parent)
Creates an uninitialized Segments object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(Segment segment)
Appends a segment at the end of this container.
|
void |
append(Segment segment,
boolean collapseIfPreviousEmpty)
Appends a segment at the end of this container.
|
void |
append(Segment segment,
String textBefore)
Appends a segment at the end of this container, with an optional non-segment part just before.
|
void |
append(Segment segment,
String textBefore,
boolean collapseIfPreviousEmpty)
Appends a segment at the end of this container, with an optional non-segment part just before.
|
void |
append(TextFragment fragment)
Appends a TextFragment as a segment at the end of this container.
|
void |
append(TextFragment fragment,
boolean collapseIfPreviousEmpty)
Appends a TextFragment as a segment at the end of this container.
|
List<Segment> |
asList()
Get all segments.
|
int |
count()
Gets the number of segments in this container.
|
int |
create(int start,
int end)
Creates a segment in this container.
|
int |
create(List<Range> ranges)
Helper method to create segments without empty segments.
|
int |
create(List<Range> ranges,
boolean allowEmptySegments)
Creates a set of segments in this container.
|
Segment |
get(int index)
Gets the segment for a given segment index.
|
Segment |
get(String id)
Gets the segment for a given identifier.
|
AlignmentStatus |
getAlignmentStatus()
Returns the
AlignmentStatus for these segments. |
TextFragment |
getFirstContent()
Gets the content of the first segment of this container.
|
int |
getIndex(String segId)
Gets the segment index for a given segment id.
|
Segment |
getLast()
Gets the last
Segment of the container. |
TextFragment |
getLastContent()
Gets the content of last segment of this container.
|
TextContainer |
getParent() |
int |
getPartIndex(int segIndex)
Gets the part index for a given segment index.
|
List<TextPart> |
getParts() |
List<Range> |
getRanges()
Gets the list of the boundaries for the current segments in this container.
|
void |
insert(int index,
Segment seg)
Inserts a given segment at the specified position.
|
Iterator<Segment> |
iterator()
Gets an iterator for the segments of this container.
|
void |
joinAll()
Merges back together all segments of this TextContainer object, and clear the
list of segments.
|
void |
joinAll(List<Range> ranges)
Merges back together all segments of this TextContainer object, and clear the
list of segments.
|
int |
joinWithNext(int segmentIndex)
Joins to a given segment all the parts between that segment and the next, as well as
the next segment.
|
void |
set(int index,
Segment seg)
Sets a new segment at a given segment index.
|
void |
setAlignmentStatus(AlignmentStatus alignmentStatus)
Sets the
AlignmentStatus for these segments. |
void |
setParts(List<TextPart> parts)
Sets the list of TextPart objects in which the segments for this Segments
object are located.
|
void |
swap(int segIndex1,
int segIndex2)
Swaps two segments in this container.
|
void |
validateSegmentId(Segment seg)
Checks if the id of a given segment is empty, null or a duplicate.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic Segments()
public Segments(TextContainer parent)
IMPORTANT: setParts() must be called with a non-null argument before calling any other methods.
parent - the parent TextContainer.public void setParts(List<TextPart> parts)
parts - the list of TextParts where the segments are stored.public Iterator<Segment> iterator()
ISegmentsISegments.iterator() for accessing both segments and non-segments parts.public List<Segment> asList()
ISegmentspublic void swap(int segIndex1,
int segIndex2)
ISegmentsFor example, if you have a container "[segment1] [segment2]" and call
swap(0,1) the resulting container becomes: "[segment2] [segment1]".
Note that the segments identifiers stay with their segment.
public void append(Segment segment, boolean collapseIfPreviousEmpty)
ISegmentspublic void append(Segment segment)
ISegmentsThis call is the same as calling ISegments.append(Segment, boolean) with collapseIfPreviousEmpty
set to true.
public void append(Segment segment, String textBefore, boolean collapseIfPreviousEmpty)
ISegmentsIf collapseIfPreviousEmpty is true and collapseIfPreviousEmpty is empty or null, and if the last part of the container is an empty segment, this new segment replaces the last one (including its id, and the new id is validated). Otherwise the new segment is appended to the content as a new segment part and its id is validated.
append in interface ISegmentssegment - the segment to append.textBefore - the text of the non-segment part before the segment (can be null).collapseIfPreviousEmpty - true to collapse the new segment if the last part of the container
is an empty segment (that is if textBefore is also empty or null).public void append(Segment segment, String textBefore)
ISegmentsThis call is the same as calling ISegments.append(Segment, String, boolean) with
collapseIfPreviousEmpty set to true.
public void append(TextFragment fragment, boolean collapseIfPreviousEmpty)
ISegmentsIf collapseIfPreviousEmpty is true and if the last part of the container is an empty segment, this new segment replaces the last one. Otherwise the new segment is appended to the content as a new segment part. In all case the id of the new segment is set automatically.
public void append(TextFragment fragment)
ISegmentsThis call is the same as calling ISegments.append(TextFragment, boolean) with
collapseIfPreviousEmpty set to true.
public void set(int index,
Segment seg)
ISegmentsIf the new segment's id exists already in the container, it is replaced by a valid id.
public void insert(int index,
Segment seg)
ISegmentsIf the segment to insert has no id or an id that is already used in the text container, the id is automatically changed to a new valid id.
insert in interface ISegmentsindex - the segment index position. If the given position is the same
as the number of segments in the container, the call is the same as ISegments.append(Segment, boolean)
with collapseIfPreviousEmpty set to true.seg - the segment to insert.public int create(List<Range> ranges)
ISegmentsISegments.create(List, boolean) with false.create in interface ISegmentsranges - the ranges of the segments to create.ISegments.create(List, boolean)public int create(List<Range> ranges, boolean allowEmptySegments)
ISegmentsTextContainer.getCodedText()
to get the coded text to use as the base for the segment boundaries.
If the content is already segmented, it is automatically un-segmented before the new
segmentation is applied.create in interface ISegmentsranges - the ranges of the segments to create. The ranges must be ordered from the lesser
position to the higher one (i.e. from left to right). If this parameter is empty or null, no
modification is done.allowEmptySegments - true to allow empty segments to be created, false to skip them.public int create(int start,
int end)
ISegmentsTextContainer.getCodedText()
to get the coded text to use as the base for the segment boundaries.
If the content is already segmented, it is automatically un-segmented before the new
segmentation is applied.
If start and end position are the same, no segment is created for those boundaries.
For example:
public int count()
ISegmentscount in interface ISegmentsTextContainer.count()public TextFragment getFirstContent()
ISegmentsgetFirstContent in interface ISegmentsTextContainer.getFirstContent(),
ISegments.getLastContent(),
TextContainer.getLastContent()public TextFragment getLastContent()
ISegmentsgetLastContent in interface ISegmentsISegments.getLastContent(),
TextContainer.getFirstContent(),
TextContainer.getFirstContent()public Segment getLast()
ISegmentsSegment of the container.public Segment get(String id)
ISegmentspublic Segment get(int index)
ISegmentsget in interface ISegmentsindex - the index of the segment to retrieve. The first
segment has the index 0, the second has the index 1, etc.
Note that the index value used here is not necessarily the same index as for a part.
That is: getSegment(0) returns the same segment as getPart(0) only if
the first part of the container is a segment.Use ISegments.get(String) to retrieve by segment identifier.
ISegments.get(String),
#see {@link #iterator()}public void joinAll()
ISegmentsjoinAll in interface ISegmentsISegments.joinAll(List)public void joinAll(List<Range> ranges)
ISegmentspublic List<Range> getRanges()
ISegmentspublic int joinWithNext(int segmentIndex)
ISegmentsFor example for the content: " [seg1] [seg2] ", the call joinWithNext(0) will give the result: " [seg1 seg2] ". And the call joinWithNext(1) will give the result: " [seg1] [seg2] " (no change because there is no segment after the segment 1.
joinWithNext in interface ISegmentssegmentIndex - index of the segment (not the part) where to append the next segment.public int getPartIndex(int segIndex)
ISegmentsFor example in the container "[segment1] [segment2] [segment3]" the segment index for "[segment2]" is 1 and its part index is 2 because there is one non-segment part before.
getPartIndex in interface ISegmentssegIndex - the segment index to convert to part index.public int getIndex(String segId)
ISegmentspublic AlignmentStatus getAlignmentStatus()
ISegmentsAlignmentStatus for these segments.getAlignmentStatus in interface ISegmentsAlignmentStatuspublic void setAlignmentStatus(AlignmentStatus alignmentStatus)
ISegmentsAlignmentStatus for these segments.setAlignmentStatus in interface ISegmentsalignmentStatus - the new AlignmentStatus value.public void validateSegmentId(Segment seg)
seg - the segment to verify and possibly modify.public TextContainer getParent()
Copyright © 2021. All rights reserved.