站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

FlyOffsetGapList (Editor Utilities) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.util/1 1.17

org.netbeans.lib.editor.util
Class FlyOffsetGapList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.netbeans.lib.editor.util.GapList<E>
              extended by org.netbeans.lib.editor.util.FlyOffsetGapList<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

public abstract class FlyOffsetGapList<E>
extends GapList<E>

A variant of OffsetGapList additionally supporting flyweight (non-modifiable) elements.
Flyweight elements may not be modified during update operations when offset gap is moved and the raw offset must be updated or when the flyweight element is added or removed from the list.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FlyOffsetGapList()
           
 
Method Summary
protected  void consistencyCheck(boolean checkElementLength)
          Check consistency of this list.
 void defaultInsertUpdate(int offset, int length)
          Inform the list that there was an insert done into an underlying storage (e.g.
 void defaultRemoveUpdate(int offset, int length)
          Inform the list that there was a removal done into an underlying storage (e.g.
protected  String dumpInternals()
           
protected abstract  int elementLength(E elem)
          Get length of an element (assuming it has a length when it has an offset).
protected  int elementOffset(int index)
          Get the offset of an element stored in the list at the given index.
protected  int elementOrEndOffset(int indexOrSize)
          Get the offset of an element stored in the list at the given index like elementOffset(int) does or get end offset of the last element if GapList.size() is passed as index parameter.
protected abstract  int elementRawOffset(E elem)
          Get the raw offset of the given element currently stored in the list.
protected  int findElementIndex(int offset)
          Find an index of the first element at the given offset in the list by using binary search.
protected abstract  boolean isElementFlyweight(E elem)
          Check whether the given element is flyweight and therefore skipped during update operations.
protected  void moveOffsetGap(int offset, int index)
          Move the offset gap so that it's on the requested offset.
protected  int offset2Raw(int offset)
          Convert the given offset into raw form suitable for storing in this list.
protected  int offsetGapLength()
           
protected  int offsetGapStart()
           
protected abstract  void setElementRawOffset(E elem, int rawOffset)
          Set the raw offset of the given element currently stored in the list.
protected  int startOffset()
          Return base starting offset to which all the tokens contained in this list are related.
protected  void updateElementOffsetAdd(E elem)
          This method updates element's offset (shifts it above offset gap if necessary) before adding the element to the list.
protected  void updateElementOffsetRemove(E elem)
          This method updates element's offset (shifts it below offset gap if necessary) before (or after) the element gets removed from the list.
protected  void updateOffsetGapLength(int offsetGapLengthDelta)
          Update the offset gap length by the given delta.
protected  void updateOffsetGapStart(int offsetDelta)
          Update the offset gap length by the given delta.
 
Methods inherited from class org.netbeans.lib.editor.util.GapList
add, add, addAll, addAll, addArray, addArray, clear, clone, consistencyCheck, consistencyError, contains, copyElements, copyElements, copyItems, dumpDetails, dumpElements, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, swap, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

FlyOffsetGapList

public FlyOffsetGapList()
Method Detail

elementRawOffset

protected abstract int elementRawOffset(E elem)
Get the raw offset of the given element currently stored in the list.

Parameters:
elem - element currently stored in the list.
Returns:
raw offset of the element. It needs to be preprocessed by raw2RelOffset(int) to become the real offset.

setElementRawOffset

protected abstract void setElementRawOffset(E elem,
                                            int rawOffset)
Set the raw offset of the given element currently stored in the list.

Parameters:
elem - element currently stored in the list.
rawOffset - raw offset to be stored in the given element.

isElementFlyweight

protected abstract boolean isElementFlyweight(E elem)
Check whether the given element is flyweight and therefore skipped during update operations.

Returns:
true if the given element is flyweight or false otherwise.

elementLength

protected abstract int elementLength(E elem)
Get length of an element (assuming it has a length when it has an offset).
As there can be flyweight elements it's assumed that the flyweight elements occupy certain offset area.
This method is primarily used for measuring of flyweight elements (except consistency check) but subclasses may extend its use to any element.


startOffset

protected int startOffset()
Return base starting offset to which all the tokens contained in this list are related. The absolute token's offset is a sum of this start offset plus token's offset.
There may be just flyweight element(s) at the begining of the list so the start offset gives the necessary basing.
By default it's zero.


elementOffset

protected final int elementOffset(int index)
Get the offset of an element stored in the list at the given index.
The raw offset stored in the element is preprocessed to become a real offset.
Flyweight elements are supported and they are asked for occupied length by elementLength(Object) and its sum plus the first preceding non-flyweight element's offset is returned.
If there is no preceding non-flyweight element a zero offset is used as a base.

Parameters:
index - of the element in the list.
Returns:
offset of the element. It will include startOffset().
Throws:
IndexOutOfBoundsException - if index >= size() or lower than zero

elementOrEndOffset

protected final int elementOrEndOffset(int indexOrSize)
Get the offset of an element stored in the list at the given index like elementOffset(int) does or get end offset of the last element if GapList.size() is passed as index parameter.

Parameters:
indexOrSize - index of the element in the list. Index equal to size() can be used to get end offset of the last element.
Returns:
offset of the element. It will include startOffset().
Throws:
IndexOutOfBoundsException - if index > size() or lower than zero

defaultInsertUpdate

public void defaultInsertUpdate(int offset,
                                int length)
Inform the list that there was an insert done into an underlying storage (e.g. a swing document) which should move up offsets of the elements that have their offset greater or equal to the insertion offset.

Subclasses can build their own way of updating and they are not required to use this method.

Parameters:
offset - offset at which the insertion occurred. It should not include startOffset().
length - length of the inserted area.

defaultRemoveUpdate

public void defaultRemoveUpdate(int offset,
                                int length)
Inform the list that there was a removal done into an underlying storage (e.g. a swing document) which should move down offsets of the elements that have their offsets greater than the removal offset.
The offsets inside the removal area will be moved to its begining.

Subclasses can build their own way of updating and they are not required to use this method.

Parameters:
offset - offset at which the removal occurred. It should not include startOffset().
length - length of the removed area.

moveOffsetGap

protected final void moveOffsetGap(int offset,
                                   int index)
Move the offset gap so that it's on the requested offset.
This method can be used when the index of the first element at the given offset was precomputed already.

Note: Improper use of this may logically damage offsets of the elements contained in the list.

Parameters:
offset - offset to which the offsetGapStart should be assigned. It should not include startOffset().
index - index of the first element at the given offset in the list.
It may be computed by findElementIndex(int).

offsetGapStart

protected final int offsetGapStart()

updateOffsetGapStart

protected final void updateOffsetGapStart(int offsetDelta)
Update the offset gap length by the given delta.
This may be needed e.g. after insertion/removal was done in the document.

Note: Improper use of this may logically damage offsets of the elements contained in the list.


offsetGapLength

protected final int offsetGapLength()

updateOffsetGapLength

protected final void updateOffsetGapLength(int offsetGapLengthDelta)
Update the offset gap length by the given delta.
This may be needed e.g. after insertion/removal was done in the document.

Note: Improper use of this may logically damage offsets of the elements contained in the list.


findElementIndex

protected final int findElementIndex(int offset)
Find an index of the first element at the given offset in the list by using binary search.

Parameters:
offset - offset of the element to be found. It should not include startOffset().
Returns:
index of the element. If there is no element with that index then the index of the next element (with the greater offset) (or size of the list) will be returned.
If there are multiple items with the same offset then the first one of them will be returned.

updateElementOffsetAdd

protected void updateElementOffsetAdd(E elem)
This method updates element's offset (shifts it above offset gap if necessary) before adding the element to the list. This method should be called before (or after) the element is physically added to the list. If the element is added below the offset gap then calling of this method is not necessary.


updateElementOffsetRemove

protected void updateElementOffsetRemove(E elem)
This method updates element's offset (shifts it below offset gap if necessary) before (or after) the element gets removed from the list.
This method should be called after the element is physically removed from the list and it's desired that it retains its natural offset (not possibly shifted by the offset gap length).
If the element was located below the offset gap prior removal then calling of this method is not necessary.


offset2Raw

protected final int offset2Raw(int offset)
Convert the given offset into raw form suitable for storing in this list.

Parameters:
offset - >=0 absolute offset that includes startOffset().
Returns:
corresponding raw offset.

consistencyCheck

protected void consistencyCheck(boolean checkElementLength)
Check consistency of this list.

Parameters:
checkElementLength - whether elementLength(Object) should be called to check lengths of the elements and verify that the offsets are in concert with the offsets.

dumpInternals

protected String dumpInternals()
Overrides:
dumpInternals in class GapList<E>

org.netbeans.modules.editor.util/1 1.17

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.