Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.jdbc.internal.common.predicate;
import com.facebook.presto.jdbc.internal.common.Utils;
import com.facebook.presto.jdbc.internal.common.block.Block;
import com.facebook.presto.jdbc.internal.common.function.SqlFunctionProperties;
import com.facebook.presto.jdbc.internal.common.type.Type;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonCreator;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonProperty;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.facebook.presto.jdbc.internal.common.type.IntegerType.INTEGER;
import static java.util.Collections.singleton;
import static java.util.Collections.unmodifiableCollection;
import static java.util.Collections.unmodifiableSet;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toCollection;
import static java.util.stream.Collectors.toList;
/**
* A set containing values that are uniquely identifiable.
* Assumes an infinite number of possible values. The values may be collectively included (aka whitelist)
* or collectively excluded (aka !whitelist).
*/
public class EquatableValueSet
implements ValueSet
{
private final Type type;
private final boolean whiteList;
private final Set entries;
@JsonCreator
public EquatableValueSet(
@JsonProperty("type") Type type,
@JsonProperty("whiteList") boolean whiteList,
@JsonProperty("entries") Set 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 = unmodifiableSet(new LinkedHashSet<>(entries));
}
static EquatableValueSet none(Type type)
{
return new EquatableValueSet(type, true, Collections.emptySet());
}
static EquatableValueSet all(Type type)
{
return new EquatableValueSet(type, false, Collections.emptySet());
}
static EquatableValueSet of(Type type, Object first, Object... rest)
{
HashSet set = new LinkedHashSet<>(rest.length + 1);
set.add(ValueEntry.create(type, first));
for (Object value : rest) {
set.add(ValueEntry.create(type, value));
}
return new EquatableValueSet(type, true, set);
}
static EquatableValueSet copyOf(Type type, Collection> values)
{
return new EquatableValueSet(type, true, values.stream()
.map(value -> ValueEntry.create(type, value))
.collect(toLinkedSet()));
}
@JsonProperty
@Override
public Type getType()
{
return type;
}
@JsonProperty
public boolean isWhiteList()
{
return whiteList;
}
@JsonProperty
public Set getEntries()
{
return entries;
}
public Collection