@Test public void testGetIpRangeSet() { AddressGroup group = new AddressGroup("group"); Map<String, AddressGroup> groupMap = ImmutableMap.of(group.getName(), group); assertThat(group.getIpRangeSet(ImmutableMap.of(), groupMap), equalTo(ImmutableRangeSet.of())); String addrObjName = "addrObj"; group.addMember(addrObjName); assertThat(group.getIpRangeSet(ImmutableMap.of(), groupMap), equalTo(ImmutableRangeSet.of())); AddressObject addressObj = new AddressObject(addrObjName); Map<String, AddressObject> addrObjects = ImmutableMap.of(addressObj.getName(), addressObj); assertThat(group.getIpRangeSet(addrObjects, groupMap), equalTo(ImmutableRangeSet.of())); addressObj.setIp(Ip.ZERO); assertThat( group.getIpRangeSet(addrObjects, groupMap), equalTo(ImmutableRangeSet.of(Range.singleton(Ip.ZERO)))); addressObj.setPrefix(IpPrefix.ZERO); assertThat( group.getIpRangeSet(addrObjects, groupMap), equalTo(ImmutableRangeSet.of(Range.closed(Ip.ZERO, Ip.MAX)))); Range<Ip> range = Range.closed(Ip.ZERO, Ip.parse("1.1.1.1")); addressObj.setIpRange(range); assertThat(group.getIpRangeSet(addrObjects, groupMap), equalTo(ImmutableRangeSet.of(range))); Range<Ip> range2 = Range.closed(Ip.parse("1.0.0.0"), Ip.parse("2.0.0.0")); AddressObject addressObj2 = new AddressObject("addressObj2"); addressObj2.setIpRange(range2); group.addMember(addressObj2.getName()); Map<String, AddressObject> bothObjectsMap = ImmutableMap.of(addressObj.getName(), addressObj, addressObj2.getName(), addressObj2); assertThat( group.getIpRangeSet(bothObjectsMap, groupMap), equalTo(ImmutableRangeSet.of(Range.closed(Ip.ZERO, Ip.parse("2.0.0.0"))))); }
public RangeSet<Ip> getIpRangeSet( Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups) { RangeSet<Ip> rangeSet = TreeRangeSet.create(); getDescendantObjects(addressObjects, addressGroups, new HashSet<>()).stream() .map(addrObjName -> addressObjects.get(addrObjName).getAddressAsRangeSet()) .forEach(rangeSet::addAll); return ImmutableRangeSet.copyOf(rangeSet); }
AddressGroup implements Serializable { public RangeSet<Ip> getIpRangeSet( Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups) { RangeSet<Ip> rangeSet = TreeRangeSet.create(); getDescendantObjects(addressObjects, addressGroups, new HashSet<>()).stream() .map(addrObjName -> addressObjects.get(addrObjName).getAddressAsRangeSet()) .forEach(rangeSet::addAll); return ImmutableRangeSet.copyOf(rangeSet); } }
AddressGroup implements Serializable { public RangeSet<Ip> getIpRangeSet( Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups) { RangeSet<Ip> rangeSet = TreeRangeSet.create(); getDescendantObjects(addressObjects, addressGroups, new HashSet<>()).stream() .map(addrObjName -> addressObjects.get(addrObjName).getAddressAsRangeSet()) .forEach(rangeSet::addAll); return ImmutableRangeSet.copyOf(rangeSet); } AddressGroup(String name); }
AddressGroup implements Serializable { public RangeSet<Ip> getIpRangeSet( Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups) { RangeSet<Ip> rangeSet = TreeRangeSet.create(); getDescendantObjects(addressObjects, addressGroups, new HashSet<>()).stream() .map(addrObjName -> addressObjects.get(addrObjName).getAddressAsRangeSet()) .forEach(rangeSet::addAll); return ImmutableRangeSet.copyOf(rangeSet); } AddressGroup(String name); IpSpace getIpSpace(
      Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups); RangeSet<Ip> getIpRangeSet(
      Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups); @Nullable String getDescription(); @Nullable String getFilter(); void addMember(String member); Set<String> getMembers(); String getName(); @Nonnull Set<String> getTags(); @Nullable Type getType(); void setDescription(String description); void setFilter(String filter); }
AddressGroup implements Serializable { public RangeSet<Ip> getIpRangeSet( Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups) { RangeSet<Ip> rangeSet = TreeRangeSet.create(); getDescendantObjects(addressObjects, addressGroups, new HashSet<>()).stream() .map(addrObjName -> addressObjects.get(addrObjName).getAddressAsRangeSet()) .forEach(rangeSet::addAll); return ImmutableRangeSet.copyOf(rangeSet); } AddressGroup(String name); IpSpace getIpSpace(
      Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups); RangeSet<Ip> getIpRangeSet(
      Map<String, AddressObject> addressObjects, Map<String, AddressGroup> addressGroups); @Nullable String getDescription(); @Nullable String getFilter(); void addMember(String member); Set<String> getMembers(); String getName(); @Nonnull Set<String> getTags(); @Nullable Type getType(); void setDescription(String description); void setFilter(String filter);  }