components/visual-panels/core/src/java/util/com/oracle/solaris/vp/util/misc/ObjectUtil.java
changeset 3553 f1d133b09a8c
parent 3552 077ebe3d0d24
child 3554 ef58713bafc4
equal deleted inserted replaced
3552:077ebe3d0d24 3553:f1d133b09a8c
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.util.misc;
       
    27 
       
    28 import java.util.Arrays;
       
    29 
       
    30 public class ObjectUtil {
       
    31     public static <T> int compare(Comparable<T> o1, T o2) {
       
    32 	if (o1 == null) {
       
    33 	    return o2 == null ? 0 : -1;
       
    34 	}
       
    35 
       
    36 	if (o2 == null) {
       
    37 	    return 1;
       
    38 	}
       
    39 
       
    40 	return o1.compareTo(o2);
       
    41     }
       
    42 
       
    43     public static boolean equals(Object o1, Object o2) {
       
    44 	if (o1 == null) {
       
    45 	    return o2 == null;
       
    46 	}
       
    47 
       
    48 	if (o2 != null && o1.getClass().isArray() && o2.getClass().isArray()) {
       
    49 	    try {
       
    50 		return Arrays.deepEquals((Object[])o1, (Object[])o2);
       
    51 	    } catch (ClassCastException ignore) {
       
    52 	    }
       
    53 
       
    54 	    try {
       
    55 		return Arrays.equals((boolean[])o1, (boolean[])o2);
       
    56 	    } catch (ClassCastException ignore) {
       
    57 	    }
       
    58 
       
    59 	    try {
       
    60 		return Arrays.equals((byte[])o1, (byte[])o2);
       
    61 	    } catch (ClassCastException ignore) {
       
    62 	    }
       
    63 
       
    64 	    try {
       
    65 		return Arrays.equals((char[])o1, (char[])o2);
       
    66 	    } catch (ClassCastException ignore) {
       
    67 	    }
       
    68 
       
    69 	    try {
       
    70 		return Arrays.equals((double[])o1, (double[])o2);
       
    71 	    } catch (ClassCastException ignore) {
       
    72 	    }
       
    73 
       
    74 	    try {
       
    75 		return Arrays.equals((float[])o1, (float[])o2);
       
    76 	    } catch (ClassCastException ignore) {
       
    77 	    }
       
    78 
       
    79 	    try {
       
    80 		return Arrays.equals((int[])o1, (int[])o2);
       
    81 	    } catch (ClassCastException ignore) {
       
    82 	    }
       
    83 
       
    84 	    try {
       
    85 		return Arrays.equals((long[])o1, (long[])o2);
       
    86 	    } catch (ClassCastException ignore) {
       
    87 	    }
       
    88 
       
    89 	    try {
       
    90 		return Arrays.equals((short[])o1, (short[])o2);
       
    91 	    } catch (ClassCastException ignore) {
       
    92 	    }
       
    93 	}
       
    94 
       
    95 	return o1.equals(o2);
       
    96     }
       
    97 }