本文整理匯總了Java中com.google.common.collect.Range.hasUpperBound方法的典型用法代碼示例。如果您正苦於以下問題:Java Range.hasUpperBound方法的具體用法?Java Range.hasUpperBound怎麽用?Java Range.hasUpperBound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Range
的用法示例。
在下文中一共展示了Range.hasUpperBound方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writable
import com.google.common.collect.Range; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> Range<Comparable<Object>> writable(TypeAdapter<T> adapter, Range<T> range) {
if (range.hasLowerBound() && range.hasUpperBound()) {
return Range.range(
(Comparable<Object>) writable(adapter, range.lowerEndpoint()),
range.lowerBoundType(),
(Comparable<Object>) writable(adapter, range.upperEndpoint()),
range.upperBoundType());
} else if (range.hasLowerBound()) {
return Range.downTo(
(Comparable<Object>) writable(adapter, range.lowerEndpoint()),
range.lowerBoundType());
} else if (range.hasUpperBound()) {
return Range.upTo(
(Comparable<Object>) writable(adapter, range.upperEndpoint()),
range.upperBoundType());
}
throw new AssertionError();
}
示例2: parseKillStreak
import com.google.common.collect.Range; //導入方法依賴的package包/類
@MethodParser("kill-streak")
public KillStreakFilter parseKillStreak(Element el) throws InvalidXMLException {
boolean repeat = XMLUtils.parseBoolean(el.getAttribute("repeat"), false);
boolean persistent = XMLUtils.parseBoolean(el.getAttribute("persistent"), false);
Integer count = XMLUtils.parseNumber(el.getAttribute("count"), Integer.class, (Integer) null);
Integer min = XMLUtils.parseNumber(el.getAttribute("min"), Integer.class, (Integer) null);
Integer max = XMLUtils.parseNumber(el.getAttribute("max"), Integer.class, (Integer) null);
Range<Integer> range;
if(count != null) {
range = Range.singleton(count);
} else if(min == null) {
if(max == null) {
throw new InvalidXMLException("kill-streak filter must have a count, min, or max", el);
} else {
range = Range.atMost(max);
}
} else {
if(max == null) {
range = Range.atLeast(min);
} else {
range = Range.closed(min, max);
}
}
if(repeat && !range.hasUpperBound()) {
throw new InvalidXMLException("repeating kill-streak filter must have a count or max", el);
}
return new KillStreakFilter(range, repeat, persistent);
}
示例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: describe
import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
* Return an english phrase describing the given {@link Range} e.g.
*
* Range.all() -> "unbounded"
* Range.singleton(3) -> "3"
* Range.atLeast(3) -> "at least 3"
* Range.closedOpen(3, 7) -> "at least 3 and less than 7"
* Range.closed(3, 7) -> "between 3 and 7"
*/
public static String describe(Range<?> range) {
if(range.hasLowerBound() && range.hasUpperBound() && range.lowerBoundType() == BoundType.CLOSED && range.upperBoundType() == BoundType.CLOSED) {
if(range.lowerEndpoint().equals(range.upperEndpoint())) {
// singleton
return range.lowerEndpoint().toString();
} else {
// closed-closed
return "between " + range.lowerEndpoint() + " and " + range.upperEndpoint();
}
}
final List<String> parts = new ArrayList<>(2);
if(range.hasLowerBound()) {
parts.add((range.lowerBoundType() == BoundType.CLOSED ? "at least " : "more than ") + range.lowerEndpoint());
}
if(range.hasUpperBound()) {
parts.add((range.upperBoundType() == BoundType.CLOSED ? "at most " : "less than ") + range.upperEndpoint());
}
switch(parts.size()) {
case 0: return "unbounded";
case 1: return parts.get(0);
default: return parts.get(0) + " and " + parts.get(1);
}
}
示例5: maximum
import com.google.common.collect.Range; //導入方法依賴的package包/類
public static Optional<Integer> maximum(Range<Integer> range) {
return range.hasUpperBound() ? Optional.of(range.upperBoundType() == BoundType.CLOSED ? range.upperEndpoint()
: Integer.valueOf(range.upperEndpoint() - 1))
: Optional.empty();
}