From 1d6371df439b1d12d9f5e65374dda813d4ff642b Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Thu, 1 Jun 2006 21:15:37 +0000 Subject: [PATCH] remove final, implement Cloneable, setTermText(): LUCENE-438 git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@410954 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 5 +++++ src/java/org/apache/lucene/analysis/Token.java | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) 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 + } + } }