1 package org.apache.lucene.analysis.tokenattributes;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import org.apache.lucene.util.Attribute;
23 * The term text of a Token.
25 public interface CharTermAttribute extends Attribute, CharSequence, Appendable {
27 /** Copies the contents of buffer, starting at offset for
28 * length characters, into the termBuffer array.
29 * @param buffer the buffer to copy
30 * @param offset the index in the buffer of the first character to copy
31 * @param length the number of characters to copy
33 public void copyBuffer(char[] buffer, int offset, int length);
35 /** Returns the internal termBuffer character array which
36 * you can then directly alter. If the array is too
37 * small for your token, use {@link
38 * #resizeBuffer(int)} to increase it. After
39 * altering the buffer be sure to call {@link
40 * #setLength} to record the number of valid
41 * characters that were placed into the termBuffer. */
42 public char[] buffer();
44 /** Grows the termBuffer to at least size newSize, preserving the
46 * @param newSize minimum size of the new termBuffer
47 * @return newly created termBuffer with length >= newSize
49 public char[] resizeBuffer(int newSize);
51 /** Set number of valid characters (length of the term) in
52 * the termBuffer array. Use this to truncate the termBuffer
53 * or to synchronize with external manipulation of the termBuffer.
54 * Note: to grow the size of the array,
55 * use {@link #resizeBuffer(int)} first.
56 * @param length the truncated length
58 public CharTermAttribute setLength(int length);
60 /** Sets the length of the termBuffer to zero.
61 * Use this method before appending contents
62 * using the {@link Appendable} interface.
64 public CharTermAttribute setEmpty();
66 // the following methods are redefined to get rid of IOException declaration:
67 public CharTermAttribute append(CharSequence csq);
68 public CharTermAttribute append(CharSequence csq, int start, int end);
69 public CharTermAttribute append(char c);
71 /** Appends the specified {@code String} to this character sequence.
72 * <p>The characters of the {@code String} argument are appended, in order, increasing the length of
73 * this sequence by the length of the argument. If argument is {@code null}, then the four
74 * characters {@code "null"} are appended.
76 public CharTermAttribute append(String s);
78 /** Appends the specified {@code StringBuilder} to this character sequence.
79 * <p>The characters of the {@code StringBuilder} argument are appended, in order, increasing the length of
80 * this sequence by the length of the argument. If argument is {@code null}, then the four
81 * characters {@code "null"} are appended.
83 public CharTermAttribute append(StringBuilder sb);
85 /** Appends the contents of the other {@code CharTermAttribute} to this character sequence.
86 * <p>The characters of the {@code CharTermAttribute} argument are appended, in order, increasing the length of
87 * this sequence by the length of the argument. If argument is {@code null}, then the four
88 * characters {@code "null"} are appended.
90 public CharTermAttribute append(CharTermAttribute termAtt);