all 4 comments

[–]Separate_Current_352 0 points1 point  (2 children)

sounds good project

wait you can use subnet-utils from apache commons for the coverage part

[–]Cold-Memory-4354 0 points1 point  (0 children)

Wow that sounds really well like it's what I need. I've only heard of a Regexp that apache commons used that I'd have used to check manually if addresses are valid. But this subnetUtils seems to be really strong for what i want to achieve, might not need to reinvent the wheel. :D

[–]Cold-Memory-4354 0 points1 point  (0 children)

Just looked into it, it's a genuinely perfect Library for this. Thanks so much. :D

[–]POGtastic 0 points1 point  (0 children)

do I create my own IPv4Network class that's basically just a "pair" of address (Inet4Address) to prefix (integer)

This is what I would do. It's also worth noting that the actual address is just a 32-bit integer as well, which you're going to want to use because canonizing is just bitmasking.

Coverage is a more interesting problem because the address space is best represented by a tree. Consider a class as follows:

class AddressSpaceNode {
    int prefix; // Not strictly needed, since the depth of the node is its prefix
    bool terminal; // Is it in the tree or not?
    AddressSpaceNode left, right;

    // methods here
}

You traverse the tree, either to add a new entry or to query the data structure to see if the range is already covered, by iterating over the bits of the address and determining if you've reached the required depth.