I currently have a solution using two HashMaps with matching keys that link the values together (i.e Key: prefix length, Values: Subnet Mask/Number of Addresses available).
Is there a significant design issue here and would it be better practice to merge these HashMaps together using a Tuple value-type, increasing complexity over two simple Maps? - Similar questions give both options but don't seem to give scenarios for when to use one over the other.
Example below for the implementation:
private static HashMap<Integer, Integer> prefixAndNumberOfAddresses;
private static HashMap<Integer, String> prefixAndSubnets;
static {
prefixAndNumberOfAddresses = new HashMap<Integer, Integer>();
prefixAndNumberOfAddresses.put(8, 16777214);
prefixAndNumberOfAddresses.put(9, 8388606);
prefixAndNumberOfAddresses.put(10, 4194302);
prefixAndNumberOfAddresses.put(11, 2097150);
prefixAndNumberOfAddresses.put(12, 1048574);
prefixAndNumberOfAddresses.put(13, 524286);
prefixAndNumberOfAddresses.put(14, 262142);
prefixAndNumberOfAddresses.put(15, 131070);
prefixAndNumberOfAddresses.put(16, 65534);
prefixAndNumberOfAddresses.put(17, 32766);
prefixAndNumberOfAddresses.put(18, 16382);
prefixAndNumberOfAddresses.put(19, 8190);
prefixAndNumberOfAddresses.put(20, 4094);
prefixAndNumberOfAddresses.put(21, 2046);
prefixAndNumberOfAddresses.put(22, 1022);
prefixAndNumberOfAddresses.put(23, 510);
prefixAndNumberOfAddresses.put(24, 254);
prefixAndNumberOfAddresses.put(25, 126);
prefixAndNumberOfAddresses.put(26, 62);
prefixAndNumberOfAddresses.put(27, 30);
prefixAndNumberOfAddresses.put(28, 14);
prefixAndNumberOfAddresses.put(29, 6);
prefixAndNumberOfAddresses.put(30, 2);
}
static {
prefixAndSubnets = new HashMap<Integer, String>();
prefixAndSubnets.put(8, "255.0.0.0");
prefixAndSubnets.put(9, "255.128.0.0");
prefixAndSubnets.put(10, "255.192.0.0");
prefixAndSubnets.put(11, "255.224.0.0");
prefixAndSubnets.put(12, "255.240.0.0");
prefixAndSubnets.put(13, "255.248.0.0");
prefixAndSubnets.put(14, "255.252.0.0");
prefixAndSubnets.put(15, "255.254.0.0");
prefixAndSubnets.put(16, "255.255.0.0");
prefixAndSubnets.put(17, "255.255.128.0");
prefixAndSubnets.put(18, "255.255.192.0");
prefixAndSubnets.put(19, "255.255.224.0");
prefixAndSubnets.put(20, "255.255.240.0");
prefixAndSubnets.put(21, "255.255.248.0");
prefixAndSubnets.put(22, "255.255.252.0");
prefixAndSubnets.put(23, "255.255.254.0");
prefixAndSubnets.put(24, "255.255.255.0");
prefixAndSubnets.put(25, "255.255.255.128");
prefixAndSubnets.put(26, "255.255.255.192");
prefixAndSubnets.put(27, "255.255.255.224");
prefixAndSubnets.put(28, "255.255.255.240");
prefixAndSubnets.put(29, "255.255.255.248");
prefixAndSubnets.put(30, "255.255.255.252");
}