Java Code Examples for com.google.common.collect.SortedLists.KeyPresentBehavior

The following are top voted examples for showing how to use com.google.common.collect.SortedLists.KeyPresentBehavior. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guava-mock   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 2
Project: guava-mock   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 3
Project: googles-monorepo-demo   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 4
Project: googles-monorepo-demo   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 5
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 6
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 7
Project: guava   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@NullableDecl
public V get(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 8
Project: guava   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@NullableDecl
public Entry<Range<K>, V> getEntry(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 9
Project: guava   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@NullableDecl
public V get(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 10
Project: guava   File: ImmutableRangeMap.java   Source Code and License 6 votes vote down vote up
@Override
@NullableDecl
public Entry<Range<K>, V> getEntry(K key) {
  int index =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          Cut.belowValue(key),
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 11
Project: guava-mock   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithoutDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITHOUT_DUPS, key,
            SortedLists.binarySearch(LIST_WITHOUT_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 12
Project: guava-mock   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITH_DUPS, key,
            SortedLists.binarySearch(LIST_WITH_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 13
Project: googles-monorepo-demo   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithoutDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITHOUT_DUPS, key,
            SortedLists.binarySearch(LIST_WITHOUT_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 14
Project: googles-monorepo-demo   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITH_DUPS, key,
            SortedLists.binarySearch(LIST_WITH_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 15
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 16
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 17
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 18
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 19
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 20
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 21
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 22
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 23
Project: bts   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 24
Project: bts   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 25
Project: j2objc   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 26
Project: j2objc   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 27
Project: guava-libraries   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 28
Project: guava-libraries   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 29
Project: guava-libraries   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithoutDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITHOUT_DUPS, key,
            SortedLists.binarySearch(LIST_WITHOUT_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 30
Project: guava-libraries   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITH_DUPS, key,
            SortedLists.binarySearch(LIST_WITH_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 31
Project: guava-libraries   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithoutDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITHOUT_DUPS, key,
            SortedLists.binarySearch(LIST_WITHOUT_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 32
Project: guava-libraries   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(LIST_WITH_DUPS, key,
            SortedLists.binarySearch(LIST_WITH_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior, absentBehavior);
      }
    }
  }
}
 
Example 33
Project: VectorAttackScanner   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 34
Project: VectorAttackScanner   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 35
Project: guava   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithoutDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(
            LIST_WITHOUT_DUPS,
            key,
            SortedLists.binarySearch(LIST_WITHOUT_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior,
            absentBehavior);
      }
    }
  }
}
 
Example 36
Project: guava   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(
            LIST_WITH_DUPS,
            key,
            SortedLists.binarySearch(LIST_WITH_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior,
            absentBehavior);
      }
    }
  }
}
 
Example 37
Project: guava   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithoutDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(
            LIST_WITHOUT_DUPS,
            key,
            SortedLists.binarySearch(LIST_WITHOUT_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior,
            absentBehavior);
      }
    }
  }
}
 
Example 38
Project: guava   File: SortedListsTest.java   Source Code and License 5 votes vote down vote up
public void testWithDups() {
  for (KeyPresentBehavior presentBehavior : KeyPresentBehavior.values()) {
    for (KeyAbsentBehavior absentBehavior : KeyAbsentBehavior.values()) {
      for (int key = 0; key <= 10; key++) {
        assertModelAgrees(
            LIST_WITH_DUPS,
            key,
            SortedLists.binarySearch(LIST_WITH_DUPS, key, presentBehavior, absentBehavior),
            presentBehavior,
            absentBehavior);
      }
    }
  }
}
 
Example 39
Project: cnGuava   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 40
Project: cnGuava   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 41
Project: org.openntf.domino   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public V get(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? values.get(index) : null;
  }
}
 
Example 42
Project: org.openntf.domino   File: ImmutableRangeMap.java   Source Code and License 5 votes vote down vote up
@Override
@Nullable
public Map.Entry<Range<K>, V> getEntry(K key) {
  int index = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(),
      Cut.belowValue(key), KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_LOWER);
  if (index == -1) {
    return null;
  } else {
    Range<K> range = ranges.get(index);
    return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
  }
}
 
