List of usage examples for java.lang Comparable equals
public boolean equals(Object obj)
From source file:com.apptentive.android.sdk.module.engagement.logic.ComparisonPredicate.java
@Override public boolean apply(Context context) { Log.v("Comparison Predicate: %s", query); Comparable value = getValue(context, query); Log.v(" => %s", value); for (Condition condition : conditions) { condition.operand = normalize(value, condition.operand); Log.v("-- Compare: %s %s %s", getLoggableValue(value), condition.operation, getLoggableValue(condition.operand)); switch (condition.operation) { case $gt: { if (value == null) { return false; }/*from w w w . j a v a 2s. c o m*/ if (condition.operand instanceof Comparable) { Comparable operand = (Comparable) condition.operand; if (!(value.compareTo(operand) > 0)) { return false; } } else { throw new IllegalArgumentException( String.format("Can't compare %s > %s", value, condition.operand)); } break; } case $gte: { if (value == null) { return false; } if (condition.operand instanceof Comparable) { Comparable operand = (Comparable) condition.operand; if (!(value.compareTo(operand) >= 0)) { return false; } } else { throw new IllegalArgumentException( String.format("Can't compare %s >= %s", value, condition.operand)); } break; } case $eq: { if (value == null) { return false; } if (condition.operand instanceof Comparable) { Comparable operand = (Comparable) condition.operand; if (!value.equals(operand)) { return false; } } else { throw new IllegalArgumentException( String.format("Can't compare %s == %s", value, condition.operand)); } break; } case $ne: { if (value == null) { return false; } if (condition.operand instanceof Comparable) { Comparable operand = (Comparable) condition.operand; if (value.equals(operand)) { return false; } } else { throw new IllegalArgumentException( String.format("Can't compare %s != %s", value, condition.operand)); } break; } case $lte: { if (value == null) { return false; } if (condition.operand instanceof Comparable) { Comparable operand = (Comparable) condition.operand; if (!(value.compareTo(operand) <= 0)) { return false; } } else { throw new IllegalArgumentException( String.format("Can't compare %s <= %s", value, condition.operand)); } break; } case $lt: { if (value == null) { return false; } if (condition.operand instanceof Comparable) { Comparable operand = (Comparable) condition.operand; if (!(value.compareTo(operand) < 0)) { return false; } } else { throw new IllegalArgumentException( String.format("Can't compare %s < %s", value, condition.operand)); } break; } case $exists: { if (!(condition.operand instanceof Boolean)) { throw new IllegalArgumentException( String.format("Argument %s is not a boolean", condition.operand)); } boolean shouldExist = (Boolean) condition.operand; boolean exists = value != null; return exists == shouldExist; } case $contains: { if (value == null) { return false; } boolean ret = false; if (value instanceof String && condition.operand instanceof String) { ret = ((String) value).toLowerCase().contains(((String) condition.operand).toLowerCase()); } return ret; } case $starts_with: { if (value == null) { return false; } boolean ret = false; if (value instanceof String && condition.operand instanceof String) { ret = ((String) value).toLowerCase().startsWith(((String) condition.operand).toLowerCase()); } return ret; } case $ends_with: { if (value == null) { return false; } boolean ret = false; if (value instanceof String && condition.operand instanceof String) { ret = ((String) value).toLowerCase().endsWith(((String) condition.operand).toLowerCase()); } return ret; } default: break; } } return true; }
From source file:jetbrains.exodus.entitystore.PersistentEntityStoreImpl.java
public boolean setProperty(@NotNull final PersistentStoreTransaction txn, @NotNull final PersistentEntity entity, @NotNull final String propertyName, @NotNull final Comparable value) { final int propertyId = getPropertyId(txn, propertyName, true); final ByteIterable oldValueEntry = getRawProperty(txn, entity, propertyId); final Comparable oldValue = oldValueEntry == null ? null : propertyTypes.entryToPropertyValue(oldValueEntry).getData(); if (value.equals(oldValue)) { // value is not null by contract return false; }// w ww . j ava 2s. c om final PersistentEntityId entityId = entity.getId(); final PropertyValue propValue = propertyTypes.dataToPropertyValue(value); getPropertiesTable(txn, entityId.getTypeId()).put(txn, entityId.getLocalId(), PropertyTypes.propertyValueToEntry(propValue), oldValueEntry, propertyId, propValue.getType()); txn.propertyChanged(entityId, propertyId, oldValue, value); return true; }
From source file:org.ojbc.bundles.adapters.staticmock.StaticMockQuery.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private boolean checkRange(Document personSearchRequestMessage, Comparable valueParam, Comparable minValueParam, Comparable maxValueParam, Comparable documentValue) throws Exception { if (valueParam == null && minValueParam == null && maxValueParam == null) { // skipping this query parameter return true; }// ww w.java2 s . c o m if (valueParam != null) { // single-value test return valueParam.equals(documentValue); } else { // range test return minValueParam.compareTo(documentValue) != 1 && documentValue.compareTo(maxValueParam) != 1; } }