@Override public Void visit(BsonObjectId value, ByteBuf arg) { arg.writeBytes(value.toByteArray()); return null; }
@Override public final int hashCode() { return getId().hashCode(); }
private static ObjectId translateObjectId(com.eightkdata.mongowp.bson.BsonObjectId id) { return new ObjectId(id.toHexString()); }
@Override public Void visit(BsonDbPointer value, ByteBuf arg) { writeString(arg, value.getNamespace()); value.getId().accept(this, arg); return null; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof BsonDbPointer)) { return false; } BsonDbPointer other = (BsonDbPointer) obj; if (!Objects.equals(this.getNamespace(), other.getNamespace())) { return false; } return this.getId().equals(other.getId()); }
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return diff; } if (obj.isObjectId()) { return 1; } assert obj instanceof BsonDbPointer; BsonDbPointer other = (BsonDbPointer) obj; // TODO: Check how MongoDB compares pointers! diff = this.getNamespace().compareTo(other.getNamespace()); if (diff != 0) { return diff; } return this.getId().compareTo(other.getId()); }
@Override public KVValue visit(BsonObjectId value, Void arg) { return new ByteArrayKVMongoObjectId(value.toByteArray()); }
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return diff; } if (obj.isDbPointer()) { return -1; } assert obj instanceof BsonObjectId; BsonObjectId other = obj.asObjectId(); byte[] otherBytes; if (obj instanceof AbstractBsonObjectId) { otherBytes = ((AbstractBsonObjectId) obj).getBytesUnsafe(); } else { otherBytes = other.toByteArray(); } byte[] thisBytes = getBytesUnsafe(); for (int i = 0; i < 12; i++) { diff = (thisBytes[i] & 0xFF) - (otherBytes[i] & 0xFF); if (diff != 0) { return diff; } } return 0; }