Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009-2012 Alexander Kerner. All rights reserved. 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 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 net.sf.kerner.utils;
General utility class.

Alexander Kerner
 public class Utils {

java.util.Locale of current user, e.g. "de", "en" or "fr".
 	public static final Locale USER_LOCALE = new Locale(System.getProperty("user.language"));

The working directory is the location in the file system from where the java command was invoked.
 	public static final File WORKING_DIR = new File(System.getProperty("user.dir"));

Number of CPUs that are available to this JVM.
 	public static final int NUM_CPUS = Runtime.getRuntime().availableProcessors();
 	private Utils() {

Simple helper method, that checks whether any of given objects is null.

objects array of Objects that are checked
java.lang.NullPointerException if any of given objects is null
 	public static void checkForNull(Object... objects) {
 		for (Object o : objects) {
 			if (o == null)
 				throw new NullPointerException();

Calculates hashCode of all elements in collection recursively, calling on every object java.lang.Object.hashCode() and add this to result.

objects Objects from which hashCode is calculated
deep hashCode for given java.util.Collection of objects
 	public static int deepHashCode(Collection<?> objects) {
 		int result = 0;
 		for (Object o : objects) {
 			if (o instanceof Collection)
 				result += deepHashCode((Collection<?>) o);
 			else if (ArrayUtils.isArray(o))
 				result += deepHashCode(Arrays.asList((Object[]) o));
 				result += o.hashCode();
 		return result;

Check, weather one Object equals another by delegating to java.lang.Object.hashCode(). If one of both Objects is null, false is returned. If both Objects arenull, true is returned.

o1 first Object
o2 second Object
true, if both objects have same hashCode; false otherwise
	public static boolean equalsOnHashCode(Object o1Object o2) {
		if (o1 == null && o2 == null) {
			return true;
		if (o2 == null || o1 == null) {
			return false;
		return o1.hashCode() == o2.hashCode();
New to GrepCode? Check out our FAQ X