@Override public boolean equals(Object obj) { if (obj instanceof Currency) { Currency other = (Currency) obj; byte[] bytes = this.bytes(); byte[] otherBytes = other.bytes(); if (type == Type.ISO && other.type == Type.ISO) { return (bytes[12] == otherBytes[12] && bytes[13] == otherBytes[13] && bytes[14] == otherBytes[14]); } } return super.equals(obj); // Full comparison }
@Override public String toString() { switch (type) { case ISO: String code = getCurrencyCodeFromTLCBytes(bytes()); if (code.equals("XRP")) { // HEX of the bytes return super.toString(); } else if (code.equals("\0\0\0")) { return "XRP"; } else { // the 3 letter isoCode return code; } case HASH: case DEMURRAGE: case UNKNOWN: default: return super.toString(); } }
@Override public void toBytesSink(BytesSink buffer) { int n = 0; for (Path path : this) { if (n++ != 0) { buffer.add(PATH_SEPARATOR_BYTE); } for (Hop hop : path) { int type = hop.getType(); buffer.add((byte) type); if (hop.hasAccount()) { buffer.add(hop.account.bytes()); } if (hop.hasCurrency()) { buffer.add(hop.currency.bytes()); } if (hop.hasIssuer()) { buffer.add(hop.issuer.bytes()); } } } buffer.add(PATHSET_END_BYTE); }
@Override public void toBytesSink(BytesSink to) { UInt64 man = mantissa(); if (isNative()) { if (!isNegative()) { man = man.or(BINARY_FLAG_IS_NON_NEGATIVE_NATIVE); } to.add(man.toByteArray()); } else { int exponent = exponent(); UInt64 packed; if (isZero()) { packed = BINARY_FLAG_IS_IOU; } else if (isNegative()) { packed = man.or(new UInt64(512 + 0 + 97 + exponent).shiftLeft(64 - 10)); } else { packed = man.or(new UInt64(512 + 256 + 97 + exponent).shiftLeft(64 - 10)); } to.add(packed.toByteArray()); to.add(currency.bytes()); to.add(issuer.bytes()); } }