From 284dcc0eae00594a167805d6bb694b009d045ada Mon Sep 17 00:00:00 2001 From: prepor Date: Mon, 2 Mar 2020 14:59:06 +0100 Subject: [PATCH] extend CanonicalByteArray support for numbers java.mathBigDecimal, java.mathBigInteger, clojure.lang.BigInt --- src/valuehash/impl.clj | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/valuehash/impl.clj b/src/valuehash/impl.clj index 42e4888..ed839b5 100644 --- a/src/valuehash/impl.clj +++ b/src/valuehash/impl.clj @@ -1,6 +1,7 @@ (ns valuehash.impl "Simple implementation based on plain byte arrays" - (:import [java.util UUID Date])) + (:import [java.util UUID Date] + [java.math BigDecimal BigInteger])) (defprotocol CanonicalByteArray "An object that can be converted to a canonical byte array, with value @@ -64,6 +65,12 @@ (to-byte-array [this] (long->bytes (Double/doubleToLongBits this))) clojure.lang.Ratio (to-byte-array [this] (long->bytes (Double/doubleToLongBits (double this)))) + clojure.lang.BigInt + (to-byte-array [this] (long->bytes (Double/doubleToLongBits (double this)))) + BigInteger + (to-byte-array [this] (long->bytes (Double/doubleToLongBits (double this)))) + BigDecimal + (to-byte-array [this] (long->bytes (Double/doubleToLongBits (double this)))) Boolean (to-byte-array [this] (byte-array 1 (if this (byte 1) (byte 0)))) Character