001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.common.util; 017 018/** 019 * Common utility methods for general objects. 020 */ 021public class ObjectUtil { 022 023 public static <Type> boolean isEqualNoNulls( Type reference1, 024 Type reference2 ) { 025 return reference1.equals(reference2); 026 } 027 028 public static <Type> boolean isEqualWithNulls( Type reference1, 029 Type reference2 ) { 030 return reference1 == null ? reference2 == null : reference1.equals(reference2); 031 } 032 033 @SuppressWarnings( {"unchecked", "rawtypes"} ) 034 public static int compareNoNulls( Comparable reference1, 035 Comparable reference2 ) { 036 return reference1.compareTo(reference2); 037 } 038 039 @SuppressWarnings( {"unchecked", "rawtypes"} ) 040 public static int compareWithNulls( Comparable reference1, 041 Comparable reference2 ) { 042 if (reference1 == null) return reference2 == null ? 0 : 1; 043 if (reference2 == null) return 1; 044 return reference1.compareTo(reference2); 045 } 046 047 private ObjectUtil() { 048 } 049}