List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:org.guanxi.idp.form.RegisterSPFormValidator.java
@SuppressWarnings("unchecked") public boolean supports(Class clazz) { return clazz.equals(RegisterSP.class); }
From source file:org.sloth.validation.CoordinateValidator.java
@Override public boolean supports(Class<?> clazz) { return clazz.equals(Coordinate.class); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.experiment.AddFileMetadataValidator.java
public boolean supports(Class clazz) { return clazz.equals(AddFileMetadataCommand.class); }
From source file:org.openmrs.module.ejemplomedellin.web.controller.UserDetailsValidator.java
/** * @see org.springframework.validation.Validator#supports(java.lang.Class) *///from w w w .j a v a2 s. c o m @Override public boolean supports(Class clazz) { return clazz.equals(UserDetails.class); }
From source file:io.coala.factory.ClassUtil.java
/** * Get the actual type arguments a child class has used to extend a generic * base class. See <a/*from ww w . j a va 2s . co m*/ * href="http://www.artima.com/weblogs/viewpost.jsp?thread=208860" * >description</a> * * @param genericAncestorType the base class * @param concreteDescendantType the child class * @return a list of the raw classes for the actual type arguments. */ public static <T> List<Class<?>> getTypeArguments(final Class<T> genericAncestorType, final Class<? extends T> concreteDescendantType) { // sanity check if (genericAncestorType == null) throw CoalaExceptionFactory.VALUE_NOT_SET.createRuntime("genericAncestorType"); if (concreteDescendantType == null) throw CoalaExceptionFactory.VALUE_NOT_SET.createRuntime("concreteDescendantType"); Map<Type, Type> resolvedTypes = new HashMap<Type, Type>(); Type type = concreteDescendantType; Class<?> typeClass = getClass(type); // start walking up the inheritance hierarchy until we hit parentClass while (!genericAncestorType.equals(typeClass)) { if (type instanceof Class) { // there is no useful information for us in raw types, so just // keep going. if (genericAncestorType.isInterface()) { Type intfType = null; for (Type intf : typeClass.getGenericInterfaces()) { if (intf instanceof ParameterizedType && genericAncestorType.equals(((ParameterizedType) intf).getRawType())) { intfType = intf; break; } } if (intfType == null) type = typeClass.getGenericSuperclass(); else type = intfType; } else type = typeClass.getGenericSuperclass(); if (type == null) { if (!typeClass.isInterface()) { LOG.warn("No generic super classes found for child class: " + typeClass + " of parent: " + genericAncestorType); return Collections.emptyList(); } for (Type intf : typeClass.getGenericInterfaces()) { if (intf instanceof ParameterizedType) { type = intf; // TODO try other interfaces if this one fails? break; } } if (type == null) { LOG.warn("No generic ancestors found for child interface: " + typeClass + " of parent: " + genericAncestorType); return Collections.emptyList(); } } // LOG.trace(String.format("Trying generic super of %s: %s", // typeClass.getSimpleName(), type)); } else { final ParameterizedType parameterizedType = (ParameterizedType) type; final Class<?> rawType = (Class<?>) parameterizedType.getRawType(); final Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); final TypeVariable<?>[] typeParameters = rawType.getTypeParameters(); for (int i = 0; i < actualTypeArguments.length; i++) { resolvedTypes.put(typeParameters[i], actualTypeArguments[i]); } if (!genericAncestorType.equals(rawType)) { type = rawType.getGenericSuperclass(); // LOG.trace(String.format( // "Trying generic super of child %s: %s", rawType, // type)); } // else // done climbing the hierarchy // LOG.trace("Matched generic " + type + " to ancestor: " // + genericAncestorType); } typeClass = getClass(type); // LOG.trace("Trying generic " + typeClass + " from: " // + Arrays.asList(typeClass.getGenericInterfaces())); } // finally, for each actual type argument provided to baseClass, // determine (if possible) // the raw class for that type argument. final Type[] actualTypeArguments; if (type instanceof Class) { actualTypeArguments = typeClass.getTypeParameters(); } else { actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments(); } // resolve types by chasing down type variables. final List<Class<?>> parentTypeArguments = new ArrayList<Class<?>>(); for (Type baseType : actualTypeArguments) { while (resolvedTypes.containsKey(baseType)) baseType = resolvedTypes.get(baseType); parentTypeArguments.add(getClass(baseType)); } // LOG.trace(String.format( // "Got child %s's type arguments for %s: %s", // childClass.getName(), parentClass.getSimpleName(), // parentTypeArguments)); return parentTypeArguments; }
From source file:br.com.sicva.seguranca.ProvedorAutenticacao.java
@Override public boolean supports(Class<?> authentication) { return authentication.equals(UsernamePasswordAuthenticationToken.class); }
From source file:com.holonplatform.core.internal.utils.TypeUtils.java
/** * Return the type parameter of a generic type. * @param clazz subClass of <code>baseClass</code> to analyze. * @param baseClass base class having the type parameter the value of which we need to retrieve * @return the parameterized type value/*w ww. j av a 2s . com*/ */ @SuppressWarnings("rawtypes") public static Type getTypeArgument(Class<?> clazz, Class<?> baseClass) { Stack<Type> superclasses = new Stack<>(); Type currentType; Class<?> currentClass = clazz; if (clazz.getGenericSuperclass() == Object.class) { currentType = clazz; superclasses.push(currentType); } else { do { currentType = currentClass.getGenericSuperclass(); superclasses.push(currentType); if (currentType instanceof Class) { currentClass = (Class) currentType; } else if (currentType instanceof ParameterizedType) { currentClass = (Class) ((ParameterizedType) currentType).getRawType(); } } while (!currentClass.equals(baseClass)); } // find which one supplies type argument and return it TypeVariable tv = baseClass.getTypeParameters()[0]; while (!superclasses.isEmpty()) { currentType = superclasses.pop(); if (currentType instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) currentType; Class<?> rawType = (Class) pt.getRawType(); int argIndex = Arrays.asList(rawType.getTypeParameters()).indexOf(tv); if (argIndex > -1) { Type typeArg = pt.getActualTypeArguments()[argIndex]; if (typeArg instanceof TypeVariable) { // type argument is another type variable - look for the value of that // variable in subclasses tv = (TypeVariable) typeArg; continue; } else { // found the value - return it return typeArg; } } } // needed type argument not supplied - break and throw exception break; } throw new IllegalArgumentException(currentType + " does not specify a type parameter"); }
From source file:org.guanxi.sp.engine.form.RegisterGuardFormValidator.java
@SuppressWarnings("unchecked") public boolean supports(Class clazz) { return clazz.equals(RegisterGuard.class); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.weather.AddWeatherValidator.java
public boolean supports(Class clazz) { return clazz.equals(AddWeatherCommand.class); }
From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java
private static <T> T tryConvertPrimitiveScalar(NodeList valueNodes, Class<T> type) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < valueNodes.getLength(); i++) { Node node = valueNodes.item(i); if (DOMUtil.isJunk(node)) { continue; }/*from w ww.j av a2 s .co m*/ if (node.getNodeType() == Node.TEXT_NODE) { sb.append(node.getTextContent()); } else { // We have failed return null; } } if (type.equals(Object.class)) { // Try string as default type return (T) XmlTypeConverter.toJavaValue(sb.toString(), String.class); } return XmlTypeConverter.toJavaValue(sb.toString(), type); }