Java Object Equal equals(BSONObject a, BSONObject b)

Here you can find the source of equals(BSONObject a, BSONObject b)

Description

BSON objects are considered equal when their binary encoding matches

License

Open Source License

Declaration

static boolean equals(BSONObject a, BSONObject b) 

Method Source Code

//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);
    }
}

Related

  1. areEqual(Object o1, Object o2)
  2. areEqual(Object o1, Object o2)
  3. areEqualStr(Object o1, Object o2)
  4. deepEquals(Object o1, Object o2)
  5. equalObjects(Object object1, Object object2)
  6. equals(final Object a, final Object b)
  7. equals(Object a, Object b)
  8. Equals(Object in1, Object in2)
  9. equals(Object o1, Object o2)