List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:Main.java
private static Object[] bindParameters(Method method, String[] args) { List<Object> parameters = new ArrayList<Object>(); Class<?>[] parameterTypes = method.getParameterTypes(); for (int i = 0, len = parameterTypes.length; i < len; i++) { Class<?> type = parameterTypes[i]; int remaining = Math.max(0, args.length - i); if (type.equals(String[].class)) { String[] rest = new String[remaining]; System.arraycopy(args, 1, rest, 0, remaining); parameters.add(rest);/* w ww.j av a 2 s. c o m*/ } else if (remaining > 0) { parameters.add(convertParameter(args[i], parameterTypes[i])); } else { parameters.add(null); } } return parameters.toArray(); }
From source file:fr.mby.utils.spring.aop.support.AopHelper.java
/** * Test if an object which implement or extend a parameterized object will be able to handle a specific type. * Example : NumberList implements List<Number> { ... } NumberList can store any subtypes of Number : Number, * Integer, Long, ... This method return true if called like this supportsType(numberList, Integer.class, * List.class) This method return false if called like this supportsType(numberList, String.class, List.class) * // ww w. j ava2 s. c om * @param object * the instantiated object we want to test against * @param type * the type we want to test if the object can hanldle * @param genericIfc * the type of the parameterized object (not the parameter type) * @return true if the object implementing the genericIfc supports the specified type */ public static <T> boolean supportsType(final Object object, final Class<?> type, final Class<?> genericIfc) { Class<?> typeArg = GenericTypeResolver.resolveTypeArgument(object.getClass(), genericIfc); if (typeArg == null || typeArg.equals(genericIfc)) { final Class<?> targetClass = AopUtils.getTargetClass(object); if (targetClass != object.getClass()) { typeArg = GenericTypeResolver.resolveTypeArgument(targetClass, genericIfc); } } final boolean test = typeArg == null || typeArg.isAssignableFrom(type); final String logMsg; if (test) { logMsg = "[{}] supports type: [{}] for genericIfc [{}]."; } else { logMsg = "[{}] doesn't support type: [{}] for genericIfc [{}]."; } AopHelper.LOG.debug(logMsg, object.getClass().getSimpleName(), type.getSimpleName(), genericIfc.getSimpleName()); return test; }
From source file:Main.java
private static boolean isTypeMatch(Class<?> one, Class<?> two) { if (one.equals(two)) { return true; }// w w w .jav a2s .co m if (one.isPrimitive()) { if (one.getName().equals("int") && two.getName().equals("java.lang.Integer")) { return true; } if (one.getName().equals("long") && two.getName().equals("java.lang.Long")) { return true; } if (one.getName().equals("float") && two.getName().equals("java.lang.Float")) { return true; } if (one.getName().equals("double") && two.getName().equals("java.lang.Double")) { return true; } if (one.getName().equals("char") && two.getName().equals("java.lang.Character")) { return true; } if (one.getName().equals("byte") && two.getName().equals("java.lang.Byte")) { return true; } if (one.getName().equals("short") && two.getName().equals("java.lang.Short")) { return true; } if (one.getName().equals("boolean") && two.getName().equals("java.lang.Boolean")) { return true; } } return false; }
From source file:com.netflix.hystrix.contrib.javanica.utils.AopUtils.java
public static <T extends Annotation> Optional<T> getAnnotation(Class<?> type, Class<T> annotation) { Validate.notNull(annotation, "annotation cannot be null"); Validate.notNull(type, "type cannot be null"); for (Annotation ann : type.getDeclaredAnnotations()) { if (ann.annotationType().equals(annotation)) return Optional.of((T) ann); }// w w w.ja v a2 s . c o m Class<?> superType = type.getSuperclass(); if (superType != null && !superType.equals(Object.class)) { return getAnnotation(superType, annotation); } return Optional.absent(); }
From source file:it.greenvulcano.util.ArrayUtils.java
public static final List<?> arrayToList(Object arr) { List<?> list = null;/*from w w w. j ava2 s . c om*/ Class<?> ac = arr.getClass(); if (!ac.isArray()) { throw new IllegalArgumentException("The input parameter isn't an array"); } Class<?> act = ac.getComponentType(); if (act.isPrimitive()) { if (act.equals(boolean.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((boolean[]) arr)); } else if (act.equals(byte.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((byte[]) arr)); } else if (act.equals(char.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((char[]) arr)); } else if (act.equals(short.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((short[]) arr)); } else if (act.equals(int.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((int[]) arr)); } else if (act.equals(long.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((long[]) arr)); } else if (act.equals(float.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((float[]) arr)); } else if (act.equals(double.class)) { list = Arrays.asList(org.apache.commons.lang3.ArrayUtils.toObject((double[]) arr)); } } else { list = arrayToList((Object[]) arr); } return list; }
From source file:Main.java
/** * Checks is the given method from java.lang.Object * @param method - method to check/*from w w w.j a v a2 s . c o m*/ * @return true if method from java.lang.Object */ public static boolean isJavaLangObjectMethod(Method method) { Method methods[] = Object.class.getDeclaredMethods(); for (Method objMethod : methods) { if (objMethod.getName().equals(method.getName())) { Class<?> methodParameterTypes[] = method.getParameterTypes(); Class<?> objectMethodParameterTypes[] = objMethod.getParameterTypes(); if (objectMethodParameterTypes.length == methodParameterTypes.length) { boolean matched = true; for (int i = 0; i < methodParameterTypes.length; i++) { Class<?> class1 = methodParameterTypes[i]; Class<?> class2 = objectMethodParameterTypes[i]; if (!class1.equals(class2)) { matched = false; break; } } if (matched) { return true; } } } } return false; }
From source file:com.facebook.stetho.inspector.MethodDispatcher.java
/** * Determines if the method is a {@link ChromeDevtoolsMethod}, and validates accordingly * if it is./* w ww . ja v a 2 s.co m*/ * * @throws IllegalArgumentException Thrown if it is a {@link ChromeDevtoolsMethod} but * it otherwise fails to satisfy requirements. */ private static boolean isDevtoolsMethod(Method method) throws IllegalArgumentException { if (!method.isAnnotationPresent(ChromeDevtoolsMethod.class)) { return false; } else { Class<?> args[] = method.getParameterTypes(); String methodName = method.getDeclaringClass().getSimpleName() + "." + method.getName(); Util.throwIfNot(args.length == 2, "%s: expected 2 args, got %s", methodName, args.length); Util.throwIfNot(args[0].equals(JsonRpcPeer.class), "%s: expected 1st arg of JsonRpcPeer, got %s", methodName, args[0].getName()); Util.throwIfNot(args[1].equals(JSONObject.class), "%s: expected 2nd arg of JSONObject, got %s", methodName, args[1].getName()); Class<?> returnType = method.getReturnType(); if (!returnType.equals(void.class)) { Util.throwIfNot(JsonRpcResult.class.isAssignableFrom(returnType), "%s: expected JsonRpcResult return type, got %s", methodName, returnType.getName()); } return true; } }
From source file:eu.leads.processor.planner.ClassUtil.java
private static boolean isMatch(Class targetClass, Class loadedClass) { if (targetClass.equals(loadedClass)) { return true; }/*from w w w. j av a2 s . c o m*/ Class[] classInterfaces = loadedClass.getInterfaces(); if (classInterfaces != null) { for (Class eachInterfaceClass : classInterfaces) { if (eachInterfaceClass.equals(targetClass)) { return true; } if (isMatch(targetClass, eachInterfaceClass)) { return true; } } } Class superClass = loadedClass.getSuperclass(); if (superClass != null) { if (isMatch(targetClass, superClass)) { return true; } } return false; }
From source file:io.cloudslang.lang.entities.bindings.values.PyObjectValueProxyFactory.java
@SuppressWarnings("unchecked") private static Object getParamDefaultValue(PyObject pyObject, Class<?> parameterType) throws Exception { if (parameterType.equals(PyType.class)) { return pyObject.getType(); } else if (parameterType.isPrimitive()) { return ClassUtils.primitiveToWrapper(parameterType).getConstructor(String.class).newInstance("0"); } else if (Number.class.isAssignableFrom(parameterType) || String.class.isAssignableFrom(parameterType)) { return parameterType.getConstructor(String.class).newInstance("0"); } else {//from www.j ava2s . c om return null; } }
From source file:com.avanza.ymer.TestSpaceObjectFakeConverter.java
static DocumentConverter create() { return DocumentConverter.create(new DocumentConverter.Provider() { @Override/* w ww. java 2 s .c o m*/ public BasicDBObject convertToDBObject(Object type) { if (type instanceof TestSpaceObject) { TestSpaceObject testSpaceObject = (TestSpaceObject) type; BasicDBObject dbObject = new BasicDBObject(); dbObject.put("_id", testSpaceObject.getId()); if (testSpaceObject.getMessage() != null) { dbObject.put("message", testSpaceObject.getMessage()); } return dbObject; } else if (type instanceof TestSpaceOtherObject) { TestSpaceOtherObject testSpaceOtherObject = (TestSpaceOtherObject) type; BasicDBObject dbObject = new BasicDBObject(); dbObject.put("_id", testSpaceOtherObject.getId()); if (testSpaceOtherObject.getMessage() != null) { dbObject.put("message", testSpaceOtherObject.getMessage()); } return dbObject; } else if (type instanceof TestReloadableSpaceObject) { TestReloadableSpaceObject testSpaceObject = (TestReloadableSpaceObject) type; BasicDBObject dbObject = new BasicDBObject(); dbObject.put("_id", testSpaceObject.getId()); dbObject.put("patched", testSpaceObject.isPatched()); dbObject.put("versionID", testSpaceObject.getVersionID()); if (testSpaceObject.getLatestRestoreVersion() != null) { dbObject.put("latestRestoreVersion", testSpaceObject.getLatestRestoreVersion()); } return dbObject; } else { throw new RuntimeException("Unknown object type: " + type.getClass()); } } @Override public <T> T convert(Class<T> toType, BasicDBObject document) { if (toType.equals(TestSpaceObject.class)) { TestSpaceObject testSpaceObject = new TestSpaceObject(); testSpaceObject.setId(document.getString("_id")); testSpaceObject.setMessage(document.getString("message")); return toType.cast(testSpaceObject); } else if (toType.equals(TestReloadableSpaceObject.class)) { TestReloadableSpaceObject testSpaceObject = new TestReloadableSpaceObject(); testSpaceObject.setId(document.getInt("_id")); if (document.containsField("patched")) { testSpaceObject.setPatched(document.getBoolean("patched")); } testSpaceObject.setVersionID(document.getInt("versionID")); if (document.containsField("latestRestoreVersion")) { testSpaceObject.setLatestRestoreVersion(document.getInt("latestRestoreVersion")); } return toType.cast(testSpaceObject); } else { throw new RuntimeException("Unknown object type: " + toType); } } @Override public Object convert(Object type) { if (type instanceof Number) { return type; } return type.toString(); } @Override public Query toQuery(Object template) { throw new UnsupportedOperationException(); } }); }