com.ebay.jetstream.util.CommonUtils Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright © 2012-2015 eBay Software Foundation
* This program is dual licensed under the MIT and Apache 2.0 licenses.
* Please see LICENSE for more information.
*******************************************************************************/
package com.ebay.jetstream.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Map;
import java.util.Map.Entry;
/**
* @author jvembunarayanan
*/
public class CommonUtils {
public static > T findEnumIgnoreCase(Class enumClass, String string, T defValue) {
for (T value : EnumSet.allOf(enumClass))
if (value.toString().equalsIgnoreCase(string))
return value;
return defValue;
}
public static Class> getCallingClass(int callerIndex) {
try {
return Class.forName(new Throwable().getStackTrace()[callerIndex + 1].getClassName());
}
catch (ClassNotFoundException e) {
throw runtimeException(e);
}
}
@SuppressWarnings( { "unchecked", "cast" })
public static T getDeepCopy(T object) throws InstantiationException, IllegalAccessException {
T newObject = object;
if (object instanceof Map) {
newObject = (T) object.getClass().newInstance();
for (Entry