Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.netbeans.modules.editor.fold/1 1.5.22
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.netbeans.api.editor.fold
Class FoldUtilities

    java.lang.Object
      org.netbeans.api.editor.fold.FoldUtilities

    public final class FoldUtilities

extends Object

Various utility methods for dealing with the folds.

Note: Until explicitly noted all the utility methods require a lock to be held on the `FoldHierarchy` during execution of the methods.

Method Summary
`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 the first collapsed fold (deep-diving into the hierarchy) in the requested boundaries.
`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 nearest fold that either starts right at or follows 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 boolean` | `isEmpty(Fold fold)` Check whether the starting offset of the fold is the same like its ending offset.
`static boolean` | `isRootFold(Fold fold)` Is the given fold a root fold?

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### isRootFold

    public static boolean isRootFold(Fold fold)

  Is the given fold a root fold?

  Parameters:
    `fold` - non-null fold which is either root fold or a regular fold.
  Returns:
    true if the given fold is root fold or false otherwise.

### findFoldStartIndex

    public 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.

  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.

  Parameters:
    `fold` - fold which children will be inspected.
    `offset` - >=0 offset in the document for which the representing child will be searched.
  Returns:
    index of the child fold that represents the given offset.
    An `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.

### findFoldEndIndex

    public 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).

  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.

  Parameters:
    `fold` - fold which children will be inspected.
    `offset` - >=0 offset in the document for which the representing child will be searched.
  Returns:
    index of the child fold that contains or is above the given offset.
    A highest `index` is returned for which `offset < getFold(index).getEndOffset()`
    or `fold.getFoldCount()` in case there is no such fold.

### isEmpty

    public static boolean isEmpty(Fold fold)

  Check whether the starting offset of the fold is the same like its ending offset.

  Parameters:
    `fold` - fold that should be checked whether it's empty.
  Returns:
    true if the fold is empty or false otherwise.

### collapseAll

    public static void collapseAll(FoldHierarchy hierarchy)

  Collapse all folds in the hierarchy.
  This method does the necessary locking of the document and hierarchy.

  Parameters:
    `hierarchy` - hierarchy under which all folds should be collapsed.

### collapse

    public static void collapse(FoldHierarchy hierarchy,
                                FoldType type)

  Collapse all folds of the given type.
  This method does the necessary locking of the document and hierarchy.

  Parameters:
    `hierarchy` - hierarchy under which the folds should be collapsed.
    `type` - folds with this type will be collapsed.

### collapse

    public static void collapse(FoldHierarchy hierarchy,
                                Collection foldTypes)

  Collapse all folds that having any of the fold types in the given collection.
  This method does the necessary locking of the document and hierarchy.

  Parameters:
    `hierarchy` - hierarchy under which the folds should be collapsed.
    `foldTypes` - collection of fold types to search for.

### expandAll

    public static void expandAll(FoldHierarchy hierarchy)

  Expand all folds in the hierarchy.
  This method does the necessary locking of the document and hierarchy.

  Parameters:
    `hierarchy` - hierarchy under which all folds should be expanded.

### expand

    public static void expand(FoldHierarchy hierarchy,
                              FoldType type)

  Expand all folds of the given type.
  This method does the necessary locking of the document and hierarchy.

  Parameters:
    `hierarchy` - hierarchy under which the folds should be expanded.
    `type` - folds with this type will be expanded.

### expand

    public 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.
  This method does the necessary locking of the document and hierarchy.

  Parameters:
    `hierarchy` - hierarchy under which the folds should be expanded.
    `foldTypes` - collection of fold types to search for.

### containsOffset

    public static boolean containsOffset(Fold fold,
                                         int offset)

  Check whether fold contains the given offset.

  Parameters:
    `fold` - fold to be tested for containing the given offset
    `offset` - that will be tested for being contained in the given fold.
  Returns:
    true if `offset >= fold.getStartOffset() && offset < fold.getEndOffset()`

### childrenToArray

    public static Fold[] childrenToArray(Fold fold)

  Return children of the given fold as array.

  Parameters:
    `fold` - fold which children will be returned.
  Returns:
    non-null array of all child folds.

