List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:com.sugaronrest.restapicalls.ModuleInfo.java
public static Iterable<Field> getFieldsUpTo(Class<?> type, Class<?> exclusiveParent) { List<Field> currentClassFields = new ArrayList<>(); currentClassFields.addAll(Arrays.asList(type.getDeclaredFields())); Class<?> parentClass = type.getSuperclass(); if (parentClass != null && (exclusiveParent == null || !parentClass.equals(exclusiveParent))) { List<Field> parentClassFields = (List<Field>) getFieldsUpTo(parentClass, exclusiveParent); currentClassFields.addAll(parentClassFields); }//from w w w .j a v a 2 s .c om return currentClassFields; }
From source file:com.microsoft.tfs.core.httpclient.auth.NTLMScheme.java
public static boolean supportsCredentials(final Class<?> credentialClass) { if (credentialClass == null || !isSupported()) { return false; }// www . jav a 2 s .c o m if (credentialClass.equals(DefaultNTCredentials.class)) { return NTLMEngine.getInstance().supportsCredentialsDefault(); } else if (credentialClass.equals(UsernamePasswordCredentials.class)) { return NTLMEngine.getInstance().supportsCredentialsSpecified(); } return false; }
From source file:com.microsoft.tfs.core.httpclient.auth.NegotiateScheme.java
public static boolean supportsCredentials(final Class<?> credentialClass) { if (credentialClass == null || !isSupported()) { return false; }/*w w w . j av a2 s.c o m*/ if (credentialClass.equals(DefaultNTCredentials.class)) { return NegotiateEngine.getInstance().supportsCredentialsDefault(); } else if (credentialClass.equals(UsernamePasswordCredentials.class)) { return NegotiateEngine.getInstance().supportsCredentialsSpecified(); } return false; }
From source file:com.ghy.common.util.reflection.ReflectionUtils.java
/** * value String/* w ww .j av a2 s .co m*/ * , private/protected, ??setter. */ public static void setFieldsValues(final Object obj, final String fieldName, final Object value) { Field field = getAccessibleField(obj, fieldName); if (field == null) { return; } try { Class<?> type = field.getType(); if (type.equals(Integer.class) || type.equals(int.class)) { field.set(obj, Integer.valueOf((String) value)); } else if (type.equals(Long.class) || type.equals(long.class)) { field.set(obj, Long.valueOf((String) value)); } else if (type.equals(Double.class) || type.equals(double.class)) { field.set(obj, Double.valueOf((String) value)); } else if (type.equals(Float.class) || type.equals(float.class)) { field.set(obj, Float.valueOf((String) value)); } else if (type.equals(Boolean.class) || type.equals(boolean.class)) { field.set(obj, Boolean.valueOf((String) value)); } else if (type.equals(Date.class)) { field.set(obj, new SimpleDateFormat("yyyyMMddHHmmsssss").parse((String) value)); } else { field.set(obj, value); } } catch (IllegalAccessException e) { logger.error(":{}", e.getMessage()); } catch (IllegalArgumentException e) { logger.error(":{}", e.getMessage()); e.printStackTrace(); } catch (ParseException e) { logger.error(":{}", e.getMessage()); e.printStackTrace(); } }
From source file:org.openspaces.rest.utils.ControllerUtils.java
public static Object convertPropertyToPrimitiveType(String object, Class type, String propKey) { if (type.equals(Long.class) || type.equals(Long.TYPE)) return Long.valueOf(object); if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) return Boolean.valueOf(object); if (type.equals(Integer.class) || type.equals(Integer.TYPE)) return Integer.valueOf(object); if (type.equals(Byte.class) || type.equals(Byte.TYPE)) return Byte.valueOf(object); if (type.equals(Short.class) || type.equals(Short.TYPE)) return Short.valueOf(object); if (type.equals(Float.class) || type.equals(Float.TYPE)) return Float.valueOf(object); if (type.equals(Double.class) || type.equals(Double.TYPE)) return Double.valueOf(object); if (type.isEnum()) return Enum.valueOf(type, object); if (type.equals(String.class) || type.equals(Object.class)) return String.valueOf(object); if (type.equals(java.util.Date.class)) { try {// www . j a v a2s .co m return simpleDateFormat.parse(object); } catch (ParseException e) { throw new RestException( "Unable to parse date [" + object + "]. Make sure it matches the format: " + date_format); } } //unknown type throw new UnsupportedTypeException("Non primitive type when converting property [" + propKey + "]:" + type); }
From source file:com.github.strawberry.guice.config.ConfigLoader.java
/** * Utility method to create a default non-null value for the given type * parameter. This gets called when {@link Redis#allowNull()} was set to * false for the given {@link Field}, and no value for the specified key(s) * (see {@link Redis#value()}) was present in the Redis database. * @param type The type to create the non-null value for. * @return A non-null instance of the type. Note: for primitives this will * obviously result in a boxed return value. *//*ww w . j a v a2 s . co m*/ private static Object nonNullValueOf(Class<?> type) { Object value = null; if (type.equals(char[].class)) { value = new char[] {}; } else if (type.equals(Character[].class)) { value = new Character[] {}; } else if (type.equals(char.class) || type.equals(Character.class)) { value = '\0'; } else if (type.equals(String.class)) { value = ""; } else if (type.equals(byte[].class)) { value = new byte[] {}; } else if (type.equals(Byte[].class)) { value = new Byte[] {}; } else if (type.equals(byte.class) || type.equals(Byte.class)) { value = (byte) 0; } else if (type.equals(boolean.class) || type.equals(Boolean.class)) { value = false; } else if (type.equals(short.class) || type.equals(Short.class)) { value = (short) 0; } else if (type.equals(int.class) || type.equals(Integer.class)) { value = 0; } else if (type.equals(long.class) || type.equals(Long.class)) { value = 0L; } else if (type.equals(BigInteger.class)) { value = BigInteger.ZERO; } else if (type.equals(float.class) || type.equals(Float.class)) { value = 0.0f; } else if (type.equals(double.class) || type.equals(Double.class)) { value = 0.0; } else if (type.equals(BigDecimal.class)) { value = BigDecimal.ZERO; } else if (Map.class.isAssignableFrom(type)) { value = mapImplementationOf(type); } else if (Collection.class.isAssignableFrom(type)) { value = collectionImplementationOf(type); } return value; }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert//from w w w . ja va 2 s . c om * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class targetClass) throws IllegalArgumentException { if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:com.evolveum.midpoint.schema.constants.ObjectTypes.java
@SuppressWarnings("unchecked") public static ObjectTypes getObjectType(Class<? extends ObjectType> objectType) { for (ObjectTypes type : values()) { if (type.getClassDefinition().equals(objectType)) { return type; }//from w w w.j av a 2 s. co m } // No match. Try with superclass. Class<?> superclass = objectType.getSuperclass(); if (superclass != null && !superclass.equals(ObjectType.class)) { return getObjectType((Class<? extends ObjectType>) superclass); } throw new IllegalArgumentException("Unsupported object type " + objectType); }
From source file:Main.java
private final static Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> declaringClass, Class<?> inClass) { if (inClass == null) return null; Class<?> superClass = null; Type resolvedType = null;//from www.j a v a 2 s.c o m Type genericSuperClass = null; if (!declaringClass.equals(inClass)) { if (declaringClass.isInterface()) { // the declaringClass is an interface Class<?>[] interfaces = inClass.getInterfaces(); for (int i = 0; i < interfaces.length && resolvedType == null; i++) { superClass = interfaces[i]; resolvedType = resolveTypeVariable(type, declaringClass, superClass); genericSuperClass = inClass.getGenericInterfaces()[i]; } } if (resolvedType == null) { superClass = inClass.getSuperclass(); resolvedType = resolveTypeVariable(type, declaringClass, superClass); genericSuperClass = inClass.getGenericSuperclass(); } } else { resolvedType = type; genericSuperClass = superClass = inClass; } if (resolvedType != null) { // if its another type this means we have finished if (resolvedType instanceof TypeVariable<?>) { type = (TypeVariable<?>) resolvedType; TypeVariable<?>[] parameters = superClass.getTypeParameters(); int positionInClass = 0; for (; positionInClass < parameters.length && !type.equals(parameters[positionInClass]); positionInClass++) { } // we located the position of the typevariable in the superclass if (positionInClass < parameters.length) { // let's look if we have type specialization information in the current class if (genericSuperClass instanceof ParameterizedType) { ParameterizedType pGenericType = (ParameterizedType) genericSuperClass; Type[] args = pGenericType.getActualTypeArguments(); return positionInClass < args.length ? args[positionInClass] : null; } } // we didnt find typevariable specialization in the class, so it's the best we can // do, lets return the resolvedType... } } return resolvedType; }
From source file:jp.furplag.util.commons.ObjectUtils.java
/** * substitute for {@code instanceof}./*from w w w . j a v a 2 s .co m*/ * * @param clazz the Object, return false if null. * @param classes array of {@link java.lang.Class}. * @return if true, {@code o.getClass()} (or Class<?> o) contains given Classes. */ public static boolean isAny(final Object o, final Class<?>... classes) { if (classes == null) return o == null; if (classes.length < 1) return false; Class<?> type = o == null ? null : (o instanceof Class) ? ((Class<?>) o) : o.getClass().isArray() ? o.getClass().getComponentType() : o.getClass(); for (Class<?> clazz : classes) { if (o == null && clazz == null) return true; if (o == null || clazz == null) continue; if (clazz.equals(type)) return true; if (!(o instanceof Class) && ClassUtils.primitiveToWrapper(type).equals(ClassUtils.primitiveToWrapper(clazz))) return true; if (clazz.isArray() && type.equals(clazz.getComponentType())) return true; } return false; }