Example 43
Project: guava-mock   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex =
      SortedLists.binarySearch(
          ranges,
          Range.<K>upperBoundFn(),
          range.lowerBound,
          KeyPresentBehavior.FIRST_AFTER,
          KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          range.upperBound,
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges =
      new ImmutableList<Range<K>>() {
        @Override
        public int size() {
          return len;
        }

        @Override
        public Range<K> get(int index) {
          checkElementIndex(index, len);
          if (index == 0 || index == len - 1) {
            return ranges.get(index + off).intersection(range);
          } else {
            return ranges.get(index + off);
          }
        }

        @Override
        boolean isPartialView() {
          return true;
        }
      };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
    @Override
    public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
      if (range.isConnected(subRange)) {
        return outer.subRangeMap(subRange.intersection(range));
      } else {
        return ImmutableRangeMap.of();
      }
    }
  };
}
 
Example 44
Project: guava-mock   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */
private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }

  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex =
        SortedLists.binarySearch(
            ranges,
            Range.<C>upperBoundFn(),
            range.lowerBound,
            KeyPresentBehavior.FIRST_AFTER,
            KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }

  int toIndex;
  if (range.hasUpperBound()) {
    toIndex =
        SortedLists.binarySearch(
            ranges,
            Range.<C>lowerBoundFn(),
            range.upperBound,
            KeyPresentBehavior.FIRST_PRESENT,
            KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
}
 
Example 45
Project: guava-mock   File: SortedListsTest.java   Source Code and License 4 votes vote down vote up
void assertModelAgrees(List<Integer> list, Integer key, int answer,
    KeyPresentBehavior presentBehavior, KeyAbsentBehavior absentBehavior) {
  switch (presentBehavior) {
    case FIRST_PRESENT:
      if (list.contains(key)) {
        assertEquals(list.indexOf(key), answer);
        return;
      }
      break;
    case LAST_PRESENT:
      if (list.contains(key)) {
        assertEquals(list.lastIndexOf(key), answer);
        return;
      }
      break;
    case ANY_PRESENT:
      if (list.contains(key)) {
        assertEquals(key, list.get(answer));
        return;
      }
      break;
    case FIRST_AFTER:
      if (list.contains(key)) {
        assertEquals(list.lastIndexOf(key) + 1, answer);
        return;
      }
      break;
    case LAST_BEFORE:
      if (list.contains(key)) {
        assertEquals(list.indexOf(key) - 1, answer);
        return;
      }
      break;
    default:
      throw new AssertionError();
  }
  // key is not present
  int nextHigherIndex = list.size();
  for (int i = list.size() - 1; i >= 0 && list.get(i) > key; i--) {
    nextHigherIndex = i;
  }
  switch (absentBehavior) {
    case NEXT_LOWER:
      assertEquals(nextHigherIndex - 1, answer);
      return;
    case NEXT_HIGHER:
      assertEquals(nextHigherIndex, answer);
      return;
    case INVERTED_INSERTION_INDEX:
      assertEquals(-1 - nextHigherIndex, answer);
      return;
    default:
      throw new AssertionError();
  }
}
 
Example 46
Project: googles-monorepo-demo   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex =
      SortedLists.binarySearch(
          ranges,
          Range.<K>upperBoundFn(),
          range.lowerBound,
          KeyPresentBehavior.FIRST_AFTER,
          KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          range.upperBound,
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges =
      new ImmutableList<Range<K>>() {
        @Override
        public int size() {
          return len;
        }

        @Override
        public Range<K> get(int index) {
          checkElementIndex(index, len);
          if (index == 0 || index == len - 1) {
            return ranges.get(index + off).intersection(range);
          } else {
            return ranges.get(index + off);
          }
        }

        @Override
        boolean isPartialView() {
          return true;
        }
      };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
    @Override
    public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
      if (range.isConnected(subRange)) {
        return outer.subRangeMap(subRange.intersection(range));
      } else {
        return ImmutableRangeMap.of();
      }
    }
  };
}
 
