1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
14 * @Author Toni Kalajainen
16 package org.simantics.utils;
18 import java.util.Collection;
19 import java.util.Iterator;
22 * Basic utilities for any objects.
24 public class ObjectUtils {
27 * Compares two object for equality.
29 * Some times it is annoying to compare two objects if their value may be
34 * @return true if equal or both null
36 public static boolean objectEquals(Object o1, Object o2) {
39 if (o1 == null && o2 == null)
41 if (o1 == null || o2 == null)
46 public static int hashCode(Object obj) {
47 return (obj == null ? 0 : obj.hashCode());
50 public static boolean equals(Collection<?> c1, Collection<?> c2) {
51 if (c1.size() != c2.size())
53 Iterator<?> i1 = c1.iterator();
54 Iterator<?> i2 = c2.iterator();
55 while (i1.hasNext()) {
56 if (!ObjectUtils.objectEquals(i1.next(), i2.next()))