/** * Computes the index in the list of positions at which a position with the given * offset would be inserted. The position is supposed to become the first in this list * of all positions with the same offset. * * @param positions the list in which the index is computed * @param offset the offset for which the index is computed * @return the computed index * * @see IDocument#computeIndexInCategory(String, int) * @deprecated As of 3.4, replaced by {@link #computeIndexInPositionList(List, int, boolean)} */ @Deprecated protected int computeIndexInPositionList(List<? extends Position> positions, int offset) { return computeIndexInPositionList(positions, offset, true); }
/** * Computes the index in the list of positions at which a position with the given * offset would be inserted. The position is supposed to become the first in this list * of all positions with the same offset. * * @param positions the list in which the index is computed * @param offset the offset for which the index is computed * @return the computed index * * @see IDocument#computeIndexInCategory(String, int) * @deprecated As of 3.4, replaced by {@link #computeIndexInPositionList(List, int, boolean)} */ @Deprecated protected int computeIndexInPositionList(List<? extends Position> positions, int offset) { return computeIndexInPositionList(positions, offset, true); }
/** * A list of positions in the given category with an end position inside * the given region. The order of the positions is arbitrary. * * @param category the position category * @param offset the offset of the region * @param length the length of the region * @return a list of the positions in the region * @throws BadPositionCategoryException if category is undefined in this document * @since 3.4 */ private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException { List<Position> positions= fEndPositions.get(category); if (positions == null) throw new BadPositionCategoryException(); int indexStart= computeIndexInPositionList(positions, offset, false); int indexEnd= computeIndexInPositionList(positions, offset + length, false); return positions.subList(indexStart, indexEnd); }
/** * A list of positions in the given category with an offset inside the given * region. The order of the positions is arbitrary. * * @param category the position category * @param offset the offset of the region * @param length the length of the region * @return a list of the positions in the region * @throws BadPositionCategoryException if category is undefined in this document * @since 3.4 */ private List<Position> getStartingPositions(String category, int offset, int length) throws BadPositionCategoryException { List<Position> positions= fPositions.get(category); if (positions == null) throw new BadPositionCategoryException(); int indexStart= computeIndexInPositionList(positions, offset, true); int indexEnd= computeIndexInPositionList(positions, offset + length, true); return positions.subList(indexStart, indexEnd); }
/** * A list of positions in the given category with an offset inside the given * region. The order of the positions is arbitrary. * * @param category the position category * @param offset the offset of the region * @param length the length of the region * @return a list of the positions in the region * @throws BadPositionCategoryException if category is undefined in this document * @since 3.4 */ private List<Position> getStartingPositions(String category, int offset, int length) throws BadPositionCategoryException { List<Position> positions= fPositions.get(category); if (positions == null) throw new BadPositionCategoryException(); int indexStart= computeIndexInPositionList(positions, offset, true); int indexEnd= computeIndexInPositionList(positions, offset + length, true); return positions.subList(indexStart, indexEnd); }
/** * A list of positions in the given category with an end position inside * the given region. The order of the positions is arbitrary. * * @param category the position category * @param offset the offset of the region * @param length the length of the region * @return a list of the positions in the region * @throws BadPositionCategoryException if category is undefined in this document * @since 3.4 */ private List<Position> getEndingPositions(String category, int offset, int length) throws BadPositionCategoryException { List<Position> positions= fEndPositions.get(category); if (positions == null) throw new BadPositionCategoryException(); int indexStart= computeIndexInPositionList(positions, offset, false); int indexEnd= computeIndexInPositionList(positions, offset + length, false); return positions.subList(indexStart, indexEnd); }
@Override public boolean containsPosition(String category, int offset, int length) { if (category == null) return false; List<Position> list= fPositions.get(category); if (list == null) return false; int size= list.size(); if (size == 0) return false; int index= computeIndexInPositionList(list, offset); if (index < size) { Position p= list.get(index); while (p != null && p.offset == offset) { if (p.length == length) return true; ++ index; p= (index < size) ? list.get(index) : null; } } return false; }
@Override public boolean containsPosition(String category, int offset, int length) { if (category == null) return false; List<Position> list= fPositions.get(category); if (list == null) return false; int size= list.size(); if (size == 0) return false; int index= computeIndexInPositionList(list, offset); if (index < size) { Position p= list.get(index); while (p != null && p.offset == offset) { if (p.length == length) return true; ++ index; p= (index < size) ? list.get(index) : null; } } return false; }
int index= computeIndexInPositionList(positions, orderedByOffset ? position.offset : position.offset + position.length - 1, orderedByOffset); if (index < size && positions.get(index) == position) { positions.remove(index);
int index= computeIndexInPositionList(positions, orderedByOffset ? position.offset : position.offset + position.length - 1, orderedByOffset); if (index < size && positions.get(index) == position) { positions.remove(index);
@Override public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength())) throw new BadLocationException(); if (category == null) throw new BadPositionCategoryException(); List<Position> list= fPositions.get(category); if (list == null) throw new BadPositionCategoryException(); list.add(computeIndexInPositionList(list, position.offset), position); List<Position> endPositions= fEndPositions.get(category); if (endPositions == null) throw new BadPositionCategoryException(); endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position); }
@Override public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { if ((0 > position.offset) || (0 > position.length) || (position.offset + position.length > getLength())) throw new BadLocationException(); if (category == null) throw new BadPositionCategoryException(); List<Position> list= fPositions.get(category); if (list == null) throw new BadPositionCategoryException(); list.add(computeIndexInPositionList(list, position.offset), position); List<Position> endPositions= fEndPositions.get(category); if (endPositions == null) throw new BadPositionCategoryException(); endPositions.add(computeIndexInPositionList(endPositions, position.offset + position.length - 1, false), position); }
@Override public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException { if (0 > offset || offset > getLength()) throw new BadLocationException(); List<Position> c= fPositions.get(category); if (c == null) throw new BadPositionCategoryException(); return computeIndexInPositionList(c, offset); }
@Override public int computeIndexInCategory(String category, int offset) throws BadLocationException, BadPositionCategoryException { if (0 > offset || offset > getLength()) throw new BadLocationException(); List<Position> c= fPositions.get(category); if (c == null) throw new BadPositionCategoryException(); return computeIndexInPositionList(c, offset); }