android: Add ability to add a range set to another

This commit is contained in:
Tobias Brunner
2017-07-03 10:27:52 +02:00
parent a9875259e8
commit abf02a2176
2 changed files with 42 additions and 0 deletions
@@ -84,6 +84,21 @@ public class IPRangeSet implements Iterable<IPRange>
}
}
/**
* Add all ranges from the given set.
*/
public void add(IPRangeSet ranges)
{
if (ranges == this)
{
return;
}
for (IPRange range : ranges.mRanges)
{
add(range);
}
}
/**
* Add all ranges from the given collection to this set.
*/
@@ -142,6 +142,33 @@ public class IPRangeSetTest
new IPRange("255.255.255.255/32"));
}
@Test
public void testAddSet() throws UnknownHostException
{
IPRangeSet set = new IPRangeSet();
IPRangeSet other = new IPRangeSet();
other.add(new IPRange("192.168.1.0/24"));
other.add(new IPRange("10.0.1.0/24"));
other.add(new IPRange("255.255.255.255/32"));
set.add(other);
assertEquals("size", 3, set.size());
assertSubnets(set, new IPRange("10.0.1.0/24"), new IPRange("192.168.1.0/24"),
new IPRange("255.255.255.255/32"));
}
@Test
public void testAddSetIdent() throws UnknownHostException
{
IPRangeSet set = new IPRangeSet();
set.add(new IPRange("192.168.1.0/24"));
set.add(new IPRange("10.0.1.0/24"));
set.add(new IPRange("255.255.255.255/32"));
set.add(set);
assertEquals("size", 3, set.size());
assertSubnets(set, new IPRange("10.0.1.0/24"), new IPRange("192.168.1.0/24"),
new IPRange("255.255.255.255/32"));
}
@Test
public void testRemoveNothing() throws UnknownHostException
{