當前位置: 首頁>>代碼示例>>Java>>正文


Java Range.upTo方法代碼示例

本文整理匯總了Java中com.google.common.collect.Range.upTo方法的典型用法代碼示例。如果您正苦於以下問題:Java Range.upTo方法的具體用法?Java Range.upTo怎麽用?Java Range.upTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.Range的用法示例。


在下文中一共展示了Range.upTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: parseNumericRange

import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
 * Parse a range in the standard mathematical format e.g.
 *
 *     [0, 1) for a closed-open range from 0 to 1.
 *
 * Can also parse single numbers as a closed range e.g.
 *
 *     5 for a closed-closed range from 5 to 5.
 */
public static <T extends Number & Comparable<T>> Range<T> parseNumericRange(Node node, Class<T> type) throws InvalidXMLException {
    String value = node.getValue();

    Matcher matcher = RANGE_RE.matcher(value);
    if(!matcher.matches()) {
        T number = parseNumber(node, value, type, (T) null);
        if(number != null) {
            return Range.singleton(number);
        }
        throw new InvalidXMLException("Invalid " + type.getSimpleName().toLowerCase() + " range '" + value + "'", node);
    }

    T lower = parseNumber(node, matcher.group(2), type, true);
    T upper = parseNumber(node, matcher.group(3), type, true);

    BoundType lowerType = null, upperType = null;
    if(!Double.isInfinite(lower.doubleValue())) {
        lowerType = "(".equals(matcher.group(1)) ? BoundType.OPEN : BoundType.CLOSED;
    }
    if(!Double.isInfinite(upper.doubleValue())) {
        upperType = ")".equals(matcher.group(4)) ? BoundType.OPEN : BoundType.CLOSED;
    }

    if(lower.compareTo(upper) == 1) {
        throw new InvalidXMLException("range lower bound (" + lower + ") cannot be greater than upper bound (" + upper + ")", node);
    }

    if(lowerType == null) {
        if(upperType == null) {
            return Range.all();
        } else {
            return Range.upTo(upper, upperType);
        }
    } else {
        if(upperType == null) {
            return Range.downTo(lower, lowerType);
        } else {
            return Range.range(lower, lowerType, upper, upperType);
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:51,代碼來源:XMLUtils.java


注:本文中的com.google.common.collect.Range.upTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。