private void doComparisonsOnRaw(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) throws IOException { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); ByteArrayOutputStream baosA = new ByteArrayOutputStream(); ByteArrayOutputStream baosB = new ByteArrayOutputStream(); a.write(new DataOutputStream(baosA)); b.write(new DataOutputStream(baosB)); assertEquals( "Comparing " + a + " and " + b + " as raw", signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(), baosB.toByteArray(), 0, baosB.size())), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as raw (inverse)", -signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(), baosA.toByteArray(), 0, baosA.size())), expectedSignum); }
private void doComparisonsOnObjects(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); assertEquals( "Comparing " + a + " and " + b + " as objects", signum(comparator.compare(a, b)), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as objects (inverse)", -signum(comparator.compare(b, a)), expectedSignum); }
public void testHash() throws Exception { assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabcd"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertNotSame( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 2).hashCode()); }
private void doComparisonsOnRaw(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) throws IOException { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); ByteArrayOutputStream baosA = new ByteArrayOutputStream(); ByteArrayOutputStream baosB = new ByteArrayOutputStream(); a.write(new DataOutputStream(baosA)); b.write(new DataOutputStream(baosB)); assertEquals( "Comparing " + a + " and " + b + " as raw", signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(), baosB.toByteArray(), 0, baosB.size())), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as raw (inverse)", -signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(), baosA.toByteArray(), 0, baosA.size())), expectedSignum); }
private void doComparisonsOnObjects(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); assertEquals( "Comparing " + a + " and " + b + " as objects", signum(comparator.compare(a, b)), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as objects (inverse)", -signum(comparator.compare(b, a)), expectedSignum); }
public void testHash() throws Exception { assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabcd"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertNotSame( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 2).hashCode()); }