当前位置: 首页>>代码示例>>Java>>正文


Java Range.hasLowerBound方法代码示例

本文整理汇总了Java中com.google.common.collect.Range.hasLowerBound方法的典型用法代码示例。如果您正苦于以下问题:Java Range.hasLowerBound方法的具体用法?Java Range.hasLowerBound怎么用?Java Range.hasLowerBound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.Range的用法示例。


在下文中一共展示了Range.hasLowerBound方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:Support.java

示例2: 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);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:28,代码来源:FilterDefinitionParser.java

示例3: 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);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:37,代码来源:Ranges.java

示例4: assertLowerBound

import com.google.common.collect.Range; //导入方法依赖的package包/类
public static void assertLowerBound(Range<?> range) {
    if(!range.hasLowerBound()) {
        throw new IllegalArgumentException("Range has no lower bound");
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:6,代码来源:Ranges.java

示例5: assertUpperBound

import com.google.common.collect.Range; //导入方法依赖的package包/类
public static void assertUpperBound(Range<?> range) {
    if(!range.hasLowerBound()) {
        throw new IllegalArgumentException("Range has no upper bound");
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:6,代码来源:Ranges.java

示例6: minimum

import com.google.common.collect.Range; //导入方法依赖的package包/类
public static Optional<Integer> minimum(Range<Integer> range) {
    return range.hasLowerBound() ? Optional.of(range.lowerBoundType() == BoundType.CLOSED ? range.lowerEndpoint()
                                                                                          : Integer.valueOf(range.lowerEndpoint() + 1))
                                 : Optional.empty();
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:6,代码来源:Ranges.java


注:本文中的com.google.common.collect.Range.hasLowerBound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。