本文整理汇总了Java中com.google.common.collect.Range.contains方法的典型用法代码示例。如果您正苦于以下问题:Java Range.contains方法的具体用法?Java Range.contains怎么用?Java Range.contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Range
的用法示例。
在下文中一共展示了Range.contains方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseChildList
import com.google.common.collect.Range; //导入方法依赖的package包/类
public List<T> parseChildList(Element parent, Range<Integer> count) throws InvalidXMLException {
final List<T> list = parseChildren(parent).collect(Collectors.toList());
if(count.contains(list.size())) return list;
final Optional<Integer> min = Ranges.minimum(count), max = Ranges.maximum(count);
if(!max.isPresent()) {
throw new InvalidXMLException("Expected " + min.get() + " or more child elements", parent);
} else if(!min.isPresent()) {
throw new InvalidXMLException("Expected no more than " + max.get() + " child elements", parent);
} else if(min.equals(max)) {
throw new InvalidXMLException("Expected exactly " + min.get() + " child elements", parent);
} else {
throw new InvalidXMLException("Expected between " + min.get() + " and " + max.get() + " child elements", parent);
}
}
示例2: parseNumber
import com.google.common.collect.Range; //导入方法依赖的package包/类
public static <T extends Number & Comparable<T>> T parseNumber(Node node, String text, Class<T> type, Range<T> range) throws InvalidXMLException {
T value = parseNumber(node, text, type, true);
if(!range.contains(value)) {
throw new InvalidXMLException(value + " is not in the range " + range, node);
}
return value;
}
示例3: parseRandom
import com.google.common.collect.Range; //导入方法依赖的package包/类
@MethodParser("random")
public Filter parseRandom(Element el) throws InvalidXMLException {
Node node = new Node(el);
Range<Double> chance;
try {
chance = Range.closedOpen(0d, XMLUtils.parseNumber(node, Double.class));
} catch(InvalidXMLException e) {
chance = XMLUtils.parseNumericRange(node, Double.class);
}
Range<Double> valid = Range.closed(0d, 1d);
if (valid.encloses(chance)) {
return proto.isNoOlderThan(ProtoVersions.EVENT_QUERIES) ? new RandomFilter(chance)
: new LegacyRandomFilter(chance);
} else {
double lower = chance.hasLowerBound() ? chance.lowerEndpoint() : Double.NEGATIVE_INFINITY;
double upper = chance.hasUpperBound() ? chance.upperEndpoint() : Double.POSITIVE_INFINITY;
double invalid;
if(!valid.contains(lower)) {
invalid = lower;
} else {
invalid = upper;
}
throw new InvalidXMLException("chance value (" + invalid + ") is not between 0 and 1", el);
}
}
示例4: batchGet
import com.google.common.collect.Range; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<KvPair> batchGet(List<ByteString> keys) {
TiRegion curRegion = null;
Range curKeyRange = null;
Pair<TiRegion, Store> lastPair;
List<ByteString> keyBuffer = new ArrayList<>();
List<KvPair> result = new ArrayList<>(keys.size());
for (ByteString key : keys) {
if (curRegion == null || !curKeyRange.contains(Comparables.wrap(key))) {
Pair<TiRegion, Store> pair = session.getRegionManager().getRegionStorePairByKey(key);
lastPair = pair;
curRegion = pair.first;
curKeyRange = makeRange(curRegion.getStartKey(), curRegion.getEndKey());
try (RegionStoreClient client =
RegionStoreClient.create(lastPair.first, lastPair.second, getSession())) {
List<KvPair> partialResult = client.batchGet(keyBuffer, timestamp.getVersion());
// TODO: Add lock check
result.addAll(partialResult);
} catch (Exception e) {
throw new TiClientInternalException("Error Closing Store client.", e);
}
keyBuffer = new ArrayList<>();
keyBuffer.add(key);
}
}
return result;
}
示例5: base62ToDecimal
import com.google.common.collect.Range; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Long base62ToDecimal(String base62) {
int base62Length = base62.length();
if (base62Length > BASE62_MAX_LENGTH) {
return -1L;
}
List<Range<Character>> ranges = Lists.newArrayList(Range.closed('a', 'z'),
Range.closed('0', '9'), Range.closed('A', 'Z'));
for (int i = 0; i < base62Length; i++) {
boolean status = false;
for (Range<Character> range : ranges) {
if (range.contains(base62.charAt(i))) {
status = true;
break;
}
}
if (!status) {
return -1L;
}
}
long decimal = 0L;
for (int i = 0; i < base62Length; i++) {
int num = ascii2integer(base62.charAt(i));
decimal += num * Math.pow(BASE, i);
}
return decimal;
}
示例6: selectVersion
import com.google.common.collect.Range; //导入方法依赖的package包/类
@Nonnull
private static ABIVersion selectVersion(final ConnectClientRequest message) {
final Range<ABIVersion> clientRange = Range.closed(message.getMinVersion(), message.getMaxVersion());
for (ABIVersion v : SUPPORTED_ABIVERSIONS) {
if (clientRange.contains(v)) {
return v;
}
}
throw new IllegalArgumentException(String.format(
"No common version between backend versions %s and client versions %s", SUPPORTED_ABIVERSIONS,
clientRange));
}