@Override public ScalarValue<?> visit(KVBinary value, Void arg) { return new ByteSourceScalarBinary(value.getSubtype(), value.getCategory(), value.getByteSource()); }
@Override public String toString() { return "KVBinary[subtype= " + getSubtype() + "(" + getCategory() + "), size= " + size() +"]"; }
/** * Two KVBinary are equal if their subtypes are the same and * their contain the same bytes. * * @param obj * @return */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null) { return false; } if (!(obj instanceof KVBinary)) { return false; } KVBinary other = (KVBinary) obj; if (this.getSubtype() != other.getSubtype()) { return false; } return this.getByteSource().contentEquals(other.getByteSource()); }
@Override public int hashCode() { return Hashing.goodFastHash(32) .newHasher() .putInt(getSubtype().hashCode()) .putLong(size()) .hash() .asInt(); }
public long size() { return getByteSource().size(); }
@Override public BsonBinary visit(KVBinary value, Void arg) { BinarySubtype subtype; switch (value.getSubtype()) { case MONGO_FUNCTION: subtype = BinarySubtype.FUNCTION; default: throw new AssertionError("It is not defined how to translate " + "the binary subtype " + value.getSubtype() + " to" + "MongoDB binaries subtypes"); byte byteType = value.getCategory(); return new ByteArrayBsonBinary(subtype, byteType, value.getByteSource().read());