List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:net.sf.jasperreports.renderers.util.RendererUtil.java
/** * *//*from w w w. j a v a 2 s . co m*/ public static boolean isLazy(Renderable renderer) { boolean isLazy = false; if (renderer instanceof ResourceRenderer) { isLazy = ((ResourceRenderer) renderer).isLazy(); } else if (renderer != null) { @SuppressWarnings("deprecation") Class<?> depClass = net.sf.jasperreports.engine.JRImageRenderer.class; if (depClass.equals(renderer.getClass())) { @SuppressWarnings("deprecation") net.sf.jasperreports.engine.JRImageRenderer depRenderer = (net.sf.jasperreports.engine.JRImageRenderer) renderer; @SuppressWarnings("deprecation") String depImageLocation = depRenderer.getImageLocation(); isLazy = depImageLocation != null; } } return isLazy; }
From source file:net.sf.jasperreports.renderers.util.RendererUtil.java
/** * *///from w ww. ja v a2 s .co m public static String getResourceLocation(Renderable renderer) { String resourceLocation = null; if (renderer instanceof ResourceRenderer) { resourceLocation = ((ResourceRenderer) renderer).getResourceLocation(); } else if (renderer != null) { @SuppressWarnings("deprecation") Class<?> depClass = net.sf.jasperreports.engine.JRImageRenderer.class; if (depClass.equals(renderer.getClass())) { @SuppressWarnings("deprecation") net.sf.jasperreports.engine.JRImageRenderer depRenderer = (net.sf.jasperreports.engine.JRImageRenderer) renderer; @SuppressWarnings("deprecation") String depImageLocation = depRenderer.getImageLocation(); resourceLocation = depImageLocation; } } return resourceLocation; }
From source file:io.coala.factory.ClassUtil.java
/** * @param primitive/*www . j a va 2 s . co m*/ * @param wrapper * @return <tt>true</tt> if x is the primitive type wrapped by y, * <tt>false</tt> otherwise */ public static boolean isPrimitiveOf(final Class<?> primitive, final Class<?> wrapper) { if (!primitive.isPrimitive() || wrapper.isPrimitive()) return false; // System.err.println( primitive+" =?= "+wrapper ); if (primitive.equals(byte.class) && wrapper.equals(Byte.class)) return true; if (primitive.equals(short.class) && wrapper.equals(Short.class)) return true; if (primitive.equals(int.class) && wrapper.equals(Integer.class)) return true; if (primitive.equals(long.class) && wrapper.equals(Long.class)) return true; if (primitive.equals(double.class) && wrapper.equals(Double.class)) return true; if (primitive.equals(float.class) && wrapper.equals(Float.class)) return true; if (primitive.equals(boolean.class) && wrapper.equals(Boolean.class)) return true; if (primitive.equals(char.class) && wrapper.equals(Character.class)) return true; return false; }
From source file:com.mawujun.util.AnnotationUtils.java
/** * Helper method for comparing two objects of an array type. * * @param componentType the component type of the array * @param o1 the first object// w w w. j av a 2 s . c o m * @param o2 the second object * @return a flag whether these objects are equal */ private static boolean arrayMemberEquals(Class<?> componentType, Object o1, Object o2) { if (componentType.isAnnotation()) { return annotationArrayMemberEquals((Annotation[]) o1, (Annotation[]) o2); } if (componentType.equals(Byte.TYPE)) { return Arrays.equals((byte[]) o1, (byte[]) o2); } if (componentType.equals(Short.TYPE)) { return Arrays.equals((short[]) o1, (short[]) o2); } if (componentType.equals(Integer.TYPE)) { return Arrays.equals((int[]) o1, (int[]) o2); } if (componentType.equals(Character.TYPE)) { return Arrays.equals((char[]) o1, (char[]) o2); } if (componentType.equals(Long.TYPE)) { return Arrays.equals((long[]) o1, (long[]) o2); } if (componentType.equals(Float.TYPE)) { return Arrays.equals((float[]) o1, (float[]) o2); } if (componentType.equals(Double.TYPE)) { return Arrays.equals((double[]) o1, (double[]) o2); } if (componentType.equals(Boolean.TYPE)) { return Arrays.equals((boolean[]) o1, (boolean[]) o2); } return Arrays.equals((Object[]) o1, (Object[]) o2); }
From source file:net.servicefixture.util.ReflectionUtils.java
public static String getDefaultValue(Class type) { if (isEnumarationPatternClass(type)) { StringBuilder sb = new StringBuilder(); Field[] fields = type.getFields(); for (int i = 0; i < fields.length; i++) { if (type.equals(fields[i].getType()) && Modifier.isFinal(fields[i].getModifiers()) && Modifier.isPublic(fields[i].getModifiers()) && Modifier.isStatic(fields[i].getModifiers())) { try { sb.append(fields[i].getName()).append(";"); } catch (IllegalArgumentException e) { }//from ww w . ja v a 2 s . com } } return sb.toString(); } else if (type.isEnum()) { StringBuilder sb = new StringBuilder(); try { Object[] array = (Object[]) type.getMethod("values").invoke(null); for (int i = 0; i < array.length; i++) { sb.append(array[i]).append(";"); } } catch (Exception e) { } return sb.toString(); } else if (Calendar.class.isAssignableFrom(type) || XMLGregorianCalendar.class.isAssignableFrom(type)) { return "${calendar.after(0)}"; } else if (Date.class.isAssignableFrom(type)) { return "${date.after(0)}"; } else if (Number.class.isAssignableFrom(type) || "long".equals(type.getName()) || "int".equals(type.getName()) || "short".equals(type.getName()) || "float".equals(type.getName()) || "double".equals(type.getName())) { return "0"; } else if (String.class.equals(type)) { return "String"; } else if (Boolean.class.equals(type) || "boolean".equals(type.getName())) { return "true"; } return type.getName(); }
From source file:com.redhat.example.rules.unittest.RuleFactWatcher.java
/** * class immutable check/*from w w w .ja v a 2 s . c om*/ * @param clazz * @return true if the parameter class is immutable. */ public static boolean isImmutable(Class<?> clazz) { if (clazz != null) { if (clazz.equals(String.class) || Number.class.isAssignableFrom(clazz) || Date.class.isAssignableFrom(clazz) || clazz == Object.class) { return true; } } return false; }
From source file:jp.go.nict.langrid.client.soap.io.SoapResponseParser.java
private static <T> T nodeToType(XPathWorkspace w, Node node, Class<T> clazz, Converter converter) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ConversionException, DOMException, ParseException { if (clazz.isPrimitive()) { return converter.convert(resolveHref(w, node).getTextContent(), clazz); } else if (clazz.equals(String.class)) { return clazz.cast(resolveHref(w, node).getTextContent()); } else if (clazz.equals(byte[].class)) { try {//from w w w . j av a2 s . c o m return clazz.cast(Base64.decodeBase64(resolveHref(w, node).getTextContent().getBytes("ISO8859-1"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } else if (clazz.equals(Calendar.class)) { Date date = fmt.get().parse(resolveHref(w, node).getTextContent()); Calendar c = Calendar.getInstance(); c.setTime(date); return clazz.cast(c); } else if (clazz.isArray()) { Class<?> ct = clazz.getComponentType(); List<Object> elements = new ArrayList<Object>(); node = resolveHref(w, node); for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (!(child instanceof Element)) continue; elements.add(nodeToType(w, child, ct, converter)); } return clazz.cast(elements.toArray((Object[]) Array.newInstance(ct, elements.size()))); } else { T instance = clazz.newInstance(); node = resolveHref(w, node); for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (!(child instanceof Element)) continue; String nn = child.getLocalName(); Method setter = ClassUtil.findSetter(clazz, nn); setter.invoke(instance, nodeToType(w, resolveHref(w, child), setter.getParameterTypes()[0], converter)); } return instance; } }
From source file:com.iterranux.droolsjbpmCore.internal.AbstractGenericFactory.java
/** * Get the actual type arguments a child class has used to extend a generic base class. * * @param baseClass the base class//w w w . ja v a2 s .c o m * @param childClass the child class * @return a list of the raw classes for the actual type arguments. */ @SuppressWarnings("all") public static <T> List<Class<?>> getTypeArguments(Class<T> baseClass, Class<? extends T> childClass) { Map<Type, Type> resolvedTypes = new HashMap<Type, Type>(); Type type = childClass; // start walking up the inheritance hierarchy until we hit baseClass while (!getClass(type).equals(baseClass)) { if (type instanceof Class) { // there is no useful information for us in raw types, so just keep going. type = ((Class) type).getGenericSuperclass(); } else { ParameterizedType parameterizedType = (ParameterizedType) type; Class<?> rawType = (Class) parameterizedType.getRawType(); Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); TypeVariable<?>[] typeParameters = rawType.getTypeParameters(); for (int i = 0; i < actualTypeArguments.length; i++) { resolvedTypes.put(typeParameters[i], actualTypeArguments[i]); } if (!rawType.equals(baseClass)) { type = rawType.getGenericSuperclass(); } } } // finally, for each actual type argument provided to baseClass, determine (if possible) // the raw class for that type argument. Type[] actualTypeArguments; if (type instanceof Class) { actualTypeArguments = ((Class) type).getTypeParameters(); } else { actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments(); } List<Class<?>> typeArgumentsAsClasses = new ArrayList<Class<?>>(); // resolve types by chasing down type variables. for (Type baseType : actualTypeArguments) { while (resolvedTypes.containsKey(baseType)) { baseType = resolvedTypes.get(baseType); } typeArgumentsAsClasses.add(getClass(baseType)); } return typeArgumentsAsClasses; }
From source file:nz.co.senanque.validationengine.ValidationUtils.java
public static Comparable<?> convertTo(final Class<Comparable<?>> clazz, Object obj) { if (obj == null) { return null; }/*from w w w. j a va2s . c o m*/ if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(Long.class) || clazz.equals(Long.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Long(((Number) obj).longValue()); } return Long.valueOf(oStr); } if (clazz.equals(Integer.class) || clazz.equals(Integer.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Integer(((Number) obj).intValue()); } return Integer.valueOf(oStr); } if (clazz.equals(Double.class) || clazz.equals(Double.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Double(((Number) obj).doubleValue()); } return Double.valueOf(oStr); } if (clazz.equals(Float.class) || clazz.equals(Float.TYPE)) { if (Number.class.isAssignableFrom(obj.getClass())) { return new Float(((Number) obj).floatValue()); } return Float.valueOf(oStr); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(oStr); } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } return null; }
From source file:me.rojo8399.placeholderapi.impl.utils.TypeUtils.java
@SuppressWarnings("unchecked") public static <T> T convertPrimitive(String val, Class<T> primitiveClass) { val = val.toLowerCase().trim(); if (primitiveClass.equals(char.class) || primitiveClass.equals(Character.class)) { return (T) (Character) val.charAt(0); }/*from ww w . j a v a 2 s. c o m*/ if (primitiveClass.equals(int.class) || primitiveClass.equals(Integer.class)) { return (T) Integer.valueOf(val); } if (primitiveClass.equals(long.class) || primitiveClass.equals(Long.class)) { return (T) Long.valueOf(val); } if (primitiveClass.equals(short.class) || primitiveClass.equals(Short.class)) { return (T) Short.valueOf(val); } if (primitiveClass.equals(byte.class) || primitiveClass.equals(Byte.class)) { return (T) Byte.valueOf(val); } if (primitiveClass.equals(double.class) || primitiveClass.equals(Double.class)) { return (T) Double.valueOf(val); } if (primitiveClass.equals(float.class) || primitiveClass.equals(Float.class)) { return (T) Float.valueOf(val); } if (primitiveClass.equals(boolean.class) || primitiveClass.equals(Boolean.class)) { return (T) (Boolean) isTrue(val); } throw new IllegalArgumentException("Class is not primitive or a wrapper!"); }