You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2015/01/10 14:08:51 UTC
svn commit: r1650737 - in /lucene/dev/trunk/lucene: ./
core/src/java/org/apache/lucene/analysis/
core/src/test/org/apache/lucene/analysis/
spatial/src/java/org/apache/lucene/spatial/prefix/
Author: uschindler
Date: Sat Jan 10 13:08:50 2015
New Revision: 1650737
URL: http://svn.apache.org/r1650737
Log:
LUCENE-6173: Fix deep clone
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java
lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1650737&r1=1650736&r2=1650737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Sat Jan 10 13:08:50 2015
@@ -433,6 +433,9 @@ Bug Fixes
been returning the offsets of just the matching tokens in the group when
there's a distinction. (David Smiley)
+* LUCENE-6173: NumericTermAttribute and spatial/CellTokenStream do not clone
+ their BytesRef(Builder)s. Also equals/hashCode was missing. (Uwe Schindler)
+
Documentation
* LUCENE-5392: Add/improve analysis package documentation to reflect
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java?rev=1650737&r1=1650736&r2=1650737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java Sat Jan 10 13:08:50 2015
@@ -212,6 +212,39 @@ public final class NumericTokenStream ex
final NumericTermAttribute a = (NumericTermAttribute) target;
a.init(value, valueSize, precisionStep, shift);
}
+
+ @Override
+ public NumericTermAttributeImpl clone() {
+ NumericTermAttributeImpl t = (NumericTermAttributeImpl)super.clone();
+ // Do a deep clone
+ t.bytes = new BytesRefBuilder();
+ t.bytes.copyBytes(bytes.get());
+ return t;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + precisionStep;
+ result = prime * result + shift;
+ result = prime * result + Long.hashCode(value);
+ result = prime * result + valueSize;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ NumericTermAttributeImpl other = (NumericTermAttributeImpl) obj;
+ if (precisionStep != other.precisionStep) return false;
+ if (shift != other.shift) return false;
+ if (value != other.value) return false;
+ if (valueSize != other.valueSize) return false;
+ return true;
+ }
}
/**
Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java?rev=1650737&r1=1650736&r2=1650737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java Sat Jan 10 13:08:50 2015
@@ -19,7 +19,9 @@ package org.apache.lucene.analysis;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.NumericUtils;
+import org.apache.lucene.analysis.NumericTokenStream.NumericTermAttributeImpl;
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
+import org.apache.lucene.analysis.tokenattributes.TestCharTermAttributeImpl;
import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.CharTermAttributeImpl;
@@ -30,6 +32,7 @@ public class TestNumericTokenStream exte
static final int ivalue = 123456;
public void testLongStream() throws Exception {
+ @SuppressWarnings("resource")
final NumericTokenStream stream=new NumericTokenStream().setLongValue(lvalue);
final TermToBytesRefAttribute bytesAtt = stream.getAttribute(TermToBytesRefAttribute.class);
assertNotNull(bytesAtt);
@@ -54,6 +57,7 @@ public class TestNumericTokenStream exte
}
public void testIntStream() throws Exception {
+ @SuppressWarnings("resource")
final NumericTokenStream stream=new NumericTokenStream().setIntValue(ivalue);
final TermToBytesRefAttribute bytesAtt = stream.getAttribute(TermToBytesRefAttribute.class);
assertNotNull(bytesAtt);
@@ -93,6 +97,8 @@ public class TestNumericTokenStream exte
} catch (IllegalStateException e) {
// pass
}
+
+ stream.close();
}
public static interface TestAttribute extends CharTermAttribute {}
@@ -112,6 +118,15 @@ public class TestNumericTokenStream exte
} catch (IllegalArgumentException iae) {
assertTrue(iae.getMessage().startsWith("NumericTokenStream does not support"));
}
+ stream.close();
+ }
+
+ public void testAttributeClone() throws Exception {
+ NumericTermAttributeImpl att = new NumericTermAttributeImpl();
+ NumericTermAttributeImpl copy = TestCharTermAttributeImpl.assertCloneIsEqual(att);
+ assertNotSame(att.getBytesRef(), copy.getBytesRef());
+ NumericTermAttributeImpl copy2 = TestCharTermAttributeImpl.assertCopyIsEqual(att);
+ assertNotSame(att.getBytesRef(), copy2.getBytesRef());
}
}
Modified: lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java?rev=1650737&r1=1650736&r2=1650737&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java Sat Jan 10 13:08:50 2015
@@ -124,6 +124,35 @@ class CellTokenStream extends TokenStrea
fillBytesRef();
reflector.reflect(TermToBytesRefAttribute.class, "bytes", BytesRef.deepCopyOf(bytes));
}
+
+ @Override
+ public CellTermAttributeImpl clone() {
+ final CellTermAttributeImpl clone = (CellTermAttributeImpl) super.clone();
+ clone.bytes = BytesRef.deepCopyOf(bytes);
+ return clone;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((cell == null) ? 0 : cell.hashCode());
+ result = prime * result + Boolean.hashCode(omitLeafByte);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ CellTermAttributeImpl other = (CellTermAttributeImpl) obj;
+ if (cell == null) {
+ if (other.cell != null) return false;
+ } else if (!cell.equals(other.cell)) return false;
+ if (omitLeafByte != other.omitLeafByte) return false;
+ return true;
+ }
}
public CellTokenStream() {