001: /*
002: * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.binding;
032:
033: /**
034: * Consists exclusively of static methods that provide
035: * convenience behavior used by the Binding classes.
036: *
037: * @author Karsten Lentzsch
038: * @version $Revision: 1.5 $
039: */
040: public final class BindingUtils {
041:
042: private BindingUtils() {
043: // Override default constructor; prevents instantiation.
044: }
045:
046: /**
047: * Checks and answers if the two objects are
048: * both <code>null</code> or equal.
049: *
050: * <pre>
051: * #equals(null, null) == true
052: * #equals("Hi", "Hi") == true
053: * #equals("Hi", null) == false
054: * #equals(null, "Hi") == false
055: * #equals("Hi", "Ho") == false
056: * </pre>
057: *
058: * @param o1 the first object to compare
059: * @param o2 the second object to compare
060: * @return boolean <code>true</code> if and only if
061: * both objects are <code>null</code> or equal
062: */
063: public static boolean equals(Object o1, Object o2) {
064: return ((o1 != null) && (o2 != null) && (o1.equals(o2)))
065: || ((o1 == null) && (o2 == null));
066: }
067:
068: /**
069: * Checks and answers if the given string is whitespace,
070: * empty (<code>""</code>) or <code>null</code>.
071: *
072: * <pre>
073: * #isBlank(null) == true
074: * #isBlank("") == true
075: * #isBlank(" ") == true
076: * #isBlank("Hi ") == false
077: * </pre>
078: *
079: * @param str the string to check, may be <code>null</code>
080: * @return <code>true</code> if the string is whitespace, empty
081: * or <code>null</code>
082: * @see #isEmpty(String)
083: */
084: public static boolean isBlank(String str) {
085: return str == null || str.trim().length() == 0;
086: }
087:
088: /**
089: * Checks and answers if the given string is empty (<code>""</code>)
090: * or <code>null</code>.<p>
091: *
092: * <pre>
093: * #isEmpty(null) == true
094: * #isEmpty("") == true
095: * #isEmpty(" ") == false
096: * #isEmpty("Hi ") == false
097: * </pre>
098: *
099: * @param str the string to check, may be <code>null</code>
100: * @return <code>true</code> if the string is empty or <code>null</code>
101: * @see #isBlank(String)
102: */
103: public static boolean isEmpty(String str) {
104: return str == null || str.length() == 0;
105: }
106:
107: }
|