List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:io.github.benas.jpopulator.randomizers.validation.MinValueRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @param minValue the minimum threshold for the generated value * @return a random value (greater than maxValue) for the given type or null if the type is not supported *//*from w w w . j a va 2 s .co m*/ public static Object getRandomValue(final Class type, final long minValue) { if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) randomDataGenerator.nextLong(minValue, Byte.MAX_VALUE); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) randomDataGenerator.nextLong(minValue, Short.MAX_VALUE); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return (int) randomDataGenerator.nextLong(minValue, Integer.MAX_VALUE); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return randomDataGenerator.nextLong(minValue, Long.MAX_VALUE); } if (type.equals(BigInteger.class)) { return new BigInteger(String.valueOf(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE))); } if (type.equals(BigDecimal.class)) { return new BigDecimal(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE)); } return null; }
From source file:com.cloudera.dataflow.hadoop.WritableCoder.java
/** * Returns a {@code WritableCoder} instance for the provided element class. * @param <T> the element type//ww w .j a v a 2 s . c o m * @param clazz the element class * @return a {@code WritableCoder} instance for the provided element class */ public static <T extends Writable> WritableCoder<T> of(Class<T> clazz) { if (clazz.equals(NullWritable.class)) { @SuppressWarnings("unchecked") WritableCoder<T> result = (WritableCoder<T>) NullWritableCoder.of(); return result; } return new WritableCoder<>(clazz); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T parse(Class<T> type, String stringValue) throws IllegalArgumentException { if (type.equals(String.class)) { return (T) stringValue; }/*from ww w. j a va2 s . co m*/ if (type.equals(Boolean.class) || type.equals(boolean.class)) { return (T) Boolean.valueOf(stringValue); } try { if (type.equals(Integer.class) || type.equals(int.class)) { return (T) Integer.valueOf(stringValue); } if (type.equals(Long.class) || type.equals(long.class)) { return (T) Long.valueOf(stringValue); } if (type.equals(Short.class) || type.equals(short.class)) { return (T) Short.valueOf(stringValue); } if (type.equals(Byte.class) || type.equals(byte.class)) { return (T) Byte.valueOf(stringValue); } if (type.equals(Double.class) || type.equals(double.class)) { return (T) Double.valueOf(stringValue); } if (type.equals(Float.class) || type.equals(float.class)) { return (T) Float.valueOf(stringValue); } if (type.equals(File.class)) { return (T) new File(stringValue); } } catch (final NumberFormatException e) { throw new IllegalArgumentException(e.getMessage(), e); } if (type.isEnum()) { @SuppressWarnings("rawtypes") final Class enumType = type; return (T) Enum.valueOf(enumType, stringValue); } throw new IllegalArgumentException("Can't handle type " + type); }
From source file:Main.java
/** * Check if the object has a class to avoid * @param object Object to check/*from www .j a va 2s . c om*/ * @param avoidClasses Class[] list of classes to avoid * @return boolean TRUE if the class is in the list, FALSE to continue */ private static boolean isObjectToAvoid(Object object, Class[] avoidClasses) { if (object != null && avoidClasses != null) { Class objectClass = object.getClass(); do { for (Class klass : avoidClasses) { if (objectClass.equals(klass)) { return true; } } objectClass = objectClass.getSuperclass(); } while (objectClass != null); } //not found return false; }
From source file:Main.java
public static String getDataBaseType(Class type) { String res = TEXT;/* ww w .j av a2 s . c o m*/ do { if (type.equals(String.class)) { break; } if (type.equals(char.class) || type.equals(Character.class)) { break; } if (type.equals(Date.class)) { break; } if (type.equals(short.class) || type.equals(Short.class)) { res = INTEGER; break; } if (type.equals(int.class) || type.equals(Integer.class)) { res = INTEGER; break; } if (type.equals(long.class) || type.equals(Long.class)) { res = INTEGER; break; } if (type.equals(boolean.class) || type.equals(Boolean.class)) { res = INTEGER; break; } if (type.equals(double.class) || type.equals(Double.class)) { res = REAL; break; } if (type.equals(float.class) || type.equals(Float.class)) { res = REAL; break; } break; } while (false); return res; }
From source file:Main.java
public static Number getValue(Map<? extends Object, ? extends Number> map, Object key, Class<?> clazz) { Number value = map.get(key);// www . j av a 2 s .c o m if (value == null) { if (clazz.equals(Double.class)) { value = 0.0; } else { value = 0; } } return value; }
From source file:it.unibas.spicy.persistence.object.ClassUtility.java
private static boolean findInterface(Class currentClass, Class currentInterface) { Class[] interfaces = currentClass.getInterfaces(); for (Class class1 : interfaces) { if (class1.equals(currentInterface)) { return true; }// w ww . j a va2s . c o m } return false; }
From source file:me.ronghai.sa.model.ModelMeta.java
public static Object get(ResultSet rs, String cname, Class<?> type) throws SQLException { if (type != null && type.equals(java.util.Date.class)) { type = java.sql.Date.class; }//from w ww . ja v a 2s. co m return rs.getObject(cname, type); }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.util.FileUtil.java
/** * Check whether a given class is a file * * @param clazz given class//from w w w .j a va 2s.co m * @return true if is file, false otherwise */ public static boolean isFile(Class clazz) { return (clazz == null) ? false : clazz.equals(File.class); }
From source file:management.limbr.test.util.PojoTester.java
@SuppressWarnings("unchecked") private static <T> T createRichObject(Class<T> type) { try {/*from www. j a v a 2 s . c om*/ if (type.equals(Set.class)) { return (T) new HashSet<>(); } else if (type.equals(List.class)) { return (T) new ArrayList<>(); } else if (type.isEnum()) { T[] values = type.getEnumConstants(); return values[random.nextInt(values.length)]; } else { return type.newInstance(); } } catch (IllegalAccessException | InstantiationException ex) { throw new IllegalStateException("Couldn't construct object of type " + type.getName() + ".", ex); } }