19 using Lucene.Net.Support;
23 namespace Lucene.Net.Analysis.Tokenattributes
30 private static int MIN_BUFFER_SIZE = 10;
32 private char[] termBuffer;
33 private int termLength;
44 public virtual string Term
49 return new System.String(termBuffer, 0, termLength);
62 public virtual void SetTermBuffer(
char[] buffer,
int offset,
int length)
64 GrowTermBuffer(length);
65 Array.Copy(buffer, offset, termBuffer, 0, length);
72 public virtual void SetTermBuffer(System.String buffer)
74 int length = buffer.Length;
75 GrowTermBuffer(length);
89 public virtual void SetTermBuffer(System.String buffer,
int offset,
int length)
91 System.Diagnostics.Debug.Assert(offset <= buffer.Length);
92 System.Diagnostics.Debug.Assert(offset + length <= buffer.Length);
93 GrowTermBuffer(length);
106 public virtual char[] TermBuffer()
124 public virtual char[] ResizeTermBuffer(
int newSize)
126 if (termBuffer == null)
129 termBuffer =
new char[
ArrayUtil.GetNextSize(newSize < MIN_BUFFER_SIZE?MIN_BUFFER_SIZE:newSize)];
133 if (termBuffer.Length < newSize)
137 char[] newCharBuffer =
new char[
ArrayUtil.GetNextSize(newSize)];
138 Array.Copy(termBuffer, 0, newCharBuffer, 0, termBuffer.Length);
139 termBuffer = newCharBuffer;
151 private void GrowTermBuffer(
int newSize)
153 if (termBuffer == null)
156 termBuffer =
new char[
ArrayUtil.GetNextSize(newSize < MIN_BUFFER_SIZE?MIN_BUFFER_SIZE:newSize)];
160 if (termBuffer.Length < newSize)
164 termBuffer =
new char[
ArrayUtil.GetNextSize(newSize)];
169 private void InitTermBuffer()
171 if (termBuffer == null)
173 termBuffer =
new char[
ArrayUtil.GetNextSize(MIN_BUFFER_SIZE)];
181 public virtual int TermLength()
194 public virtual void SetTermLength(
int length)
197 if (length > termBuffer.Length)
198 throw new System.ArgumentException(
"length " + length +
" exceeds the size of the termBuffer (" + termBuffer.Length +
")");
202 public override int GetHashCode()
205 int code = termLength;
206 code = code * 31 +
ArrayUtil.HashCode(termBuffer, 0, termLength);
210 public override void Clear()
215 public override System.Object Clone()
219 if (termBuffer != null)
221 t.termBuffer =
new char[termBuffer.Length];
222 termBuffer.CopyTo(t.termBuffer, 0);
227 public override bool Equals(System.Object other)
240 if (termLength != o.termLength)
242 for (
int i = 0; i < termLength; i++)
244 if (termBuffer[i] != o.termBuffer[i])
255 public override System.String ToString()
258 return "term=" +
new System.String(termBuffer, 0, termLength);