Example 47
Project: googles-monorepo-demo   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */
private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }

  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex =
        SortedLists.binarySearch(
            ranges,
            Range.<C>upperBoundFn(),
            range.lowerBound,
            KeyPresentBehavior.FIRST_AFTER,
            KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }

  int toIndex;
  if (range.hasUpperBound()) {
    toIndex =
        SortedLists.binarySearch(
            ranges,
            Range.<C>lowerBoundFn(),
            range.upperBound,
            KeyPresentBehavior.FIRST_PRESENT,
            KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
}
 
Example 48
Project: googles-monorepo-demo   File: SortedListsTest.java   Source Code and License 4 votes vote down vote up
void assertModelAgrees(List<Integer> list, Integer key, int answer,
    KeyPresentBehavior presentBehavior, KeyAbsentBehavior absentBehavior) {
  switch (presentBehavior) {
    case FIRST_PRESENT:
      if (list.contains(key)) {
        assertEquals(list.indexOf(key), answer);
        return;
      }
      break;
    case LAST_PRESENT:
      if (list.contains(key)) {
        assertEquals(list.lastIndexOf(key), answer);
        return;
      }
      break;
    case ANY_PRESENT:
      if (list.contains(key)) {
        assertEquals(key, list.get(answer));
        return;
      }
      break;
    case FIRST_AFTER:
      if (list.contains(key)) {
        assertEquals(list.lastIndexOf(key) + 1, answer);
        return;
      }
      break;
    case LAST_BEFORE:
      if (list.contains(key)) {
        assertEquals(list.indexOf(key) - 1, answer);
        return;
      }
      break;
    default:
      throw new AssertionError();
  }
  // key is not present
  int nextHigherIndex = list.size();
  for (int i = list.size() - 1; i >= 0 && list.get(i) > key; i--) {
    nextHigherIndex = i;
  }
  switch (absentBehavior) {
    case NEXT_LOWER:
      assertEquals(nextHigherIndex - 1, answer);
      return;
    case NEXT_HIGHER:
      assertEquals(nextHigherIndex, answer);
      return;
    case INVERTED_INSERTION_INDEX:
      assertEquals(-1 - nextHigherIndex, answer);
      return;
    default:
      throw new AssertionError();
  }
}
 
Example 49
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex = SortedLists.binarySearch(ranges, Range.<K>upperBoundFn(), range.lowerBound, KeyPresentBehavior.FIRST_AFTER, KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), range.upperBound, KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges = new ImmutableList<Range<K>>() {
                                        @Override
                                        public int size() {
                                          return len;
                                        }

                                        @Override
                                        public Range<K> get(int index) {
                                          checkElementIndex(index, len);
                                          if (index == 0 || index == len - 1) {
                                            return ranges.get(index + off).intersection(range);
                                          } else {
                                            return ranges.get(index + off);
                                          }
                                        }

                                        @Override
                                        boolean isPartialView() {
                                          return true;
                                        }
                                      };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
    @Override
    public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
      if (range.isConnected(subRange)) {
        return outer.subRangeMap(subRange.intersection(range));
      } else {
        return ImmutableRangeMap.of();
      }
    }
  };
}
 
Example 50
Project: codebuff   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */

private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }
  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex = SortedLists.binarySearch(
  ranges,
  Range.<C>upperBoundFn(),
  range.lowerBound,
  KeyPresentBehavior.FIRST_AFTER,
  KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }
  int toIndex;
  if (range.hasUpperBound()) {
    toIndex = SortedLists.binarySearch(ranges, Range.<C>lowerBoundFn(), range.upperBound, KeyPresentBehavior.FIRST_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
        }
 
Example 51
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex = SortedLists.binarySearch(ranges, Range.<K>upperBoundFn(), range.lowerBound, KeyPresentBehavior.FIRST_AFTER, KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), range.upperBound, KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges = new ImmutableList<Range<K>>() {
                                        @Override
                                        public int size() {
                                          return len;
                                        }

                                        @Override
                                        public Range<K> get(int index) {
                                          checkElementIndex(index, len);
                                          if (index == 0 || index == len - 1) {
                                            return ranges.get(index + off).intersection(range);
                                          } else {
                                            return ranges.get(index + off);
                                          }
                                        }

                                        @Override
                                        boolean isPartialView() {
                                          return true;
                                        }
                                      };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
    @Override
    public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
      if (range.isConnected(subRange)) {
        return outer.subRangeMap(subRange.intersection(range));
      } else {
        return ImmutableRangeMap.of();
      }
    }
  };
}
 
