protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) { List<Integer> elements = newArrayList(elementsSet); /* * A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it * doesn't need one, or it should be suppressed for ContiguousSet. */ for (int i = 0; i < elements.size() - 1; i++) { assertEquals(elements.get(i) + 1, (int) elements.get(i + 1)); } Range<Integer> range = elements.isEmpty() ? Range.closedOpen(0, 0) : Range.encloseAll(elements); return ContiguousSet.create(range, DiscreteDomain.integers()); } }
public void testEncloseAll_empty() { try { Range.encloseAll(ImmutableSet.<Integer>of()); fail(); } catch (NoSuchElementException expected) { } }
public void testEncloseAll() { assertEquals(Range.closed(0, 0), Range.encloseAll(Arrays.asList(0))); assertEquals(Range.closed(-3, 5), Range.encloseAll(Arrays.asList(5, -3))); assertEquals(Range.closed(-3, 5), Range.encloseAll(Arrays.asList(1, 2, 2, 2, 5, -3, 0, -1))); }
public void testEncloseAll_nullValue() { List<Integer> nullFirst = Lists.newArrayList(null, 0); try { Range.encloseAll(nullFirst); fail(); } catch (NullPointerException expected) { } List<Integer> nullNotFirst = Lists.newArrayList(0, null); try { Range.encloseAll(nullNotFirst); fail(); } catch (NullPointerException expected) { } }
/** * Returns the minimal range that * {@linkplain Range#contains(Comparable) contains} all of the given values. * The returned range is {@linkplain BoundType#CLOSED closed} on both ends. * * @throws ClassCastException if the parameters are not <i>mutually * comparable</i> * @throws NoSuchElementException if {@code values} is empty * @throws NullPointerException if any of {@code values} is null */ public static <C extends Comparable<?>> Range<C> encloseAll( Iterable<C> values) { return Range.encloseAll(values); } }
protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) { List<Integer> elements = newArrayList(elementsSet); /* * A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it * doesn't need one, or it should be suppressed for ContiguousSet. */ for (int i = 0; i < elements.size() - 1; i++) { assertEquals(elements.get(i) + 1, (int) elements.get(i + 1)); } Range<Integer> range = elements.isEmpty() ? Range.closedOpen(0, 0) : Range.encloseAll(elements); return ContiguousSet.create(range, DiscreteDomain.integers()); } }
protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) { List<Integer> elements = newArrayList(elementsSet); /* * A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it * doesn't need one, or it should be suppressed for ContiguousSet. */ for (int i = 0; i < elements.size() - 1; i++) { assertEquals(elements.get(i) + 1, (int) elements.get(i + 1)); } Range<Integer> range = (elements.isEmpty()) ? Range.closedOpen(0, 0) : Range.encloseAll(elements); return ContiguousSet.create(range, DiscreteDomain.integers()); } }
public void testEncloseAll() { assertEquals(Range.closed(0, 0), Range.encloseAll(Arrays.asList(0))); assertEquals(Range.closed(-3, 5), Range.encloseAll(Arrays.asList(5, -3))); assertEquals(Range.closed(-3, 5), Range.encloseAll(Arrays.asList(1, 2, 2, 2, 5, -3, 0, -1))); }
public void testEncloseAll_nullValue() { List<Integer> nullFirst = Lists.newArrayList(null, 0); try { Range.encloseAll(nullFirst); fail(); } catch (NullPointerException expected) {} List<Integer> nullNotFirst = Lists.newArrayList(0, null); try { Range.encloseAll(nullNotFirst); fail(); } catch (NullPointerException expected) {} }
public void testEncloseAll_empty() { try { Range.encloseAll(ImmutableSet.<Integer>of()); fail(); } catch (NoSuchElementException expected) {} }
@Override public Map<Long, ILogData> readRange(RuntimeLayout runtimeLayout, Set<Long> globalAddresses) { Range<Long> range = Range.encloseAll(globalAddresses); long startAddress = range.lowerEndpoint(); long endAddress = range.upperEndpoint(); int numUnits = runtimeLayout.getLayout().getSegmentLength(startAddress); log.trace("readRange[{}-{}]: chain {}/{}", startAddress, endAddress, numUnits, numUnits); Map<Long, LogData> logResult = CFUtils.getUninterruptibly( runtimeLayout .getLogUnitClient(startAddress, numUnits - 1) .read(range)).getAddresses(); //in case of a hole, do a normal read and use its hole fill policy Map<Long, ILogData> returnResult = new TreeMap<>(); for (Map.Entry<Long, LogData> entry : logResult.entrySet()) { ILogData value = entry.getValue(); if (value == null || value.isEmpty()) { value = read(runtimeLayout, entry.getKey()); } returnResult.put(entry.getKey(), value); } return returnResult; }