本文整理匯總了Java中com.google.common.collect.Range.upperBoundType方法的典型用法代碼示例。如果您正苦於以下問題:Java Range.upperBoundType方法的具體用法?Java Range.upperBoundType怎麽用?Java Range.upperBoundType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Range
的用法示例。
在下文中一共展示了Range.upperBoundType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: needMaximum
import com.google.common.collect.Range; //導入方法依賴的package包/類
public static int needMaximum(Range<Integer> range) {
assertUpperBound(range);
return range.upperBoundType() == BoundType.CLOSED ? range.upperEndpoint()
: range.upperEndpoint() - 1;
}
示例3: needOpenMaximum
import com.google.common.collect.Range; //導入方法依賴的package包/類
public static int needOpenMaximum(Range<Integer> range) {
assertUpperBound(range);
return range.upperBoundType() == BoundType.CLOSED ? range.upperEndpoint() + 1
: range.upperEndpoint();
}
示例4: toClosed
import com.google.common.collect.Range; //導入方法依賴的package包/類
public static Range<Integer> toClosed(Range<Integer> range) {
assertBounded(range);
return range.lowerBoundType() == BoundType.CLOSED && range.upperBoundType() == BoundType.CLOSED
? range
: Range.closed(needMinimum(range), needMaximum(range));
}