/** * Determine two values of any type equal * @param first is actual value * @param second is value in query condition * @return true if equal, otherwise false */ protected static boolean equals(final Object first, final Object second) { if (first == null) { return second == null; } else if (first instanceof Id) { if (second instanceof String) { return second.equals(((Id) first).asString()); } else if (second instanceof Long) { return second.equals(((Id) first).asLong()); } } else if (first instanceof Number || second instanceof Number) { return compare(first, second) == 0; } return first.equals(second); }
@Override public boolean equals(Object object) { if (!(object instanceof Relation)) { return false; } Relation other = (Relation) object; return this.relation().equals(other.relation()) && this.key().equals(other.key()) && this.value().equals(other.value()); }
@Override public int hashCode() { return this.type().hashCode() ^ this.relation().hashCode() ^ this.key().hashCode() ^ this.value().hashCode(); }
private static Set<IndexLabel> matchRangeOrSearchIndexLabels( ConditionQuery query, Set<IndexLabel> indexLabels) { Set<IndexLabel> matchedIndexLabels = InsertionOrderUtil.newSet(); for (Condition.Relation relation : query.userpropRelations()) { if (!relation.relation().isRangeType() && !relation.relation().isSearchType()) { continue; } Id key = (Id) relation.key(); boolean matched = false; for (IndexLabel indexLabel : indexLabels) { if (indexLabel.indexType() == IndexType.RANGE || indexLabel.indexType() == IndexType.SEARCH) { if (indexLabel.indexField().equals(key)) { matched = true; matchedIndexLabels.add(indexLabel); break; } } } if (!matched) { return ImmutableSet.of(); } } return matchedIndexLabels; }
/** * Determine two values of any type equal * @param first is actual value * @param second is value in query condition * @return true if equal, otherwise false */ protected static boolean equals(final Object first, final Object second) { if (first == null) { return second == null; } else if (first instanceof Id) { if (second instanceof String) { return second.equals(((Id) first).asString()); } else if (second instanceof Long) { return second.equals(((Id) first).asLong()); } } else if (first instanceof Number || second instanceof Number) { return compare(first, second) == 0; } return first.equals(second); }
/** * Determine two numbers equal * @param first is actual value, might be Number/Date or String, It is * probably that the `first` is serialized to String. * @param second is value in query condition, must be Number/Date * @return the value 0 if first is numerically equal to second; * a value less than 0 if first is numerically less than * second; and a value greater than 0 if first is * numerically greater than second. */ protected static int compare(final Object first, final Object second) { if (second instanceof Number) { return NumericUtil.compareNumber(first, (Number) second); } else if (second instanceof Date) { return compareDate(first, (Date) second); } else { throw new BackendException("Can't compare between %s and %s", first, second); } }
@Override public boolean test(Object value) { return this.relation.test(value, this.value); }
public boolean containsCondition(HugeKeys key, Condition.RelationType type) { for (Relation r : this.relations()) { if (r.key().equals(key) && r.relation().equals(type)) { return true; } } return false; }
public boolean containsCondition(Condition.RelationType type) { for (Relation r : this.relations()) { if (r.relation().equals(type)) { return true; } } return false; }
@Override public boolean test(HugeElement element) { if (this.relation == RelationType.SCAN) { return true; } Object value = element.sysprop(this.key); return this.relation.test(value, this.value); }
public boolean hasSecondaryCondition() { // NOTE: we need to judge all the conditions, including the nested for (Condition.Relation r : this.relations()) { if (r.relation().isSecondaryType()) { return true; } } return false; }
@Override public boolean equals(Object object) { if (!(object instanceof Relation)) { return false; } Relation other = (Relation) object; return this.relation().equals(other.relation()) && this.key().equals(other.key()) && this.value().equals(other.value()); }
@Override public boolean test(Object first, Object second) { E.checkState(this.tester != null, "Can't test %s", this.name()); return this.tester.apply(first, second); }
public boolean hasSearchCondition() { // NOTE: we need to judge all the conditions, including the nested for (Condition.Relation r : this.relations()) { if (r.relation().isSearchType()) { return true; } } return false; }
@Override public boolean test(HugeElement element) { HugeProperty<?> prop = element.getProperty(this.key()); Object value = prop != null ? prop.value() : null; return this.relation.test(value, this.value); }
@Override public String toString() { return String.format("%s %s %s", this.key(), this.relation.string(), this.value); }
public boolean hasRangeCondition() { // NOTE: we need to judge all the conditions, including the nested for (Condition.Relation r : this.relations()) { if (r.relation().isRangeType()) { return true; } } return false; }
@Override public int hashCode() { return this.type().hashCode() ^ this.relation().hashCode() ^ this.key().hashCode() ^ this.value().hashCode(); }
private static Set<IndexLabel> matchRangeOrSearchIndexLabels( ConditionQuery query, Set<IndexLabel> indexLabels) { Set<IndexLabel> matchedIndexLabels = InsertionOrderUtil.newSet(); for (Condition.Relation relation : query.userpropRelations()) { if (!relation.relation().isRangeType() && !relation.relation().isSearchType()) { continue; } Id key = (Id) relation.key(); boolean matched = false; for (IndexLabel indexLabel : indexLabels) { if (indexLabel.indexType() == IndexType.RANGE || indexLabel.indexType() == IndexType.SEARCH) { if (indexLabel.indexField().equals(key)) { matched = true; matchedIndexLabels.add(indexLabel); break; } } } if (!matched) { return ImmutableSet.of(); } } return matchedIndexLabels; }
/** * Determine two numbers equal * @param first is actual value, might be Number/Date or String, It is * probably that the `first` is serialized to String. * @param second is value in query condition, must be Number/Date * @return the value 0 if first is numerically equal to second; * a value less than 0 if first is numerically less than * second; and a value greater than 0 if first is * numerically greater than second. */ protected static int compare(final Object first, final Object second) { if (second instanceof Number) { return NumericUtil.compareNumber(first, (Number) second); } else if (second instanceof Date) { return compareDate(first, (Date) second); } else { throw new BackendException("Can't compare between %s and %s", first, second); } }