pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / analysis / tokenattributes / CharTermAttribute.java
1 package org.apache.lucene.analysis.tokenattributes;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 import org.apache.lucene.util.Attribute;
21
22 /**
23  * The term text of a Token.
24  */
25 public interface CharTermAttribute extends Attribute, CharSequence, Appendable {
26   
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
32    */
33   public void copyBuffer(char[] buffer, int offset, int length);
34   
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();
43
44   /** Grows the termBuffer to at least size newSize, preserving the
45    *  existing content.
46    *  @param newSize minimum size of the new termBuffer
47    *  @return newly created termBuffer with length >= newSize
48    */
49   public char[] resizeBuffer(int newSize);
50
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
57    */
58   public CharTermAttribute setLength(int length);
59   
60   /** Sets the length of the termBuffer to zero.
61    * Use this method before appending contents
62    * using the {@link Appendable} interface.
63    */
64   public CharTermAttribute setEmpty();
65   
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);
70
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. 
75    */
76   public CharTermAttribute append(String s);
77
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. 
82    */
83   public CharTermAttribute append(StringBuilder sb);
84
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. 
89    */
90   public CharTermAttribute append(CharTermAttribute termAtt);
91 }