List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:com.qcadoo.model.internal.validators.ScaleValidator.java
@Override public boolean call(final Entity entity, final Object oldValue, final Object newValue) { if (newValue == null) { return true; }/*from w w w . j ava2 s. c o m*/ Class<?> fieldClass = fieldDefinition.getType().getType(); if (!fieldClass.equals(BigDecimal.class)) { return true; } return validateScale(fieldDefinition, newValue, entity); }
From source file:com.youtube.processor.YoutubeTypeConverter.java
private Object deserializeItem(Object item) { try {//from w w w .j a v a 2 s . co m Class klass = YoutubeEventClassifier.detectClass((String) item); if (klass.equals(Video.class)) { item = mapper.readValue((String) item, Video.class); } else if (klass.equals(Channel.class)) { item = mapper.readValue((String) item, Channel.class); } } catch (Exception e) { LOGGER.error("Exception while trying to deserializeItem: {}", e); } return item; }
From source file:org.sventon.web.command.ConfigCommandValidator.java
@Override public boolean supports(final Class clazz) { return clazz.equals(ConfigCommand.class); }
From source file:eu.eubrazilcc.lvl.core.xml.PubMedXmlBinder.java
@Override @SuppressWarnings("unchecked") protected <T> JAXBElement<T> createType(final T obj) { Object element = null;/*from www .j av a2 s .c o m*/ Class<? extends Object> clazz = obj.getClass(); if (clazz.equals(PubmedArticleSet.class)) { element = PUBMED_XML_FACTORY.createPubmedArticleSet(); } else if (clazz.equals(PubmedArticle.class)) { element = PUBMED_XML_FACTORY.createPubmedArticle(); } else { throw new IllegalArgumentException("Unsupported type: " + clazz.getCanonicalName()); } return (JAXBElement<T>) element; }
From source file:net.sourceforge.fenixedu.domain.cms.UnitClassTemplateController.java
/** * @param units/*w w w .j a v a2 s. com*/ * @return one of the AcceptableTypes on 'units' or null if there is none */ private Unit findCorrectUnit(final List<Unit> units) { Unit unitOfGivinType = null; for (final Unit unit : units) { for (final Class<?> clazz : getAcceptableTypes()) { if (clazz.equals(unit.getClass())) { if (unitOfGivinType == null) { unitOfGivinType = unit; } else { return null; } } } } return unitOfGivinType; }
From source file:mercury.RootJsonHandler.java
protected <T extends DTO> T populateDtoFromJson(String jsonData, T dto) { try {//from w ww .j a va2s .c o m JSONObject json = new JSONObject(jsonData); Class clazz = dto.getClass(); for (Field field : clazz.getDeclaredFields()) { try { String name = field.getName(); Class fieldClass = field.getType(); Object value = null; if (fieldClass.equals(String.class)) { value = json.has(name) ? json.getString(name) : null; } else if (fieldClass.equals(Integer.class)) { try { value = json.has(name) ? json.getInt(name) : null; } catch (Exception e) { value = -1; } } else if (fieldClass.equals(Float.class)) { String sValue = json.has(name) ? json.getString(name).replaceAll(",", ".") : null; value = sValue != null ? Float.valueOf(sValue) : null; } else if (fieldClass.equals(Date.class)) { value = json.has(name) ? json.getString(name) : null; value = value != null ? this.dateFormatter.parse((String) value) : null; } if (value == null) { continue; } Method setter = clazz.getDeclaredMethod("set" + StringUtils.capitalize(name), fieldClass); if (setter != null) { setter.invoke(dto, value); } } catch (Exception e) { continue; } } } catch (JSONException je) { } return dto; }
From source file:cn.powerdash.libsystem.common.exception.BeanValidatorExceptionHandler.java
/** * /*from ww w. j a v a 2s . co m*/ * Description: set the validation data. * * @param constraintsViolatioins * @param handler * @param formId * @param error */ @Override protected void setValidationErrorData(final Exception ex, final Object handler, final String formId, ResultDto<List<ValidationResultDto>> error) { ConstraintViolationException vex = (ConstraintViolationException) ex; Set<ConstraintViolation<?>> constraintsViolatioins = vex.getConstraintViolations(); final List<ValidationResultDto> errorData = error.getData(); if (StringUtils.isNotEmpty(formId) && constraintsViolatioins != null && constraintsViolatioins.size() > 0 && handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; // method parameter arrays MethodParameter[] methodParameters = handlerMethod.getMethodParameters(); if (methodParameters != null && methodParameters.length > 0 && !ApplicationConstant.MANUAL_VALIDATE.equals(vex.getMessage())) { for (ConstraintViolation<?> constraintViolation : constraintsViolatioins) { Class<?> doaminClass = constraintViolation.getRootBeanClass(); for (MethodParameter methodParameter : methodParameters) { Class<?> dtoClass = methodParameter.getParameterType(); if (!dtoClass.equals(doaminClass)) { continue; } else if (doaminClass.equals(dtoClass)) { setResultDto(constraintViolation, errorData, formId, false); } } } } else { for (ConstraintViolation<?> constraintViolation : constraintsViolatioins) { setResultDto(constraintViolation, errorData, formId, true); } } } }
From source file:com.qcadoo.model.internal.validators.UnscaledValueValidator.java
@Override public boolean call(final Entity entity, final Object oldValue, final Object newValue) { if (newValue == null) { return true; }/*www . j a v a2 s .c om*/ Class<?> fieldClass = fieldDefinition.getType().getType(); if (!(fieldClass.equals(Integer.class) || fieldClass.equals(BigDecimal.class))) { return true; } if (fieldClass.equals(BigDecimal.class)) { return validatePresicion(fieldDefinition, entity, ((BigDecimal) newValue).precision() - ((BigDecimal) newValue).scale()); } else { return validatePresicion(fieldDefinition, entity, newValue.toString().length()); } }
From source file:org.mitre.swd.view.SwdResponse.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {/* w w w . j av a2s.co m*/ Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes f) { return false; } @Override public boolean shouldSkipClass(Class<?> clazz) { // skip the JPA binding wrapper if (clazz.equals(BeanPropertyBindingResult.class)) { return true; } else { return false; } } }).create(); response.setContentType("application/json"); Object obj = model.get("entity"); if (obj == null) { obj = model; } Writer out; try { out = response.getWriter(); gson.toJson(obj, out); } catch (IOException e) { logger.error("IOException in SwdResponse.java: ", e); } }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.ProtocolSupportValidator.java
@Override public boolean isValid(String object, ConstraintValidatorContext constraintContext) { ConstraintValidatorContextImpl x = (ConstraintValidatorContextImpl) constraintContext; Class<?> owner = x.getValidationContext().getCurrentOwner(); List<String> protocols = null; if (owner.equals(TrustedIdpEntity.class)) { protocols = trustedIdpProtocolHandlers.getProtocols(); } else if (owner.equals(ApplicationEntity.class)) { protocols = applicationProtocolHandlers.getProtocols(); } else {//from www .j a v a 2 s.c o m LOG.warn("Invalid owner {}. Ignoring validation.", owner.getCanonicalName()); return true; } for (String protocol : protocols) { if (protocol.equals(object)) { return true; } } return false; }