com.google.common.collect.Range.span()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中com.google.common.collect.Range.span方法的一些代码示例,展示了Range.span的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.span方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:span

Range.span介绍

[英]Returns the minimal range that #encloses both this range and other. For example, the span of [1..3] and (5..7) is [1..7).

If the input ranges are #isConnected, the returned range can also be called their union. If they are not, note that the span might contain values that are not contained in either input range.

Like #intersection(Range), this operation is commutative, associative and idempotent. Unlike it, it is always well-defined for any two input ranges.
[中]返回#包含此范围和其他范围的最小范围。例如,[1..3]和(5..7)的跨度是[1..7]。
如果输入范围是#未连接的,则返回的范围也可以称为其并集。如果不是,请注意跨度可能包含两个输入范围中都不包含的值。
与#交(值域)一样,这个运算是交换的、结合的和幂等的。与之不同的是,它总是为任意两个输入范围定义良好。

代码示例

代码示例来源:origin: apache/kylin

public static <C extends Comparable<?>> Range<C> merge(Range<C> a, Range<C> b) {
  if (a == null && b == null) {
    return null;
  } else if (a == null || b == null) {
    return a == null ? b : a;
  } else {
    return a.span(b);
  }
}

代码示例来源:origin: google/guava

/** Returns the range that spans the given range and entry, if the entry can be coalesced. */
private static <K extends Comparable, V> Range<K> coalesce(
  Range<K> range, V value, @Nullable Entry<Cut<K>, RangeMapEntry<K, V>> entry) {
 if (entry != null
   && entry.getValue().getKey().isConnected(range)
   && entry.getValue().getValue().equals(value)) {
  return range.span(entry.getValue().getKey());
 }
 return range;
}

代码示例来源:origin: google/j2objc

/** Returns the range that spans the given range and entry, if the entry can be coalesced. */
private static <K extends Comparable, V> Range<K> coalesce(
  Range<K> range, V value, @NullableDecl Entry<Cut<K>, RangeMapEntry<K, V>> entry) {
 if (entry != null
   && entry.getValue().getKey().isConnected(range)
   && entry.getValue().getValue().equals(value)) {
  return range.span(entry.getValue().getKey());
 }
 return range;
}

代码示例来源:origin: wildfly/wildfly

/** Returns the range that spans the given range and entry, if the entry can be coalesced. */
private static <K extends Comparable, V> Range<K> coalesce(
  Range<K> range, V value, @NullableDecl Entry<Cut<K>, RangeMapEntry<K, V>> entry) {
 if (entry != null
   && entry.getValue().getKey().isConnected(range)
   && entry.getValue().getValue().equals(value)) {
  return range.span(entry.getValue().getKey());
 }
 return range;
}

代码示例来源:origin: google/guava

