Here you can find the source of equals(BSONObject a, BSONObject b)
static boolean equals(BSONObject a, BSONObject b)
//package com.java2s; /**//w ww . j ava 2 s .c om * Copyright (c) 2012, Thilo Planz. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the Apache License, Version 2.0 * as published by the Apache Software Foundation (the "License"). * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * * You should have received a copy of the License along with this program. * If not, see <http://www.apache.org/licenses/LICENSE-2.0>. */ import java.util.Arrays; import org.bson.BSON; import org.bson.BSONObject; public class Main { /** * BSON objects are considered equal when their binary encoding matches */ static boolean equals(BSONObject a, BSONObject b) { return a.keySet().equals(b.keySet()) && Arrays.equals(BSON.encode(a), BSON.encode(b)); } static boolean equals(Object a, Object b) { if (a == b) return true; if (a == null || b == null) return false; if (a instanceof BSONObject) if (b instanceof BSONObject) return equals((BSONObject) a, (BSONObject) b); else return false; if (a instanceof byte[]) { if (b instanceof byte[]) return Arrays.equals((byte[]) a, (byte[]) b); else return false; } return a.equals(b); } }