Java List Null Empty isNullOrEmptyAwareEqual(final List targetOne, final List targetTwo)

Here you can find the source of isNullOrEmptyAwareEqual(final List targetOne, final List targetTwo)

Description

Check if either both objects are null or List#isEmpty() empty .

License

Open Source License

Parameter

Parameter Description
targetOne one list to check for equality
targetTwo other list to check for equality

Return

if both are null / empty or equal to each other

Declaration

public static boolean isNullOrEmptyAwareEqual(final List<?> targetOne, final List<?> targetTwo) 

Method Source Code


//package com.java2s;
/*/*w  w  w  . java2s.c om*/
   Copyright (C) 2016 HermeneutiX.org
    
   This file is part of SciToS.
    
   SciToS is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
    
   SciToS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
    
   You should have received a copy of the GNU General Public License
   along with SciToS. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.List;

public class Main {
    /**
     * Check if either both objects are {@code null} or {@link String#isEmpty() empty}. Otherwise check if one {@link String#equals(Object) equals}
     * the other.
     *
     * @param targetOne
     *            one {@code String} to check for equality
     * @param targetTwo
     *            other {@code String} to check for equality
     * @return if both are {@code null}/{@link String#isEmpty() empty} or {@link String#equals(Object) equal} to each other
     */
    public static boolean isNullOrEmptyAwareEqual(final String targetOne, final String targetTwo) {
        final boolean checkResult;
        if (targetOne == null || targetOne.isEmpty()) {
            checkResult = targetTwo == null || targetTwo.isEmpty();
        } else {
            checkResult = targetOne.equals(targetTwo);
        }
        return checkResult;
    }

    /**
     * Check if either both objects are {@code null} or {@link List#isEmpty() empty}. Otherwise check if one {@link List#equals(Object) equals} the
     * other.
     *
     * @param targetOne
     *            one list to check for equality
     * @param targetTwo
     *            other list to check for equality
     * @return if both are {@code null}/{@link List#isEmpty() empty} or {@link List#equals(Object) equal} to each other
     */
    public static boolean isNullOrEmptyAwareEqual(final List<?> targetOne, final List<?> targetTwo) {
        final boolean checkResult;
        if (targetOne == null || targetOne.isEmpty()) {
            checkResult = targetTwo == null || targetTwo.isEmpty();
        } else {
            checkResult = targetOne.equals(targetTwo);
        }
        return checkResult;
    }
}

Related

  1. isNullish(java.util.List value)
  2. isNullList(List l)
  3. isNullOrEmpty(List list)
  4. isNullOrEmpty(List list)
  5. isNullOrEmpty(List l)
  6. isNullOrEmptyList(final List list)
  7. isNullOrEmptyList(List list)
  8. isNullOrEmptyList(String message, List list)
  9. isObjectListEmpty(List list)