List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:com.zaradai.kunzite.trader.config.statics.digester.InstrumentTypeConverter.java
@Override public Object convert(Class type, Object value) { checkNotNull(type, "Type cant be null"); checkNotNull(value, "Value cant be null"); checkArgument(type.equals(InstrumentType.class), "Conversion target must be InstrumentType"); checkArgument(String.class.isAssignableFrom(value.getClass()), "Value should be a string, but is a %s", value.getClass());//ww w . ja v a 2s . c o m return InstrumentType.valueOf((String) value); }
From source file:com.zaradai.kunzite.trader.config.statics.digester.OptionTypeConverter.java
@Override public Object convert(Class type, Object value) { checkNotNull(type, "Type cant be null"); checkNotNull(value, "Value cant be null"); checkArgument(type.equals(OptionType.class), "Conversion target must be OptionType"); checkArgument(String.class.isAssignableFrom(value.getClass()), "Value should be a string, but is a %s", value.getClass());//w w w.j a v a 2 s . c om return OptionType.valueOf((String) value); }
From source file:org.bonitasoft.web.designer.model.contract.databind.ContractDeserializer.java
private void parseNodeContractInput(ArrayNode inputArray, ContractInputContainer rootNodeInput) throws IOException { for (int i = 0; i < inputArray.size(); i++) { JsonNode childNode = inputArray.get(i); Class<?> inputType = inputType(childNode); if (inputType.equals(NodeContractInput.class)) { NodeContractInput nodeContractInput = newNodeContractInput(childNode); rootNodeInput.addInput(nodeContractInput); parseNodeContractInput(childInput(childNode), nodeContractInput); } else {// w ww. ja v a 2 s . co m rootNodeInput.addInput(newLeafContractInput(childNode, inputType)); } } }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Check if the right-hand side type may be assigned to the left-hand side * type, assuming setting by reflection. Considers primitive wrapper * classes as assignable to the corresponding primitive types. * @param lhsType the target type//w ww . j a va 2s. co m * @param rhsType the value type that should be assigned to the target type * @return if the target type is assignable from the value type * @see TypeUtils#isAssignable */ public static boolean isAssignable(Class lhsType, Class rhsType) { Assert.notNull(lhsType, "Left-hand side type must not be null"); Assert.notNull(rhsType, "Right-hand side type must not be null"); return (lhsType.isAssignableFrom(rhsType) || lhsType.equals(primitiveWrapperTypeMap.get(rhsType))); }
From source file:com.px100systems.data.core.CompoundIndexDescriptor.java
public CompoundIndexDescriptor(Class<?> entityClass, String name, String[] fields) { if (name.trim().isEmpty()) throw new RuntimeException("Empty compound index name in " + entityClass.getSimpleName()); this.name = NAME_PREFIX + entityClass.getSimpleName() + "_" + name + "_idx"; for (String field : fields) { String[] s = field.split(" "); if (s.length != 2) throw new RuntimeException("Invalid compound index " + name + " in " + entityClass.getSimpleName() + ": couldn't parse field '" + field + "'"); Method getter = ReflectionUtils.findMethod(entityClass, PropertyAccessor.methodName("get", s[0])); if (getter == null) throw new RuntimeException("Invalid compound index " + name + " in " + entityClass.getSimpleName() + ": couldn't find getter for '" + field + "'"); Class<?> returnType = getter.getReturnType(); if (!returnType.equals(Integer.class) && !returnType.equals(Long.class) && !returnType.equals(Double.class) && !returnType.equals(Date.class) && !returnType.equals(String.class) && !returnType.equals(Boolean.class)) throw new RuntimeException("Invalid compound index " + name + " in " + entityClass.getSimpleName() + ": field '" + field + "' - only Integer, Long, Double, Date, String, and Boolean are supported"); this.fields.add(new Field(s[0], returnType, s[1].equalsIgnoreCase("DESC"))); }/* w w w . ja va 2 s . c o m*/ }
From source file:com.bstek.dorado.config.text.TextParserHelper.java
private void doGetTextSectionInfo(TextSectionInfo textSectionInfo, Class<?> type) { for (Class<?> i : type.getInterfaces()) { doGetTextSectionInfo(textSectionInfo, i); }// ww w .j a v a2 s . c o m Class<?> superclass = type.getSuperclass(); if (superclass != null && !superclass.equals(Object.class)) { doGetTextSectionInfo(textSectionInfo, superclass); } collectXmlNodeInfo(textSectionInfo, type); }
From source file:management.limbr.test.util.PojoTester.java
private Object getTestValueFor(Class<?> type) { if (type.equals(boolean.class) || type.equals(Boolean.class)) { return random.nextBoolean(); } else if (type.equals(byte.class) || type.equals(Byte.class)) { return (byte) random.nextInt(Byte.MAX_VALUE); } else if (type.equals(short.class) || type.equals(Short.class)) { return (short) random.nextInt(Short.MAX_VALUE); } else if (type.equals(int.class) || type.equals(Integer.class)) { return random.nextInt(); } else if (type.equals(long.class) || type.equals(Long.class)) { return random.nextLong(); } else if (type.equals(char.class) || type.equals(Character.class)) { return (char) random.nextInt(Character.MAX_VALUE); } else if (type.equals(float.class) || type.equals(Float.class)) { return random.nextFloat(); } else if (type.equals(double.class) || type.equals(Double.class)) { return random.nextDouble(); } else if (type.equals(String.class)) { return Long.toString(random.nextLong()); } else {//from ww w . j av a 2 s . c o m return createRichObject(type); } }
From source file:com.tobedevoured.modelcitizen.spring.ModelFactoryBean.java
/** * Create new instance of model before blueprint values are set. Autowire them from Spring Context if they have the * @SpringBlueprint annotation/* w w w . j av a2s. c om*/ * * @param erector {@link Erector} * @return Object * @throws BlueprintTemplateException */ @Override protected Object createNewInstance(Erector erector) throws BlueprintTemplateException { SpringBlueprint springBlueprint = erector.getBlueprint().getClass().getAnnotation(SpringBlueprint.class); if (springBlueprint != null && springBlueprint.bean()) { Class beanClass = springBlueprint.beanClass(); if (beanClass.equals(NotSet.class)) { beanClass = erector.getTarget(); } try { if (StringUtils.isNotBlank(springBlueprint.beanName())) { logger.debug("Retrieving model from Spring [{},{}]", springBlueprint.beanName(), beanClass); return applicationContext.getBean(springBlueprint.beanName(), beanClass); } else { logger.debug("Retrieving model from Spring [{}]", beanClass); return applicationContext.getBean(beanClass); } } catch (NoSuchBeanDefinitionException e) { // Model not directly registered with Spring, autowire it manually. Object instance = super.createNewInstance(erector); beanFactory.autowireBean(instance); return instance; } } else { return super.createNewInstance(erector); } }
From source file:com.liferay.cli.support.util.ReflectionUtils.java
/** * Attempt to find a {@link Field field} on the supplied {@link Class} with * the supplied <code>name</code> and/or {@link Class type}. Searches all * superclasses up to {@link Object}./*ww w .j a v a2 s. c o m*/ * * @param clazz the class to introspect * @param name the name of the field (may be <code>null</code> if type is * specified) * @param type the type of the field (may be <code>null</code> if name is * specified) * @return the corresponding Field object, or <code>null</code> if not found */ public static Field findField(final Class<?> clazz, final String name, final Class<?> type) { Validate.notNull(clazz, "Class must not be null"); Validate.isTrue(name != null || type != null, "Either name or type of the field must be specified"); Class<?> searchType = clazz; while (!Object.class.equals(searchType) && searchType != null) { final Field[] fields = searchType.getDeclaredFields(); for (final Field field : fields) { if ((name == null || name.equals(field.getName())) && (type == null || type.equals(field.getType()))) { return field; } } searchType = searchType.getSuperclass(); } return null; }
From source file:com.redhat.lightblue.metadata.types.BinaryType.java
@Override public Object cast(Object obj) { byte[] ret = null; if (obj != null) { if (obj.getClass().isArray()) { Class<?> component = obj.getClass().getComponentType(); if (component.equals(byte.class)) { ret = (byte[]) obj; } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); }// w w w . java 2 s. c om } else { throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString()); } } return ret; }