### childrenToArray

    public static Fold[] childrenToArray(Fold fold,
                                         int index,
                                         int count)

  Return children of the given fold as array.

  Parameters:
    `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()``.
  Returns:
    non-null array of selected child folds.

### childrenAsList

    public static List childrenAsList(Fold fold)

  Return children of the given fold as modifiable list.
  `findRecursive(Fold)` can be used to collect children recursively.

  Parameters:
    `fold` - fold which children will be returned.
  Returns:
    non-null modifiable list of all child folds.

### childrenAsList

    public static List childrenAsList(Fold fold,
                                      int index,
                                      int count)

  Return children of the given fold as list.

  Parameters:
    `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()``.
  Returns:
    non-null list of selected child folds.
    The list can potentially be further modified by the caller without any effect on the fold hierarchy.

### find

    public static List find(Fold fold,
                            FoldType foldType)

  Find direct subfolds of the given fold having certain type.
  Complexity corresponds to number of direct child folds under the given fold.

  Parameters:
    `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.
  Returns:
    non-null list of folds matching the criteria.
    The list can potentially be further modified by the caller without any effect on the fold hierarchy.

### find

    public static List find(Fold fold,
                            Collection foldTypes)

  Find direct subfolds of the given fold having any of the fold types in the given collection.
  Complexity corresponds to number of direct child folds under the given fold.

  Parameters:
    `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.
  Returns:
    non-null list of folds matching the criteria.
    The list can potentially be further modified by the caller without any effect on the fold hierarchy.

### findRecursive

    public static List findRecursive(Fold fold)

  Collect all children of the given fold recursively.
  Complexity corresponds to number of all child folds (including grandchildren etc.) under the given fold.

  Parameters:
    `fold` - all children of this fold will be collected.
  Returns:
    non-null list of folds matching the criteria.
    The list can potentially be further modified by the caller without any effect on the fold hierarchy.

### findRecursive

    public static List findRecursive(Fold fold,
                                     FoldType foldType)

  Recursively find any subfolds of the given fold having certain type.
  Complexity corresponds to number of all child folds (including grandchildren etc.) under the given fold.

  Parameters:
    `fold` - all children of this fold will be searched. The search is recursive into grandchildren etc.
    `foldType` - non-null fold type to search for.
  Returns:
    non-null list of folds matching the criteria.
    The list can potentially be further modified by the caller without any effect on the fold hierarchy.

### findRecursive

    public 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.
  Complexity corresponds to number of all child folds (including grandchildren etc.) under the given fold.

  Parameters:
    `fold` - all children of this fold will be searched. The search is recursive into grandchildren etc.
    `foldTypes` - collection of fold types to search for.
  Returns:
    non-null list of folds matching the criteria.
    The list can potentially be further modified by the caller without any effect on the fold hierarchy.

### findNearestFold

    public static Fold findNearestFold(FoldHierarchy hierarchy,
                                       int offset)

  Find nearest fold that either starts right at or follows the given offset.
  The search deep-dives into hierarchy.

  Parameters:
    `offset` - >=0 offset in a document.
  Returns:
    fold in the hierarchy that starts directly at the offset or follows it. The most important is the lowest distance of the start of the fold to the given offset. If there would be a nearest fold having a first child that starts at the same position like the parent then the parent would be returned.

### findOffsetFold

    public 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.
  The search deep-dives into hierarchy.

  Parameters:
    `offset` - >=0 offset in a document.
  Returns:
    deepset fold in the hierarchy satisfying `fold.getStartOffset() >= offset && offset <= fold.getEndOffset()` or null if there is no such fold (except the root fold) satisfying the condition.
    For two consecutive folds (one ending at the offset and the next one starting at the offset) the latter fold would be returned.

### findCollapsedFold

    public static Fold findCollapsedFold(FoldHierarchy hierarchy,
                                         int startOffset,
                                         int endOffset)

  Find the first collapsed fold (deep-diving into the hierarchy) in the requested boundaries.

  Parameters:
    `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.
  Returns:
    collapsed fold satisfying `fold.getEndOffset() > startOffset and fold.getStartOffset() < endOffset` or null if such fold does not exist.

### collapsedFoldIterator

    public static Iterator collapsedFoldIterator(FoldHierarchy hierarchy,
                                                 int startOffset,
                                                 int endOffset)

  Get iterator over the collapsed folds.

  Parameters:
    `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.
  Returns:
    iterator over collapsed folds satisfying `fold.getEndOffset() > startOffset and fold.getStartOffset() < endOffset`
    If a particular collapsed fold gets returned then its children are not deep-dived for collapsed folds. Instead the search continues by a following sibling.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.netbeans.modules.editor.fold/1 1.5.22
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Built on December 7 2006. | Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.