@Override public boolean isComparable() { return elementType.isComparable(); }
@Override public boolean isComparable() { return valueType.isComparable(); }
@Override public boolean isComparable() { return fields.stream().allMatch(field -> field.getType().isComparable()); }
@JsonCreator public EquatableValueSet( @JsonProperty("type") Type type, @JsonProperty("whiteList") boolean whiteList, @JsonProperty("entries") Set<ValueEntry> entries) { requireNonNull(type, "type is null"); requireNonNull(entries, "entries is null"); if (!type.isComparable()) { throw new IllegalArgumentException("Type is not comparable: " + type); } if (type.isOrderable()) { throw new IllegalArgumentException("Use SortedRangeSet instead"); } this.type = type; this.whiteList = whiteList; this.entries = Collections.unmodifiableSet(new HashSet<>(entries)); }
static ValueSet copyOf(Type type, Collection<Object> values) { if (type.isOrderable()) { return SortedRangeSet.copyOf(type, values.stream() .map(value -> Range.equal(type, value)) .collect(toList())); } if (type.isComparable()) { return EquatableValueSet.copyOf(type, values); } throw new IllegalArgumentException("Cannot create discrete ValueSet with non-comparable type: " + type); }
public ClassifierType(Type type) { super(new TypeSignature(ClassifierParametricType.NAME, TypeSignatureParameter.of(type.getTypeSignature()))); checkArgument(type.isComparable(), "type must be comparable"); labelType = type; }
static ValueSet of(Type type, Object first, Object... rest) { if (type.isOrderable()) { return SortedRangeSet.of(type, first, rest); } if (type.isComparable()) { return EquatableValueSet.of(type, first, rest); } throw new IllegalArgumentException("Cannot create discrete ValueSet with non-comparable type: " + type); }
public boolean canBind(Type type) { if (comparableRequired && !type.isComparable()) { return false; } if (orderableRequired && !type.isOrderable()) { return false; } if (variadicBound != null && !type.getTypeSignature().getBase().equals(variadicBound)) { return false; } return true; }
public boolean canBind(Type type) { if (comparableRequired && !type.isComparable()) { return false; } if (orderableRequired && !type.isOrderable()) { return false; } if (variadicBound != null && !type.getTypeSignature().getBase().equals(variadicBound)) { return false; } return true; }
private boolean satisfiesConstraints(Type type) { if (comparableRequired && !type.isComparable()) { return false; } if (orderableRequired && !type.isOrderable()) { return false; } if (requiredBaseName.isPresent() && !UNKNOWN.equals(type) && !requiredBaseName.get().equals(type.getTypeSignature().getBase())) { // TODO: the case below should be properly handled: // * `type` does not have the `requiredBaseName` but can be coerced to some type that has the `requiredBaseName`. return false; } return true; } }
private boolean satisfiesConstraints(Type type) { if (comparableRequired && !type.isComparable()) { return false; } if (orderableRequired && !type.isOrderable()) { return false; } if (requiredBaseName.isPresent() && !UNKNOWN.equals(type) && !requiredBaseName.get().equals(type.getTypeSignature().getBase())) { // TODO: the case below should be properly handled: // * `type` does not have the `requiredBaseName` but can be coerced to some type that has the `requiredBaseName`. return false; } return true; } }
private boolean checkAllEquatableTypes(AggregateInfo aggregateInfo) { for (Symbol symbol : aggregateInfo.getOriginalNonDistinctAggregateArgs()) { Type type = symbolAllocator.getTypes().get(symbol); if (!type.isComparable()) { return false; } } if (!symbolAllocator.getTypes().get(aggregateInfo.getMask()).isComparable()) { return false; } return true; }
private boolean checkAllEquatableTypes(AggregateInfo aggregateInfo) { for (Symbol symbol : aggregateInfo.getOriginalNonDistinctAggregateArgs()) { Type type = symbolAllocator.getTypes().get(symbol); if (!type.isComparable()) { return false; } } if (!symbolAllocator.getTypes().get(aggregateInfo.getMask()).isComparable()) { return false; } return true; }
static ValueSet none(Type type) { if (type.isOrderable()) { return SortedRangeSet.none(type); } if (type.isComparable()) { return EquatableValueSet.none(type); } return AllOrNoneValueSet.none(type); }
static ValueSet all(Type type) { if (type.isOrderable()) { return SortedRangeSet.all(type); } if (type.isComparable()) { return EquatableValueSet.all(type); } return AllOrNoneValueSet.all(type); }
private static void addTypeRow(Builder builder, Type type) { builder.addRow( type.getDisplayName(), jdbcDataType(type), columnSize(type), null, null, null, DatabaseMetaData.typeNullable, false, type.isComparable() ? DatabaseMetaData.typeSearchable : DatabaseMetaData.typePredNone, null, false, null, null, 0, 0, null, null, numPrecRadix(type)); }
@Test public void testOperatorsImplemented() { for (Type type : typeRegistry.getTypes()) { if (type.isComparable()) { functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(NOT_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); functionRegistry.resolveOperator(HASH_CODE, ImmutableList.of(type)); } if (type.isOrderable()) { functionRegistry.resolveOperator(LESS_THAN, ImmutableList.of(type, type)); functionRegistry.resolveOperator(LESS_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN, ImmutableList.of(type, type)); } } }
@Test public void testOperatorsImplemented() { for (Type type : typeRegistry.getTypes()) { if (type.isComparable()) { functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(NOT_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); functionRegistry.resolveOperator(HASH_CODE, ImmutableList.of(type)); } if (type.isOrderable()) { functionRegistry.resolveOperator(LESS_THAN, ImmutableList.of(type, type)); functionRegistry.resolveOperator(LESS_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN, ImmutableList.of(type, type)); } } }
protected void assertPositionEquals(Block block, int position, Object expectedStackValue, Object expectedObjectValue) { long hash = 0; if (type.isComparable()) { hash = hashPosition(type, block, position); } assertPositionValue(block, position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, 1), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedStackValue, hash, expectedObjectValue); BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); type.appendTo(block, position, blockBuilder); assertPositionValue(blockBuilder.build(), 0, expectedStackValue, hash, expectedObjectValue); }
protected void assertPositionEquals(Block block, int position, Object expectedStackValue, Object expectedObjectValue) { long hash = 0; if (type.isComparable()) { hash = hashPosition(type, block, position); } assertPositionValue(block, position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, 1), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedStackValue, hash, expectedObjectValue); BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); type.appendTo(block, position, blockBuilder); assertPositionValue(blockBuilder.build(), 0, expectedStackValue, hash, expectedObjectValue); }