Example 52
Project: codebuff   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */

private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }
  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex = SortedLists.binarySearch(
  ranges,
  Range.<C>upperBoundFn(),
  range.lowerBound,
  KeyPresentBehavior.FIRST_AFTER,
  KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }
  int toIndex;
  if (range.hasUpperBound()) {
    toIndex = SortedLists.binarySearch(ranges, Range.<C>lowerBoundFn(), range.upperBound, KeyPresentBehavior.FIRST_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
        }
 
Example 53
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex = SortedLists.binarySearch(ranges, Range.<K>upperBoundFn(), range.lowerBound, KeyPresentBehavior.FIRST_AFTER, KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), range.upperBound, KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges = new ImmutableList<Range<K>>() {
                                        @Override
                                        public int size() {
                                          return len;
                                        }

                                        @Override
                                        public Range<K> get(int index) {
                                          checkElementIndex(index, len);
                                          if (index == 0 || index == len - 1) {
                                            return ranges.get(index + off).intersection(range);
                                          } else {
                                            return ranges.get(index + off);
                                          }
                                        }

                                        @Override
                                        boolean isPartialView() {
                                          return true;
                                        }
                                      };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
    @Override
    public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
      if (range.isConnected(subRange)) {
        return outer.subRangeMap(subRange.intersection(range));
      } else {
        return ImmutableRangeMap.of();
      }
    }
  };
}
 
Example 54
Project: codebuff   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */

private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }
  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex = SortedLists.binarySearch(
  ranges,
  Range.<C>upperBoundFn(),
  range.lowerBound,
  KeyPresentBehavior.FIRST_AFTER,
  KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }
  int toIndex;
  if (range.hasUpperBound()) {
    toIndex = SortedLists.binarySearch(ranges, Range.<C>lowerBoundFn(), range.upperBound, KeyPresentBehavior.FIRST_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
        }
 
Example 55
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex = SortedLists.binarySearch(ranges, Range.<K>upperBoundFn(), range.lowerBound, KeyPresentBehavior.FIRST_AFTER, KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex = SortedLists.binarySearch(ranges, Range.<K>lowerBoundFn(), range.upperBound, KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges = new ImmutableList<Range<K>>() {
                                        @Override
                                        public int size() {
                                          return len;
                                        }

                                        @Override
                                        public Range<K> get(int index) {
                                          checkElementIndex(index, len);
                                          if (index == 0 || index == len - 1) {
                                            return ranges.get(index + off).intersection(range);
                                          } else {
                                            return ranges.get(index + off);
                                          }
                                        }

                                        @Override
                                        boolean isPartialView() {
                                          return true;
                                        }
                                      };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
    @Override
    public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
      if (range.isConnected(subRange)) {
        return outer.subRangeMap(subRange.intersection(range));
      } else {
        return ImmutableRangeMap.of();
      }
    }
  };
}
 
Example 56
Project: codebuff   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */

private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }
  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex = SortedLists.binarySearch(
  ranges,
  Range.<C>upperBoundFn(),
  range.lowerBound,
  KeyPresentBehavior.FIRST_AFTER,
  KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }
  int toIndex;
  if (range.hasUpperBound()) {
    toIndex = SortedLists.binarySearch(ranges, Range.<C>lowerBoundFn(), range.upperBound, KeyPresentBehavior.FIRST_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
        }
 
Example 57
Project: codebuff   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex =
      SortedLists.binarySearch(
          ranges,
          Range.<K>upperBoundFn(),
          range.lowerBound,
          KeyPresentBehavior.FIRST_AFTER,
          KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex =
      SortedLists.binarySearch(
          ranges,
          Range.<K>lowerBoundFn(),
          range.upperBound,
          KeyPresentBehavior.ANY_PRESENT,
          KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges =
      new ImmutableList<Range<K>>() {
        @Override
        public int size() {
          return len;
        }

        @Override
        public Range<K> get(int index) {
          checkElementIndex(index, len);
          if (index == 0 || index == len - 1) {
            return ranges.get(index + off).intersection(range);
          } else {
            return ranges.get(index + off);
          }
        }

        @Override
        boolean isPartialView() {
          return true;
        }
      };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
    @Override
    public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
      if (range.isConnected(subRange)) {
        return outer.subRangeMap(subRange.intersection(range));
      } else {
        return ImmutableRangeMap.of();
      }
    }
  };
}
 
