ObjectUtil.java

49 lines | 1.36 kB Blame History Raw Download
/*
 * Copyright 2016 Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags.
 *
 * 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.
 */

package org.keycloak.common.util;

/**
 * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
 */
public class ObjectUtil {

    private ObjectUtil() {}

    /**
     *
     * @param str1
     * @param str2
     * @return true if both strings are null or equal
     */
    public static boolean isEqualOrBothNull(Object str1, Object str2) {
        if (str1 == null && str2 == null) {
            return true;
        }

        if ((str1 != null && str2 == null) || (str1 == null && str2 != null)) {
            return false;
        }

        return str1.equals(str2);
    }

    public static String capitalize(String str) {
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }
}