List of usage examples for org.springframework.util ObjectUtils nullSafeEquals
public static boolean nullSafeEquals(@Nullable Object o1, @Nullable Object o2)
From source file:example.app.model.Contact.java
@Override public boolean equals(Object obj) { if (obj == this) { return true; }//from ww w .ja v a2s.c o m if (!(obj instanceof Contact)) { return false; } Contact that = (Contact) obj; return ObjectUtils.nullSafeEquals(this.getPerson(), that.getPerson()) && ObjectUtils.nullSafeEquals(this.getAddress(), that.getAddress()) && ObjectUtils.nullSafeEquals(this.getEmail(), that.getEmail()) && ObjectUtils.nullSafeEquals(this.getPhoneNumber(), that.getPhoneNumber()); }
From source file:com.turbospaces.spaces.tx.TransactionModificationContext.java
/** * get byte array pointer associated with write/take for the given key if any or fetch byte array pointer from index * manager (if there is no direct key association with-in transaction). * //from w ww . j a v a2 s . c om * @param key * primary key lock guardian * @param indexManager * space index manager * @return byte array pointer or <code>null</code> */ public ByteBuffer getPointerData(final Object key, final IndexManager indexManager) { if (!getTakes().isEmpty()) for (EntryKeyLockQuard keyGuard : getTakes().keySet()) if (ObjectUtils.nullSafeEquals(keyGuard.getKey(), key)) return null; if (!getWrites().isEmpty()) for (Entry<EntryKeyLockQuard, WriteTakeEntry> next : getWrites().entrySet()) if (ObjectUtils.nullSafeEquals(next.getKey().getKey(), key)) return next.getValue().getPointer().getSerializedDataBuffer(); return (ByteBuffer) indexManager.getByUniqueIdentifier(key, false); }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.resources.jdbc.Connection.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }/*from w w w. ja v a 2s . c om*/ if (!(obj instanceof Connection)) { return false; } Connection connection = (Connection) obj; return ObjectUtils.nullSafeEquals(this.getConnectionProperties(), connection.getConnectionProperties()) && ObjectUtils.nullSafeEquals(this.getDriverClassName(), connection.getDriverClassName()) && ObjectUtils.nullSafeEquals(this.getPassword(), connection.getPassword()) && ObjectUtils.nullSafeEquals(this.getUrl(), connection.getUrl()) && ObjectUtils.nullSafeEquals(this.getUsername(), connection.getUsername()); }
From source file:com.opengamma.language.definition.JavaTypeInfo.java
@Override public boolean equals(final Object o) { if (o == this) { return true; }/*from www. j a v a 2 s.c o m*/ if (!(o instanceof JavaTypeInfo<?>)) { return false; } final JavaTypeInfo<?> other = (JavaTypeInfo<?>) o; if (getRawClass() != other.getRawClass()) { return false; } if (isAllowNull() != other.isAllowNull()) { return false; } if (isDefaultValue()) { if (other.isDefaultValue()) { if (!ObjectUtils.nullSafeEquals(getDefaultValue(), other.getDefaultValue())) { return false; } } else { return false; } } else { if (other.isDefaultValue()) { return false; } } if (_parameter == null) { if (other._parameter != null) { return false; } } else { if (other._parameter == null) { return false; } if (!Arrays.equals(_parameter, other._parameter)) { return false; } } return true; }
From source file:org.hdiv.web.servlet.tags.form.SelectedValueComparatorHDIV.java
private static boolean exhaustiveCompare(Object boundValue, Object candidate, PropertyEditor editor, Map<PropertyEditor, Object> convertedValueCache) { String candidateDisplayString = ValueFormatterHDIV.getDisplayString(candidate, editor, false); if (boundValue instanceof LabeledEnum) { LabeledEnum labeledEnum = (LabeledEnum) boundValue; String enumCodeAsString = ObjectUtils.getDisplayString(labeledEnum.getCode()); if (enumCodeAsString.equals(candidateDisplayString)) { return true; }/*from w w w .j a va 2s .c o m*/ String enumLabelAsString = ObjectUtils.getDisplayString(labeledEnum.getLabel()); if (enumLabelAsString.equals(candidateDisplayString)) { return true; } } else if (boundValue.getClass().isEnum()) { Enum boundEnum = (Enum) boundValue; String enumCodeAsString = ObjectUtils.getDisplayString(boundEnum.name()); if (enumCodeAsString.equals(candidateDisplayString)) { return true; } String enumLabelAsString = ObjectUtils.getDisplayString(boundEnum.toString()); if (enumLabelAsString.equals(candidateDisplayString)) { return true; } } else if (ObjectUtils.getDisplayString(boundValue).equals(candidateDisplayString)) { return true; } else if (editor != null && candidate instanceof String) { // Try PE-based comparison (PE should *not* be allowed to escape creating thread) String candidateAsString = (String) candidate; Object candidateAsValue; if (convertedValueCache != null && convertedValueCache.containsKey(editor)) { candidateAsValue = convertedValueCache.get(editor); } else { editor.setAsText(candidateAsString); candidateAsValue = editor.getValue(); if (convertedValueCache != null) { convertedValueCache.put(editor, candidateAsValue); } } if (ObjectUtils.nullSafeEquals(boundValue, candidateAsValue)) { return true; } } return false; }
From source file:com.frank.search.solr.core.query.result.SolrResultPage.java
@Override public List<HighlightEntry.Highlight> getHighlights(T entity) { if (entity != null && this.highlighted != null) { for (HighlightEntry<T> highlightEntry : this.highlighted) { if (highlightEntry != null && ObjectUtils.nullSafeEquals(highlightEntry.getEntity(), entity)) { return highlightEntry.getHighlights(); }// w w w.ja v a2s . c om } } return Collections.emptyList(); }
From source file:org.wallride.service.UserService.java
@CacheEvict(value = WallRideCacheConfiguration.USER_CACHE, allEntries = true) public User updateProfile(ProfileUpdateRequest request, AuthorizedUser updatedBy) { User user = userRepository.findOneForUpdateById(request.getUserId()); if (user == null) { throw new IllegalArgumentException("The user does not exist"); }//from ww w . j a v a 2 s . co m User duplicate; if (!ObjectUtils.nullSafeEquals(request.getEmail(), user.getEmail())) { duplicate = userRepository.findOneByEmail(request.getEmail()); if (duplicate != null) { throw new DuplicateEmailException(request.getEmail()); } } if (!ObjectUtils.nullSafeEquals(request.getLoginId(), user.getLoginId())) { duplicate = userRepository.findOneByLoginId(request.getLoginId()); if (duplicate != null) { throw new DuplicateLoginIdException(request.getLoginId()); } } user.setEmail(request.getEmail()); user.setLoginId(request.getLoginId()); user.setName(request.getName()); user.setUpdatedAt(LocalDateTime.now()); user.setUpdatedBy(updatedBy.toString()); return userRepository.saveAndFlush(user); }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.services.engine.Host.java
public void validate(Object target, Errors errors) { Host host = (Host) target;/*from w ww. j a v a 2s. c om*/ if (!errors.hasFieldErrors("name")) { if (!StringUtils.hasText(host.getName())) { errors.rejectValue("name", "service.engine.host.name.required"); } else { if (host.parent() != null) { // detect duplicate host names Service service = host.parent().parent(); for (Host h : service.getEngine().getHosts()) { if (h != host && ObjectUtils.nullSafeEquals(host.getName(), h.getName())) { errors.reject("service.engine.host.name.unique", new Object[] { host.getName(), service.getName() }, null); } } } } } if (!errors.hasFieldErrors("appBase")) { if (!StringUtils.hasText(host.getAppBase())) { errors.rejectValue("appBase", "service.engine.host.appBase.required"); } } errors.pushNestedPath("logging"); host.getLogging().validate(host.getLogging(), errors); errors.popNestedPath(); }
From source file:com.brienwheeler.lib.spring.beans.PropertyPlaceholderConfigurer.java
/** * Resolves any placeholders in the supplied properties map, preferring the use of * previously set System properties over the current property map contents for * placeholder substitution.//from w w w . j a va2 s. c om * <p> * Also sets any resolved properties as System properties, if no System * property by that name already exists. * * @param properties the merged context properties */ public static void processProperties(final Properties properties, String placeholderPrefix, String placeholderSuffix) { PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix); PropertyPlaceholderHelper.PlaceholderResolver resolver = new PropertyPlaceholderHelper.PlaceholderResolver() { @Override public String resolvePlaceholder(String placeholderName) { // SYSTEM_PROPERTIES_MODE_OVERRIDE means we look at previously set // system properties in preference to properties defined in our file String value = System.getProperty(placeholderName); if (value == null) value = properties.getProperty(placeholderName); return value; } }; for (Object key : properties.keySet()) { String propertyName = (String) key; // get the value from the map String propertyValue = properties.getProperty(propertyName); // resolve it against system properties then other properties in the // passed-in Properties String resolvedValue = helper.replacePlaceholders(propertyValue, resolver); // set back into passed-in Properties if changed if (!ObjectUtils.nullSafeEquals(propertyValue, resolvedValue)) { properties.setProperty(propertyName, resolvedValue); } // set into System properties if not already set setProperty(propertyName, resolvedValue); } }
From source file:org.guicerecipes.spring.testbeans.TestBean.java
@Override public boolean equals(Object other) { if (this == other) { return true; }/*w w w .j a va 2 s . co m*/ if ((other == null) || !(other instanceof TestBean)) { return false; } TestBean tb2 = (TestBean) other; return (ObjectUtils.nullSafeEquals(name, tb2.name) && (age == tb2.age)); }