range,
   nextRange);
 range = range.span(peekingItr.next());
} else {
 break;

代码示例来源:origin: google/google-java-format

private static Range<Integer> union(Range<Integer> x, Range<Integer> y) {
 return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(INTEGERS);
}

代码示例来源:origin: google/j2objc

range,
   nextRange);
 range = range.span(peekingItr.next());
} else {
 break;

代码示例来源:origin: google/guava

assertEquals(Range.closed(0, 8), range.span(Range.closed(0, 2)));
assertEquals(Range.atMost(8), range.span(Range.atMost(2)));
assertEquals(Range.closed(2, 8), range.span(Range.closedOpen(2, 4)));
assertEquals(Range.atMost(8), range.span(Range.lessThan(4)));
assertEquals(Range.closed(2, 8), range.span(Range.closed(2, 6)));
assertEquals(Range.atMost(8), range.span(Range.atMost(6)));
assertEquals(range, range.span(Range.closed(4, 6)));
assertEquals(range, range.span(Range.closed(5, 7)));
assertEquals(range, range.span(Range.closed(6, 8)));
assertEquals(range, range.span(range));
assertEquals(Range.closed(4, 10), range.span(Range.closed(4, 10)));
assertEquals(Range.atLeast(4), range.span(Range.atLeast(4)));
assertEquals(Range.closed(2, 8), range.span(Range.closed(2, 8)));
assertEquals(Range.atMost(8), range.span(Range.atMost(8)));
assertEquals(Range.closed(2, 10), range.span(Range.closed(2, 10)));
assertEquals(Range.<Integer>all(), range.span(Range.<Integer>all()));
assertEquals(Range.closed(4, 10), range.span(Range.closed(6, 10)));
assertEquals(Range.atLeast(4), range.span(Range.atLeast(6)));

代码示例来源:origin: google/google-java-format

private static Range<Integer> union(Range<Integer> x, Range<Integer> y) {
 return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(DiscreteDomain.integers());
}

代码示例来源:origin: wildfly/wildfly

range,
   nextRange);
 range = range.span(peekingItr.next());
} else {
 break;

代码示例来源:origin: google/guava

expectedSpan = itr.next();
while (itr.hasNext()) {
 expectedSpan = expectedSpan.span(itr.next());

代码示例来源:origin: google/guava

private static void doPairTest(Range<Integer> a, Range<Integer> b) {
 TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
 rangeSet.add(a);
 rangeSet.add(b);
 if (a.isEmpty() && b.isEmpty()) {
  assertThat(rangeSet.asRanges()).isEmpty();
 } else if (a.isEmpty()) {
  assertThat(rangeSet.asRanges()).contains(b);
 } else if (b.isEmpty()) {
  assertThat(rangeSet.asRanges()).contains(a);
 } else if (a.isConnected(b)) {
  assertThat(rangeSet.asRanges()).containsExactly(a.span(b));
 } else {
  if (a.lowerEndpoint() < b.lowerEndpoint()) {
   assertThat(rangeSet.asRanges()).containsExactly(a, b).inOrder();
  } else {
   assertThat(rangeSet.asRanges()).containsExactly(b, a).inOrder();
  }
 }
}

代码示例来源:origin: google/guava

public void testSpanTwoRanges() {
 for (Range<Integer> range1 : RANGES) {
  for (Range<Integer> range2 : RANGES) {
   if (!range1.isConnected(range2) || range1.intersection(range2).isEmpty()) {
    RangeMap<Integer, Integer> rangemap =
      ImmutableRangeMap.<Integer, Integer>builder().put(range1, 1).put(range2, 2).build();
    assertEquals(range1.span(range2), rangemap.span());
   }
  }
 }
}

代码示例来源:origin: google/guava

public void testSpanTwoRanges() {
 for (Range<Integer> range1 : RANGES) {
  for (Range<Integer> range2 : RANGES) {
   RangeMap<Integer, Integer> rangeMap = TreeRangeMap.create();
   rangeMap.put(range1, 1);
   rangeMap.put(range2, 2);
   Range<Integer> expected;
   if (range1.isEmpty()) {
    if (range2.isEmpty()) {
     expected = null;
    } else {
     expected = range2;
    }
   } else {
    if (range2.isEmpty()) {
     expected = range1;
    } else {
     expected = range1.span(range2);
    }
   }
   try {
    assertEquals(expected, rangeMap.span());
    assertNotNull(expected);
   } catch (NoSuchElementException e) {
    assertNull(expected);
   }
  }
 }
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/** Returns the range that spans the given range and entry, if the entry can be coalesced. */
private static <K extends Comparable, V> Range<K> coalesce(
  Range<K> range, V value, @Nullable Entry<Cut<K>, RangeMapEntry<K, V>> entry) {
 if (entry != null
   && entry.getValue().getKey().isConnected(range)
   && entry.getValue().getValue().equals(value)) {
  return range.span(entry.getValue().getKey());
 }
 return range;
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

/** Returns the range that spans the given range and entry, if the entry can be coalesced. */
private static <K extends Comparable, V> Range<K> coalesce(
  Range<K> range, V value, @NullableDecl Entry<Cut<K>, RangeMapEntry<K, V>> entry) {
 if (entry != null
   && entry.getValue().getKey().isConnected(range)
   && entry.getValue().getValue().equals(value)) {
  return range.span(entry.getValue().getKey());
 }
 return range;
}

代码示例来源:origin: io.sphere/sphere-java-client

@Override public Range<Double> apply(@Nullable Range<Double> range) {
    if (!range.hasUpperBound()) return range;
    return range.span(Ranges.closed(range.upperEndpoint(), adjustDoubleForSearch(range.upperEndpoint())));
  }
};

代码示例来源:origin: io.sphere/sphere-java-client

@Override public Range<Long> apply(@Nullable Range<Long> range) {
    if (!range.hasUpperBound()) return range;
    return range.span(Ranges.closed(range.upperEndpoint(), adjustLongForSearch(range.upperEndpoint())));
  }
};

代码示例来源:origin: io.sphere/sphere-java-client

@Override public Range<DateTime> apply(@Nullable Range<DateTime> range) {
    if (!range.hasUpperBound()) return range;
    return range.span(Ranges.closed(range.upperEndpoint(), adjustDateTimeForSearch(range.upperEndpoint())));
  }
};

代码示例来源:origin: com.google.guava/guava-tests

public void testSpanTwoRanges() {
 for (Range<Integer> range1 : RANGES) {
  for (Range<Integer> range2 : RANGES) {
   if (!range1.isConnected(range2) || range1.intersection(range2).isEmpty()) {
    RangeMap<Integer, Integer> rangemap =
      ImmutableRangeMap.<Integer, Integer>builder().put(range1, 1).put(range2, 2).build();
    assertEquals(range1.span(range2), rangemap.span());
   }
  }
 }
}

相关文章