public final class FoldUtilities extends Object
Note: Until explicitly noted all the utility methods
require a lock to be held on the FoldHierarchy
during execution of the methods.
Modifier and Type | Method and Description |
---|---|
static List |
childrenAsList(Fold fold)
Return children of the given fold as modifiable list.
|
static List |
childrenAsList(Fold fold,
int index,
int count)
Return children of the given fold as list.
|
static Fold[] |
childrenToArray(Fold fold)
Return children of the given fold as array.
|
static Fold[] |
childrenToArray(Fold fold,
int index,
int count)
Return children of the given fold as array.
|
static void |
collapse(FoldHierarchy hierarchy,
Collection foldTypes)
Collapse all folds that having any
of the fold types in the given collection.
|
static void |
collapse(FoldHierarchy hierarchy,
FoldType type)
Collapse all folds of the given type.
|
static void |
collapseAll(FoldHierarchy hierarchy)
Collapse all folds in the hierarchy.
|
static Iterator |
collapsedFoldIterator(FoldHierarchy hierarchy,
int startOffset,
int endOffset)
Get iterator over the collapsed folds.
|
static boolean |
containsOffset(Fold fold,
int offset)
Check whether fold contains the given offset.
|
static void |
expand(FoldHierarchy hierarchy,
Collection foldTypes)
Expand all folds of the given type (or all folds if the type is null)
found in the whole fold hierarchy.
|
static void |
expand(FoldHierarchy hierarchy,
FoldType type)
Expand all folds of the given type.
|
static void |
expandAll(FoldHierarchy hierarchy)
Expand all folds in the hierarchy.
|
static List |
find(Fold fold,
Collection foldTypes)
Find direct subfolds of the given fold having any
of the fold types in the given collection.
|
static List |
find(Fold fold,
FoldType foldType)
Find direct subfolds of the given fold having certain type.
|
static Fold |
findCollapsedFold(FoldHierarchy hierarchy,
int startOffset,
int endOffset)
Find a first collapsed fold by going from top-level folds to more nested ones
within the requested bounds.
|
static int |
findFoldEndIndex(Fold fold,
int offset)
Find index of the first child of the given fold that ends
above the given offset ("contains" the offset).
|
static int |
findFoldStartIndex(Fold fold,
int offset)
Find index of the child of the given fold that
starts right at or below the given offset.
|
static Fold |
findNearestFold(FoldHierarchy hierarchy,
int offset)
Find the fold nearest to the given offset.
|
static Fold |
findOffsetFold(FoldHierarchy hierarchy,
int offset)
Find a deepest fold in the hierarchy which contains the offset
or has it as one of its boundaries.
|
static List |
findRecursive(Fold fold)
Collect all children of the given fold recursively.
|
static List |
findRecursive(Fold fold,
Collection foldTypes)
Recursively find any subfolds of the given fold having any
of the fold types in the given collection.
|
static List |
findRecursive(Fold fold,
FoldType foldType)
Recursively find any subfolds of the given fold having certain type.
|
static FoldType.Domain |
getFoldTypes(String mimeType)
Obtains available FoldType values for the specified MIME type.
|
static boolean |
isAutoCollapsed(FoldType ft,
FoldHierarchy hierarchy)
Determines whether folds of that type are should be initially collapsed.
|
static boolean |
isEmpty(Fold fold)
Check whether the starting offset of the fold is the same like
its ending offset.
|
static boolean |
isFoldingEnabled(String mimeType)
Determines whether folding is enabled for a given MIME type.
|
static boolean |
isRootFold(Fold fold)
Is the given fold a root fold?
|
public static boolean isRootFold(Fold fold)
fold
- non-null fold which is either root fold or a regular fold.public static int findFoldStartIndex(Fold fold, int offset)
This method uses binary search and has log2(n) performance
where n is number of children of the given fold.
The efficiency may drop to linear if there would be many empty folds
at the given offset.
fold
- fold which children will be inspected.offset
- >=0 offset in the document for which the representing
child will be searched.index
is returned
if offset >= getFold(index).getStartOffset()
and offset <= getFold(index + 1).getStartOffset()
.
-1
is returned
if offset < getFold(0).getStartOffset()
and in case the fold does not have any children.public static int findFoldEndIndex(Fold fold, int offset)
This method uses binary search and has log2(n) performance
where n is number of children of the given fold.
The efficiency may drop to linear if there would be many empty folds
at the given offset.
fold
- fold which children will be inspected.offset
- >=0 offset in the document for which the representing
child will be searched.index
is returned for which
offset < getFold(index).getEndOffset()
fold.getFoldCount()
in case there is no such fold.public static boolean isEmpty(Fold fold)
fold
- fold that should be checked whether it's empty.public static void collapseAll(FoldHierarchy hierarchy)
hierarchy
- hierarchy under which all folds should be collapsed.public static void collapse(FoldHierarchy hierarchy, FoldType type)
hierarchy
- hierarchy under which the folds should be collapsed.type
- folds with this type will be collapsed.public static void collapse(FoldHierarchy hierarchy, Collection foldTypes)
hierarchy
- hierarchy under which the folds should be collapsed.foldTypes
- collection of fold types to search for.public static void expandAll(FoldHierarchy hierarchy)
hierarchy
- hierarchy under which all folds should be expanded.public static void expand(FoldHierarchy hierarchy, FoldType type)
hierarchy
- hierarchy under which the folds should be expanded.type
- folds with this type will be expanded.public static void expand(FoldHierarchy hierarchy, Collection foldTypes)
hierarchy
- hierarchy under which the folds should be expanded.foldTypes
- collection of fold types to search for.public static boolean containsOffset(Fold fold, int offset)
fold
- fold to be tested for containing the given offsetoffset
- that will be tested for being contained in the given fold.offset >= fold.getStartOffset()
&& offset < fold.getEndOffset()
public static Fold[] childrenToArray(Fold fold)
fold
- fold which children will be returned.public static Fold[] childrenToArray(Fold fold, int index, int count)
fold
- fold which children will be returned.index
- >=0 index of the first child to be returned.count
- >=0 number of children to be returned.
index + count <= Fold.getFoldCount()
.public static List childrenAsList(Fold fold)
FoldUtilities.findRecursive(Fold)
can be used
to collect children recursively.fold
- fold which children will be returned.public static List childrenAsList(Fold fold, int index, int count)
fold
- fold which children will be returned.index
- >=0 index of the first child to be returned.count
- >=0 number of children to be returned.
index + count <= Fold.getFoldCount()
.public static List find(Fold fold, FoldType foldType)
fold
- direct children of this fold will be searched.
The search is *not* recursive in grandchildren etc.foldType
- non-null fold type to search for.public static List find(Fold fold, Collection foldTypes)
fold
- direct children of this fold will be searched.
The search is *not* recursive in grandchildren etc.foldTypes
- collection of fold types to search for.public static List findRecursive(Fold fold)
fold
- all children of this fold will be collected.public static List findRecursive(Fold fold, FoldType foldType)
fold
- all children of this fold will be searched.
The search is recursive into grandchildren etc.foldType
- non-null fold type to search for.public static List findRecursive(Fold fold, Collection foldTypes)
fold
- all children of this fold will be searched.
The search is recursive into grandchildren etc.foldTypes
- collection of fold types to search for.public static Fold findNearestFold(FoldHierarchy hierarchy, int offset)
null
if such a fold cannot be found,
that is if no fold follows (or precedes, for negative offset values) the offset.
offset
- offset in a document, or negated value of offset to indicate backwards search.public static Fold findOffsetFold(FoldHierarchy hierarchy, int offset)
offset
- >=0 offset in a document.fold.getStartOffset() >= offset && offset <= fold.getEndOffset()
or null if there is no such fold (except the root fold) satisfying the condition.
public static Fold findCollapsedFold(FoldHierarchy hierarchy, int startOffset, int endOffset)
hierarchy
- hierarchy in which to search.startOffset
- >=0 only fold ending above it will be returned.endOffset
- >=0 only fold starting below it will be returned.fold.getEndOffset() > startOffset and fold.getStartOffset() < endOffset
or null if such fold does not exist.public static Iterator collapsedFoldIterator(FoldHierarchy hierarchy, int startOffset, int endOffset)
hierarchy
- hierarchy in which to search.startOffset
- >=0 only folds ending above it will be returned.endOffset
- >=0 only folds starting before it will be returned.fold.getEndOffset() > startOffset and fold.getStartOffset() < endOffset
public static FoldType.Domain getFoldTypes(String mimeType)
mimeType
- mime type of the contentpublic static boolean isAutoCollapsed(FoldType ft, FoldHierarchy hierarchy)
ft
- FoldType to inspecthierarchy
- context for evaluationpublic static boolean isFoldingEnabled(String mimeType)
MimePath.EMPTY
.getMimeType() to query for the default (all languages)
setting.mimeType
- the MIME type of the content.