@Override public Object clone() { return new IntPairWritable(this); }
@Test public void testGetSet() { IntPairWritable n = new IntPairWritable(); assertEquals(0, n.getFirst()); assertEquals(0, n.getSecond()); n.setFirst(5); n.setSecond(10); assertEquals(5, n.getFirst()); assertEquals(10, n.getSecond()); n = new IntPairWritable(2,4); assertEquals(2, n.getFirst()); assertEquals(4, n.getSecond()); }
@Test public void testWritable() throws Exception { IntPairWritable one = new IntPairWritable(1,2); IntPairWritable two = new IntPairWritable(3,4); assertEquals(1, one.getFirst()); assertEquals(2, one.getSecond()); assertEquals(3, two.getFirst()); assertEquals(4, two.getSecond()); ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(bout); two.write(out); byte[] b = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(b); DataInput din = new DataInputStream(bin); one.readFields(din); assertEquals(two.getFirst(), one.getFirst()); assertEquals(two.getSecond(), one.getSecond()); }
public int getFirst() { return getInt(b, 0); }
@Override public boolean equals(Object right) { if (!(right instanceof Frequency)) { return false; } Frequency that = (Frequency) right; return pair.equals(that.pair) && frequency == that.frequency; }
@Override public int hashCode() { return pair.hashCode() + RandomUtils.hashDouble(frequency); }
public IntPairWritable(IntPairWritable pair) { b = Arrays.copyOf(pair.getBytes(), INT_PAIR_BYTE_LENGTH); }
public void setFirst(int x) { putInt(x, b, 0); }
public int getFirst() { return getInt(b, 0); }
@Override public boolean equals(Object right) { if (!(right instanceof Frequency)) { return false; } Frequency that = (Frequency) right; return pair.equals(that.pair) && frequency == that.frequency; }
@Override public int hashCode() { return pair.hashCode() + RandomUtils.hashDouble(frequency); }
public IntPairWritable(IntPairWritable pair) { b = Arrays.copyOf(pair.getBytes(), INT_PAIR_BYTE_LENGTH); }
@Override public Object clone() { return new IntPairWritable(this); }