Hash implements Adaptor, Encodable { @SuppressWarnings("unchecked") @Override public <T> T adapt(Class<T> adaptor) { if (adaptor.isAssignableFrom(Hash.class)) { return (T) this; } else if (adaptor.isAssignableFrom(BlockHash.class)) { return (T) BlockHash.of(getBytesValue()); } else if (adaptor.isAssignableFrom(TxHash.class)) { return (T) TxHash.of(getBytesValue()); } else if (adaptor.isAssignableFrom(ContractTxHash.class)) { return (T) ContractTxHash.of(getBytesValue()); } return null; } Hash(final String encoded);  Hash(final BytesValue bytesValue); static Hash of(final String encoded); static Hash of(final BytesValue bytesValue); @Override String getEncoded(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @SuppressWarnings("unchecked") @Override T adapt(Class<T> adaptor); static final Hash EMPTY; }
@Test public void testAdapt() { final Hash hash = Hash.of(encodedHash); assertEquals(Hash.of(encodedHash), hash.adapt(Hash.class)); assertEquals(BlockHash.of(encodedHash), hash.adapt(BlockHash.class)); assertEquals(TxHash.of(encodedHash), hash.adapt(TxHash.class)); assertEquals(ContractTxHash.of(encodedHash), hash.adapt(ContractTxHash.class)); }