org.apache.commons.lang3.Range.isOverlappedBy()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(121)

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

Range.isOverlappedBy介绍

[英]Checks whether this range is overlapped by the specified range.

Two ranges overlap if there is at least one element in common.

This method may fail if the ranges have two different comparators or element types.
[中]检查此范围是否与指定范围重叠。
如果至少有一个元素相同,则两个范围重叠。
如果量程有两个不同的比较器或元件类型,此方法可能会失败。

代码示例

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Calculate the intersection of {@code this} and an overlapping Range.
 * @param other overlapping Range
 * @return range representing the intersection of {@code this} and {@code other} ({@code this} if equal)
 * @throws IllegalArgumentException if {@code other} does not overlap {@code this}
 * @since 3.0.1
 */
public Range<T> intersectionWith(final Range<T> other) {
  if (!this.isOverlappedBy(other)) {
    throw new IllegalArgumentException(String.format(
      "Cannot calculate intersection with non-overlapping range %s", other));
  }
  if (this.equals(other)) {
    return this;
  }
  final T min = getComparator().compare(minimum, other.minimum) < 0 ? other.minimum : minimum;
  final T max = getComparator().compare(maximum, other.maximum) < 0 ? maximum : other.maximum;
  return between(min, max, getComparator());
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testIsOverlappedBy() {
  // null handling
  assertFalse(intRange.isOverlappedBy(null));
  // easy inside range
  assertTrue(intRange.isOverlappedBy(Range.between(12, 18)));
  // outside range on each side
  assertFalse(intRange.isOverlappedBy(Range.between(32, 45)));
  assertFalse(intRange.isOverlappedBy(Range.between(2, 8)));
  // equals range
  assertTrue(intRange.isOverlappedBy(Range.between(10, 20)));
  // overlaps
  assertTrue(intRange.isOverlappedBy(Range.between(9, 14)));
  assertTrue(intRange.isOverlappedBy(Range.between(16, 21)));
  // touches lower boundary
  assertTrue(intRange.isOverlappedBy(Range.between(10, 19)));
  assertTrue(intRange.isOverlappedBy(Range.between(10, 21)));
  // touches upper boundary
  assertTrue(intRange.isOverlappedBy(Range.between(11, 20)));
  assertTrue(intRange.isOverlappedBy(Range.between(9, 20)));
  // negative
  assertFalse(intRange.isOverlappedBy(Range.between(-11, -18)));
}

代码示例来源:origin: de.julielab/julielab-entity-evaluator

public boolean overlaps(EvaluationDataEntry other) {
  return offsetRange.isOverlappedBy(other.offsetRange);
}

代码示例来源:origin: NationalSecurityAgency/timely

public boolean inRange(long begin, long end) {
  Range<Long> requestedRange = Range.between(begin, end);
  Range<Long> compressorRange = Range.between(oldestTimestamp, newestTimestamp);
  return compressorRange.isOverlappedBy(requestedRange);
}

代码示例来源:origin: io.virtdata/virtdata-lib-curves4

/**
 * Calculate the intersection of {@code this} and an overlapping Range.
 * @param other overlapping Range
 * @return range representing the intersection of {@code this} and {@code other} ({@code this} if equal)
 * @throws IllegalArgumentException if {@code other} does not overlap {@code this}
 * @since 3.0.1
 */
public Range<T> intersectionWith(final Range<T> other) {
  if (!this.isOverlappedBy(other)) {
    throw new IllegalArgumentException(String.format(
      "Cannot calculate intersection with non-overlapping range %s", other));
  }
  if (this.equals(other)) {
    return this;
  }
  final T min = getComparator().compare(minimum, other.minimum) < 0 ? other.minimum : minimum;
  final T max = getComparator().compare(maximum, other.maximum) < 0 ? maximum : other.maximum;
  return between(min, max, getComparator());
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * Calculate the intersection of {@code this} and an overlapping Range.
 * @param other overlapping Range
 * @return range representing the intersection of {@code this} and {@code other} ({@code this} if equal)
 * @throws IllegalArgumentException if {@code other} does not overlap {@code this}
 * @since 3.0.1
 */
public Range<T> intersectionWith(final Range<T> other) {
  if (!this.isOverlappedBy(other)) {
    throw new IllegalArgumentException(String.format(
      "Cannot calculate intersection with non-overlapping range %s", other));
  }
  if (this.equals(other)) {
    return this;
  }
  final T min = getComparator().compare(minimum, other.minimum) < 0 ? other.minimum : minimum;
  final T max = getComparator().compare(maximum, other.maximum) < 0 ? maximum : other.maximum;
  return between(min, max, getComparator());
}

代码示例来源:origin: de.knightsoft-net/gwt-commons-lang3

/**
 * Calculate the intersection of {@code this} and an overlapping Range.
 * @param other overlapping Range
 * @return range representing the intersection of {@code this} and {@code other} ({@code this} if equal)
 * @throws IllegalArgumentException if {@code other} does not overlap {@code this}
 * @since 3.0.1
 */
public Range<T> intersectionWith(final Range<T> other) {
  if (!this.isOverlappedBy(other)) {
    throw new IllegalArgumentException(StringUtils.simpleFormat(
      "Cannot calculate intersection with non-overlapping range %s", other));
  }
  if (this.equals(other)) {
    return this;
  }
  final T min = getComparator().compare(minimum, other.minimum) < 0 ? other.minimum : minimum;
  final T max = getComparator().compare(maximum, other.maximum) < 0 ? maximum : other.maximum;
  return between(min, max, getComparator());
}

代码示例来源:origin: com.opencsv/opencsv

if(next.isOverlappedBy(range)) {
  range = Range.between(
      Math.min(next.getMinimum(), range.getMinimum()),

代码示例来源:origin: de.julielab/julielab-entity-evaluator

if (!offsetRange.isOverlappedBy(other.offsetRange))
  return false;
if (comparisonType == ComparisonType.EXACT) {

相关文章