/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
public void testRange_unboundedRange() { assertEquals( Range.closed(Integer.MIN_VALUE, Integer.MAX_VALUE), ContiguousSet.create(Range.<Integer>all(), integers()).range()); assertEquals( Range.atLeast(Integer.MIN_VALUE), ContiguousSet.create(Range.<Integer>all(), integers()).range(CLOSED, OPEN)); assertEquals( Range.all(), ContiguousSet.create(Range.<Integer>all(), integers()).range(OPEN, OPEN)); assertEquals( Range.atMost(Integer.MAX_VALUE), ContiguousSet.create(Range.<Integer>all(), integers()).range(OPEN, CLOSED)); }
public void testRange() { assertEquals(Range.closed(1, 3), ContiguousSet.create(Range.closed(1, 3), integers()).range()); assertEquals(Range.closed(1, 3), ContiguousSet.closed(1, 3).range()); assertEquals( Range.closed(1, 3), ContiguousSet.create(Range.closedOpen(1, 4), integers()).range()); assertEquals(Range.closed(1, 3), ContiguousSet.closedOpen(1, 4).range()); assertEquals(Range.closed(1, 3), ContiguousSet.create(Range.open(0, 4), integers()).range()); assertEquals( Range.closed(1, 3), ContiguousSet.create(Range.openClosed(0, 3), integers()).range()); ContiguousSet.create(Range.closed(1, 3), integers()).range(OPEN, CLOSED)); assertEquals( Range.openClosed(0, 3), ContiguousSet.create(Range.closedOpen(1, 4), integers()).range(OPEN, CLOSED)); assertEquals( Range.openClosed(0, 3), ContiguousSet.create(Range.open(0, 4), integers()).range(OPEN, CLOSED)); assertEquals( Range.openClosed(0, 3), ContiguousSet.create(Range.openClosed(0, 3), integers()).range(OPEN, CLOSED)); Range.open(0, 4), ContiguousSet.create(Range.closed(1, 3), integers()).range(OPEN, OPEN)); assertEquals( Range.open(0, 4), ContiguousSet.create(Range.closedOpen(1, 4), integers()).range(OPEN, OPEN)); assertEquals( Range.open(0, 4), ContiguousSet.create(Range.open(0, 4), integers()).range(OPEN, OPEN)); assertEquals( Range.open(0, 4), ContiguousSet.create(Range.openClosed(0, 3), integers()).range(OPEN, OPEN));
@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 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; }
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; }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); } }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); } }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
/** Returns a short-hand representation of the contents such as {@code "[1..100]"}. */ @Override public String toString() { return range().toString(); }
@Override public void serialize(NumberRange value, JsonGenerator gen, SerializerProvider serializers) throws IOException { Range<Long> range = ContiguousSet.create(value.asRange(), DiscreteDomain.longs()).range(); gen.writeStartObject(); if (range.lowerEndpoint() != 0L) { gen.writeNumberField("from", range.lowerEndpoint()); } gen.writeNumberField("to", range.upperEndpoint()); gen.writeEndObject(); } }
public void testRange_unboundedRange() { assertEquals(Range.closed(Integer.MIN_VALUE, Integer.MAX_VALUE), ContiguousSet.create(Range.<Integer>all(), integers()).range()); assertEquals(Range.atLeast(Integer.MIN_VALUE), ContiguousSet.create(Range.<Integer>all(), integers()).range(CLOSED, OPEN)); assertEquals(Range.all(), ContiguousSet.create(Range.<Integer>all(), integers()).range(OPEN, OPEN)); assertEquals(Range.atMost(Integer.MAX_VALUE), ContiguousSet.create(Range.<Integer>all(), integers()).range(OPEN, CLOSED)); }