Example 58
Project: codebuff   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */
private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }

  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex =
        SortedLists.binarySearch(
            ranges,
            Range.<C>upperBoundFn(),
            range.lowerBound,
            KeyPresentBehavior.FIRST_AFTER,
            KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }

  int toIndex;
  if (range.hasUpperBound()) {
    toIndex =
        SortedLists.binarySearch(
            ranges,
            Range.<C>lowerBoundFn(),
            range.upperBound,
            KeyPresentBehavior.FIRST_PRESENT,
            KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
}
 
Example 59
Project: bts   File: ImmutableRangeMap.java   Source Code and License 4 votes vote down vote up
@Override
public ImmutableRangeMap<K, V> subRangeMap(final Range<K> range) {
  if (checkNotNull(range).isEmpty()) {
    return ImmutableRangeMap.of();
  } else if (ranges.isEmpty() || range.encloses(span())) {
    return this;
  }
  int lowerIndex = SortedLists.binarySearch(
      ranges, Range.<K>upperBoundFn(), range.lowerBound,
      KeyPresentBehavior.FIRST_AFTER, KeyAbsentBehavior.NEXT_HIGHER);
  int upperIndex = SortedLists.binarySearch(ranges, 
      Range.<K>lowerBoundFn(), range.upperBound,
      KeyPresentBehavior.ANY_PRESENT, KeyAbsentBehavior.NEXT_HIGHER);
  if (lowerIndex >= upperIndex) {
    return ImmutableRangeMap.of();
  }
  final int off = lowerIndex;
  final int len = upperIndex - lowerIndex;
  ImmutableList<Range<K>> subRanges = new ImmutableList<Range<K>>() {
    @Override
    public int size() {
      return len;
    }

    @Override
    public Range<K> get(int index) {
      checkElementIndex(index, len);
      if (index == 0 || index == len - 1) {
        return ranges.get(index + off).intersection(range);
      } else {
        return ranges.get(index + off);
      }
    }

    @Override
    boolean isPartialView() {
      return true;
    }
  };
  final ImmutableRangeMap<K, V> outer = this;
  return new ImmutableRangeMap<K, V>(
      subRanges, values.subList(lowerIndex, upperIndex)) {
        @Override
        public ImmutableRangeMap<K, V> subRangeMap(Range<K> subRange) {
          if (range.isConnected(subRange)) {
            return outer.subRangeMap(subRange.intersection(range));
          } else {
            return ImmutableRangeMap.of();
          }
        }
  };
}
 
Example 60
Project: bts   File: ImmutableRangeSet.java   Source Code and License 4 votes vote down vote up
/**
 * Returns a list containing the nonempty intersections of {@code range}
 * with the ranges in this range set.
 */
private ImmutableList<Range<C>> intersectRanges(final Range<C> range) {
  if (ranges.isEmpty() || range.isEmpty()) {
    return ImmutableList.of();
  } else if (range.encloses(span())) {
    return ranges;
  }

  final int fromIndex;
  if (range.hasLowerBound()) {
    fromIndex = SortedLists.binarySearch(
        ranges, Range.<C>upperBoundFn(), range.lowerBound, KeyPresentBehavior.FIRST_AFTER,
        KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    fromIndex = 0;
  }

  int toIndex;
  if (range.hasUpperBound()) {
    toIndex = SortedLists.binarySearch(
        ranges, Range.<C>lowerBoundFn(), range.upperBound, KeyPresentBehavior.FIRST_PRESENT,
        KeyAbsentBehavior.NEXT_HIGHER);
  } else {
    toIndex = ranges.size();
  }
  final int length = toIndex - fromIndex;
  if (length == 0) {
    return ImmutableList.of();
  } else {
    return new ImmutableList<Range<C>>() {
      @Override
      public int size() {
        return length;
      }

      @Override
      public Range<C> get(int index) {
        checkElementIndex(index, length);
        if (index == 0 || index == length - 1) {
          return ranges.get(index + fromIndex).intersection(range);
        } else {
          return ranges.get(index + fromIndex);
        }
      }

      @Override
      boolean isPartialView() {
        return true;
      }
    };
  }
}