Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2015 www.seleniumtests.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * 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.
 */

public class Main {
    /**
     * Checks if both the Object arguments are equal (including if they are null)
     */

    public static boolean areNullorEqual(Object obj1, Object obj2, boolean ignoreWhitespace, boolean ignoreCase)

    {

        // if both are null, they are equal

        if ((obj1 == null) && (obj2 == null))

            return true;

        // if either one of them is null, they are not equal

        if ((obj1 == null) || (obj2 == null))

            return false;

        // if they are String type

        if ((obj1 instanceof String) && (obj2 instanceof String))

        {

            if (ignoreWhitespace)

            {

                if (ignoreCase)

                    return ((String) obj1).trim().equalsIgnoreCase(((String) obj2).trim());

                else

                    return ((String) obj1).trim().equals(((String) obj2).trim());

            } else

            {

                if (ignoreCase)

                    return ((String) obj1).equalsIgnoreCase((String) obj2);

                else

                    return obj1.equals(obj2);

            }

        }

        return (obj1.equals(obj2));

    }
}