lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1650738 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/analysis/ lucene/core/src/test/org/apache/lucene/analysis/ lucene/spatial/ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/
Date Sat, 10 Jan 2015 13:09:52 GMT
Author: uschindler
Date: Sat Jan 10 13:09:51 2015
New Revision: 1650738

URL: http://svn.apache.org/r1650738
Log:
Merged revision(s) 1650737 from lucene/dev/trunk:
LUCENE-6173: Fix deep clone

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
    lucene/dev/branches/branch_5x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1650738&r1=1650737&r2=1650738&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Sat Jan 10 13:09:51 2015
@@ -415,6 +415,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/branches/branch_5x/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java?rev=1650738&r1=1650737&r2=1650738&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/analysis/NumericTokenStream.java
Sat Jan 10 13:09:51 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/branches/branch_5x/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java?rev=1650738&r1=1650737&r2=1650738&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/analysis/TestNumericTokenStream.java
Sat Jan 10 13:09:51 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/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java?rev=1650738&r1=1650737&r2=1650738&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/CellTokenStream.java
Sat Jan 10 13:09:51 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() {



Mime
View raw message