Segment.java revision 2362
2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A segment of a character array representing a fragment 0N/A * of text. It should be treated as immutable even though 0N/A * the array is directly accessible. This gives fast access 0N/A * to fragments of text without the overhead of copying 0N/A * around characters. This is effectively an unprotected 0N/A * The Segment implements the java.text.CharacterIterator 0N/A * interface to support use with the i18n support without 0N/A * copying text into a string. 0N/A * @author Timothy Prinzing 0N/A * This is the array containing the text of 0N/A * interest. This array should never be modified; 0N/A * it is available only for efficiency. 0N/A * This is the offset into the array that 0N/A * the desired text begins. 0N/A * This is the number of array elements that 0N/A * make up the text of interest. 0N/A * Creates a new segment. 0N/A * Creates a new segment referring to an existing array. 0N/A * @param array the array to refer to 0N/A * @param offset the offset into the array 0N/A * @param count the number of characters 0N/A * Flag to indicate that partial returns are valid. If the flag is true, 0N/A * an implementation of the interface method Document.getText(position,length,Segment) 0N/A * should return as much text as possible without making a copy. The default 0N/A * state of the flag is false which will cause Document.getText(position,length,Segment) 0N/A * to provide the same return behavior it always had, which may or may not 0N/A * make a copy of the text depending upon the request. 0N/A * @param p whether or not partial returns are valid. 0N/A * Flag to indicate that partial returns are valid. 0N/A * @return whether or not partial returns are valid. 0N/A * Converts a segment into a String. 0N/A * @return the string 0N/A // --- CharacterIterator methods ------------------------------------- 0N/A * Sets the position to getBeginIndex() and returns the character at that 0N/A * @return the first character in the text, or DONE if the text is empty 0N/A * @see #getBeginIndex 0N/A * Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) 0N/A * and returns the character at that position. 0N/A * @return the last character in the text, or DONE if the text is empty 0N/A * Gets the character at the current position (as returned by getIndex()). 0N/A * @return the character at the current position or DONE if the current 0N/A * position is off the end of the text. 0N/A * Increments the iterator's index by one and returns the character 0N/A * at the new index. If the resulting index is greater or equal 0N/A * to getEndIndex(), the current index is reset to getEndIndex() and 0N/A * a value of DONE is returned. 0N/A * @return the character at the new position or DONE if the new 0N/A * position is off the end of the text range. 0N/A * Decrements the iterator's index by one and returns the character 0N/A * at the new index. If the current index is getBeginIndex(), the index 0N/A * remains at getBeginIndex() and a value of DONE is returned. 0N/A * @return the character at the new position or DONE if the current 0N/A * position is equal to getBeginIndex(). 0N/A * Sets the position to the specified position in the text and returns that 0N/A * @param position the position within the text. Valid values range from 0N/A * getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown 0N/A * if an invalid value is supplied. 0N/A * @return the character at the specified position or DONE if the specified position is equal to getEndIndex() 0N/A * Returns the start index of the text. 0N/A * @return the index at which the text begins. 0N/A * Returns the end index of the text. This index is the index of the first 0N/A * character following the end of the text. 0N/A * @return the index after the last character in the text 0N/A * Returns the current index. 0N/A * @return the current index. 0N/A // --- CharSequence methods ------------------------------------- 0N/A * Creates a shallow copy.