Here you can find the source of areEqualIgnoreNull(String value1, String value2, boolean caseSensitive)
Parameter | Description |
---|---|
value1 | The first value to compare. Is ignored if null or empty String |
value2 | The second value to be compared |
true
if both values are equal or if the first value is null
or empty string.
public static final boolean areEqualIgnoreNull(String value1, String value2, boolean caseSensitive)
//package com.java2s; /*/*from ww w.j a v a 2 s.c om*/ * * The DbUnit Database Testing Framework * Copyright (C)2005, DbUnit.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ public class Main { /** * Compares the given values and returns true if they are equal. * If the first value is <code>null</code> or empty String it always * returns <code>true</code> which is the way of ignoring <code>null</code>s * for this specific case. * @param value1 The first value to compare. Is ignored if null or empty String * @param value2 The second value to be compared * @return <code>true</code> if both values are equal or if the first value * is <code>null</code> or empty string. * @since 2.4.4 */ public static final boolean areEqualIgnoreNull(String value1, String value2, boolean caseSensitive) { if (value1 == null || value1.equals("")) { return true; } else { if (caseSensitive && value1.equals(value2)) { return true; } else if (!caseSensitive && value1.equalsIgnoreCase(value2)) { return true; } else { return false; } } } }