StructuralKey { public static <K> StructuralKey<K> of(K key, Coder<K> coder) { try { return new CoderStructuralKey<>(coder, key); } catch (Exception e) { throw new IllegalArgumentException( "Could not encode a key with its provided coder " + coder.getClass().getSimpleName(), e); } } private  StructuralKey(); abstract K getKey(); static StructuralKey<?> empty(); static StructuralKey<K> of(K key, Coder<K> coder);  }
@Test public void objectEqualsTrueKeyEquals() { StructuralKey<Integer> original = StructuralKey.of(1234, VarIntCoder.of()); Assert.assertThat(StructuralKey.of(1234, VarIntCoder.of()), Matchers.equalTo(original)); }
@Test public void objectsNotEqualEncodingsEqualEquals() { byte[] original = new byte[] {1, 4, 9, 127, -22}; StructuralKey<byte[]> key = StructuralKey.of(original, ByteArrayCoder.of()); StructuralKey<byte[]> otherKey = StructuralKey.of(new byte[] {1, 4, 9, 127, -22}, ByteArrayCoder.of()); Assert.assertThat(key, Matchers.equalTo(otherKey)); }
@Test public void notEqualEncodingsEqual() { byte[] original = new byte[] {1, 4, 9, 127, -22}; StructuralKey<byte[]> key = StructuralKey.of(original, ByteArrayCoder.of()); StructuralKey<byte[]> otherKey = StructuralKey.of(new byte[] {9, -128, 22}, ByteArrayCoder.of()); Assert.assertThat(key, Matchers.not(Matchers.equalTo(otherKey))); }