List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:com.serli.chell.framework.form.FormStructure.java
private static boolean isFormField(Field field, Class<?> fieldType) { return ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0) && (fieldType.equals(String.class) || fieldType.equals(String[].class) && !field.isAnnotationPresent(HtmlTransient.class)); }
From source file:hu.bme.mit.sette.tools.catg.CatgGenerator.java
private static String getTypeString(Class<?> javaClass) { if (javaClass.isPrimitive()) { javaClass = ClassUtils.primitiveToWrapper(javaClass); }//from www. ja va 2 s. co m if (javaClass.equals(Byte.class)) { return "byte"; } else if (javaClass.equals(Short.class)) { return "short"; } else if (javaClass.equals(Integer.class)) { return "int"; } else if (javaClass.equals(Long.class)) { return "long"; } else if (javaClass.equals(Boolean.class)) { return "boolean"; } else if (javaClass.equals(Character.class)) { return "char"; } else if (javaClass.equals(String.class)) { return "String"; } else { return null; } }
From source file:hu.bme.mit.sette.tools.catg.CatgGenerator.java
private static String createCatgRead(Class<?> javaClass) { if (javaClass.isPrimitive()) { javaClass = ClassUtils.primitiveToWrapper(javaClass); }// w w w . j a v a 2s. com if (javaClass.equals(Byte.class)) { return "CATG.readByte((byte) 1)"; } else if (javaClass.equals(Short.class)) { return "CATG.readShort((short) 1)"; } else if (javaClass.equals(Integer.class)) { return "CATG.readInt(1)"; } else if (javaClass.equals(Long.class)) { return "CATG.readLong(1L)"; } else if (javaClass.equals(Boolean.class)) { return "CATG.readBool(false)"; } else if (javaClass.equals(Character.class)) { return "CATG.readChar(' ')"; } else if (javaClass.equals(String.class)) { return "CATG.readString(\"\")"; } else { return null; } }
From source file:com.mawujun.util.AnnotationUtils.java
/** * Helper method for generating a hash code for an array. * * @param componentType the component type of the array * @param o the array//from w w w . j a v a2 s .c o m * @return a hash code for the specified array */ private static int arrayMemberHash(Class<?> componentType, Object o) { if (componentType.equals(Byte.TYPE)) { return Arrays.hashCode((byte[]) o); } if (componentType.equals(Short.TYPE)) { return Arrays.hashCode((short[]) o); } if (componentType.equals(Integer.TYPE)) { return Arrays.hashCode((int[]) o); } if (componentType.equals(Character.TYPE)) { return Arrays.hashCode((char[]) o); } if (componentType.equals(Long.TYPE)) { return Arrays.hashCode((long[]) o); } if (componentType.equals(Float.TYPE)) { return Arrays.hashCode((float[]) o); } if (componentType.equals(Double.TYPE)) { return Arrays.hashCode((double[]) o); } if (componentType.equals(Boolean.TYPE)) { return Arrays.hashCode((boolean[]) o); } return Arrays.hashCode((Object[]) o); }
From source file:ConversionUtil.java
public static byte[] convertToByteArray(Object object) throws Exception { byte[] returnArray = null; Class clazz = object.getClass(); String clazzName = clazz.getName(); if (clazz.equals(Integer.class)) { Integer aValue = (Integer) object; int intValue = aValue.intValue(); returnArray = convertToByteArray(intValue); } else if (clazz.equals(String.class)) { String aValue = (String) object; returnArray = convertToByteArray(aValue); } else if (clazz.equals(Byte.class)) { Byte aValue = (Byte) object; byte byteValue = aValue.byteValue(); returnArray = convertToByteArray(byteValue); } else if (clazz.equals(Long.class)) { Long aValue = (Long) object; long longValue = aValue.longValue(); returnArray = convertToByteArray(longValue); } else if (clazz.equals(Short.class)) { Short aValue = (Short) object; short shortValue = aValue.shortValue(); returnArray = convertToByteArray(shortValue); } else if (clazz.equals(Boolean.class)) { Boolean aValue = (Boolean) object; boolean booleanValue = aValue.booleanValue(); returnArray = convertToByteArray(booleanValue); } else if (clazz.equals(Character.class)) { Character aValue = (Character) object; char charValue = aValue.charValue(); returnArray = convertToByteArray(charValue); } else if (clazz.equals(Float.class)) { Float aValue = (Float) object; float floatValue = aValue.floatValue(); returnArray = convertToByteArray(floatValue); } else if (clazz.equals(Double.class)) { Double aValue = (Double) object; double doubleValue = aValue.doubleValue(); returnArray = convertToByteArray(doubleValue); } else {//from ww w .j a va2 s .c o m throw new Exception("Cannot convert object of type " + clazzName); } return returnArray; }
From source file:com.github.fcannizzaro.prefs.Prefs.java
/** * Remove value with that key and class (to prevent multiple values deletions) * * @param key of value//from w ww . j a v a 2 s . c om * @param c class of value */ public static void remove(String key, Class c) { if (c.equals(Integer.class)) integers.remove(key); else if (c.equals(Float.class)) floats.remove(key); else if (c.equals(Boolean.class)) booleans.remove(key); else if (c.equals(String.class)) strings.remove(key); else if (c.equals(Double.class)) doubles.remove(key); else objects.remove(key); updateMemory(); }
From source file:ml.shifu.shifu.util.ClassUtils.java
@SuppressWarnings("unchecked") public static List<Method> getAllMethods(Class<?> clazz) { if (clazz == null) { return Collections.EMPTY_LIST; }/* ww w . j a va 2 s . com*/ if (clazz.equals(Object.class)) { return Collections.EMPTY_LIST; } List<Method> result = new ArrayList<Method>(); for (Method method : clazz.getDeclaredMethods()) { result.add(method); } Class<?> tmpClazz = clazz.getSuperclass(); while (!Object.class.equals(tmpClazz)) { result.addAll(getAllMethods(tmpClazz)); tmpClazz = tmpClazz.getSuperclass(); } return result; }
From source file:NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the corresponding default <code>decode</code> methods. Trims the * input <code>String</code> before attempting to parse the number. Supports * numbers in hex format (with leading 0x) and in octal format (with leading 0). * @param text the text to convert// ww w . j av a 2s .c o m * @param targetClass the target class to parse into * @return the parsed 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#decode * @see java.lang.Short#decode * @see java.lang.Integer#decode * @see java.lang.Long#decode * @see #decodeBigInteger(String) * @see java.lang.Float#valueOf * @see java.lang.Double#valueOf * @see java.math.BigDecimal#BigDecimal(String) */ public static Number parseNumber(String text, Class<?> targetClass) { // Assert.notNull(text, "Text must not be null"); //Assert.notNull(targetClass, "Target class must not be null"); String trimmed = text.trim(); if (targetClass.equals(Byte.class)) { return Byte.decode(trimmed); } else if (targetClass.equals(Short.class)) { return Short.decode(trimmed); } else if (targetClass.equals(Integer.class)) { return Integer.decode(trimmed); } else if (targetClass.equals(Long.class)) { return Long.decode(trimmed); } else if (targetClass.equals(BigInteger.class)) { return decodeBigInteger(trimmed); } else if (targetClass.equals(Float.class)) { return Float.valueOf(trimmed); } else if (targetClass.equals(Double.class)) { return Double.valueOf(trimmed); } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) { return new BigDecimal(trimmed); } else { throw new IllegalArgumentException( "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]"); } }
From source file:com.joyent.manta.http.HttpRange.java
/** * Constructs a range from a {@code Content-Length}, assuming the entire object is being requested. * * @param contentLength the object's Content-Length * @return a range representing the object content *///from w w w . java2 s . co m @SuppressWarnings("unchecked") static <T extends HttpRange> T fromContentLength(final Class<T> klass, final long contentLength) { if (klass.equals(BoundedRequest.class)) { return (T) new BoundedRequest(0, contentLength - 1); } if (klass.equals(Response.class)) { return (T) new Response(0, contentLength - 1, contentLength); } throw new IllegalArgumentException(String.format("Cannot recognize HttpRange class: [%s]", klass)); }
From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java
public static Class<?> getJavaType(int sqltype, String name, int precision, int scale) { Class<?> c = getJavaType(sqltype, precision, scale); // ???????????? if (name != null && c.equals(Object.class)) { if (name.startsWith("TIMESTAMP")) { // Oracle TIMESTAMP ?? c = java.sql.Timestamp.class; } else if (name.startsWith("NCHAR") || name.startsWith("NVARCHAR")) { c = String.class; }//from w ww . ja v a 2s . c o m } // SQL Server ? date/time if (String.class.equals(c)) { if ("date".equals(name)) { return java.sql.Date.class; } else if ("time".equals(name)) { return java.sql.Time.class; } } return c; }