/** * Returns a nonempty contiguous set containing all {@code long} values from {@code lower} * (inclusive) to {@code upper} (inclusive). (These are the same values contained in {@code * Range.closed(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closed(long lower, long upper) { return create(Range.closed(lower, upper), DiscreteDomain.longs()); }
/** * Returns a contiguous set containing all {@code long} values from {@code lower} (inclusive) to * {@code upper} (exclusive). If the endpoints are equal, an empty set is returned. (These are the * same values contained in {@code Range.closedOpen(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closedOpen(long lower, long upper) { return create(Range.closedOpen(lower, upper), DiscreteDomain.longs()); }
/** * Returns a nonempty contiguous set containing all {@code long} values from {@code lower} * (inclusive) to {@code upper} (inclusive). (These are the same values contained in {@code * Range.closed(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closed(long lower, long upper) { return create(Range.closed(lower, upper), DiscreteDomain.longs()); }
/** * Returns a nonempty contiguous set containing all {@code long} values from {@code lower} * (inclusive) to {@code upper} (inclusive). (These are the same values contained in {@code * Range.closed(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closed(long lower, long upper) { return create(Range.closed(lower, upper), DiscreteDomain.longs()); }
/** * Returns a contiguous set containing all {@code long} values from {@code lower} (inclusive) to * {@code upper} (exclusive). If the endpoints are equal, an empty set is returned. (These are the * same values contained in {@code Range.closedOpen(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closedOpen(long lower, long upper) { return create(Range.closedOpen(lower, upper), DiscreteDomain.longs()); }
/** * Returns a contiguous set containing all {@code long} values from {@code lower} (inclusive) to * {@code upper} (exclusive). If the endpoints are equal, an empty set is returned. (These are the * same values contained in {@code Range.closedOpen(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closedOpen(long lower, long upper) { return create(Range.closedOpen(lower, upper), DiscreteDomain.longs()); }
private static ContiguousSet<Long> longsBetween(long lowerInclusive, long upperExclusive) { return ContiguousSet.create(Range.closedOpen(lowerInclusive, upperExclusive), DiscreteDomain.longs()); }
private static ContiguousSet<Long> longsBetween(long lowerInclusive, long upperExclusive) { return ContiguousSet.create(Range.openClosed(lowerInclusive, upperExclusive), DiscreteDomain.longs()); }
public void testSerialization() { reserializeAndAssert(DiscreteDomain.integers()); reserializeAndAssert(DiscreteDomain.longs()); reserializeAndAssert(DiscreteDomain.bigIntegers()); }
@Test public void testMinMaxValues() { assertMinMaxValues(0L, 0L); assertMinMaxValues(42L, 42L); assertMinMaxValues(MIN_VALUE, MIN_VALUE); assertMinMaxValues(MAX_VALUE, MAX_VALUE); assertMinMaxValues(0L, 42L); assertMinMaxValues(42L, 42L); assertMinMaxValues(MIN_VALUE, 42L); assertMinMaxValues(42L, MAX_VALUE); assertMinMaxValues(MIN_VALUE, MAX_VALUE); assertValues(-42L, 0L, ContiguousSet.create(Range.closed(-42L, 0L), DiscreteDomain.longs()).asList()); assertValues(-42L, 42L, ContiguousSet.create(Range.closed(-42L, 42L), DiscreteDomain.longs()).asList()); assertValues(0L, 42L, ContiguousSet.create(Range.closed(0L, 42L), DiscreteDomain.longs()).asList()); assertValues(MIN_VALUE, MIN_VALUE + 42, ContiguousSet.create(Range.closed(MIN_VALUE, MIN_VALUE + 42), DiscreteDomain.longs()).asList()); assertValues(MAX_VALUE - 42L, MAX_VALUE, ContiguousSet.create(Range.closed(MAX_VALUE - 42L, MAX_VALUE), DiscreteDomain.longs()).asList()); }
@Test public void testMinMaxValues() { assertMinMaxValues(0L, 0L); assertMinMaxValues(42L, 42L); assertMinMaxValues(MIN_VALUE, MIN_VALUE); assertMinMaxValues(MAX_VALUE, MAX_VALUE); assertMinMaxValues(0L, 42L); assertMinMaxValues(42L, 42L); assertMinMaxValues(MIN_VALUE, 42L); assertMinMaxValues(42L, MAX_VALUE); assertMinMaxValues(MIN_VALUE, MAX_VALUE); assertValues(-42L, 0L, ContiguousSet.create(Range.closed(-42L, 0L), DiscreteDomain.longs()).asList()); assertValues(-42L, 42L, ContiguousSet.create(Range.closed(-42L, 42L), DiscreteDomain.longs()).asList()); assertValues(0L, 42L, ContiguousSet.create(Range.closed(0L, 42L), DiscreteDomain.longs()).asList()); assertValues(MIN_VALUE, MIN_VALUE + 42, ContiguousSet.create(Range.closed(MIN_VALUE, MIN_VALUE + 42), DiscreteDomain.longs()).asList()); assertValues(MAX_VALUE - 42L, MAX_VALUE, ContiguousSet.create(Range.closed(MAX_VALUE - 42L, MAX_VALUE), DiscreteDomain.longs()).asList()); }
@Override public String toString(){ return String.join(IP_SET_SEPARATOR, rangeSet.asRanges().stream().map(range -> { range = ContiguousSet.create(range, DiscreteDomain.longs()).range(); long start = range.lowerEndpoint(); long end = range.upperEndpoint(); return start == end ? NetworkUtils.longToIpv4String(start) : String.format("%s-%s", NetworkUtils.longToIpv4String(start),NetworkUtils.longToIpv4String(end)); }).collect(Collectors.toList())); } }
public static Set<String> listAllIps(String word, long limit) { word = StringUtils.deleteWhitespace(word); String[] sets = word.split(IP_SET_SEPARATOR); IpRangeSet contain = new IpRangeSet(); IpRangeSet exclude = new IpRangeSet(); for (String set : sets) { if (set.startsWith(IP_SET_INVERT_PREFIX)) { exclude.closed(set.substring(1)); } else { contain.closed(set); } } contain.remove(exclude); long size = contain.size(); if (size == 0) { throw new IllegalArgumentException(String.format("Invalid empty ipset [%s]", word)); } if (size > limit) { throw new IllegalArgumentException(String.format("ip range length[%d] is too large, must less than %d", size, limit)); } Set<String> results = new HashSet<>(); for (Range<Long> range : contain.rangeSet.asRanges()) { range = ContiguousSet.create(range, DiscreteDomain.longs()).range(); for (long i = range.lowerEndpoint(); i <= range.upperEndpoint() ; i++) { results.add(NetworkUtils.longToIpv4String(i)); } } return results; }
public long size() { long size = 0L; for (Range<Long> range : rangeSet.asRanges()) { range = ContiguousSet.create(range, DiscreteDomain.longs()).range(); size += (range.upperEndpoint() - range.lowerEndpoint() + 1); } return size; }
/** * Returns a nonempty contiguous set containing all {@code long} values from {@code lower} * (inclusive) to {@code upper} (inclusive). (These are the same values contained in {@code * Range.closed(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closed(long lower, long upper) { return create(Range.closed(lower, upper), DiscreteDomain.longs()); }
/** * Returns a nonempty contiguous set containing all {@code long} values from {@code lower} * (inclusive) to {@code upper} (inclusive). (These are the same values contained in {@code * Range.closed(lower, upper)}.) * * @throws IllegalArgumentException if {@code lower} is greater than {@code upper} * @since 23.0 */ @Beta public static ContiguousSet<Long> closed(long lower, long upper) { return create(Range.closed(lower, upper), DiscreteDomain.longs()); }
public void trackMissingEntriesWithIdBetweenPreviousAndCurrentEntry(final SeenEntry currentEntry, final Optional<SeenEntry> previousEntry) { final boolean gapExistsBetweenEntryIds = previousEntry.isPresent() && currentEntry.id.asNumeric() > nextExpectedId(previousEntry); if (gapExistsBetweenEntryIds) { final ContiguousSet<Long> missingIds = create(Range.closedOpen(nextExpectedId(previousEntry), currentEntry.id.asNumeric()), longs()); for (final long nextMissingId : missingIds) { feedTracker.track(new SeenEntry(EntryId.of(String.valueOf(nextMissingId)), currentEntry.dateTime)); } } }