Skip to content

Apache Lucene open-source search software

remove final, implement Cloneable, setTermText(): LUCENE-438

Yonik Seeley1d6371df439b
diff --git a/CHANGES.txt b/CHANGES.txt
index edbf984fade..8e2f5e6cb8d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,11 @@ New features
1.
+API Changes
+
+ 1. LUCENE-438: Remove "final" from Token, implement Cloneable, allow
+ changing of termText via setTermText(). (Yonik Seeley)
+
Bug fixes
1. Fixed the web application demo (built with "ant war-demo") which
diff --git a/src/java/org/apache/lucene/analysis/Token.java b/src/java/org/apache/lucene/analysis/Token.java
index a761bed7520..2d0e28af0b9 100644
--- a/src/java/org/apache/lucene/analysis/Token.java
+++ b/src/java/org/apache/lucene/analysis/Token.java
@@ -30,7 +30,7 @@ package org.apache.lucene.analysis;
belongs to. For example an end of sentence marker token might be implemented
with type "eos". The default token type is "word". */
-public final class Token {
+public class Token implements Cloneable {
String termText; // the text of the term
int startOffset; // start in source text
int endOffset; // end in source text
@@ -91,6 +91,11 @@ public final class Token {
*/
public int getPositionIncrement() { return positionIncrement; }
+ /** Sets the Token's term text. */
+ public void setTermText(String text) {
+ termText = text;
+ }
+
/** Returns the Token's term text. */
public final String termText() { return termText; }
@@ -109,7 +114,7 @@ public final class Token {
/** Returns this Token's lexical type. Defaults to "word". */
public final String type() { return type; }
- public final String toString() {
+ public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("(" + termText + "," + startOffset + "," + endOffset);
if (!type.equals("word"))
@@ -119,4 +124,12 @@ public final class Token {
sb.append(")");
return sb.toString();
}
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e); // shouldn't happen since we implement Cloneable
+ }
+ }
}