- private static List<String> parseIpv6Address(final List<String> addressGroups) {
- int countEmpty = 0;
- for (String group : addressGroups) {
- if (group.equals("")) {
- countEmpty++;
- }
- }
- List<String> ready = new ArrayList<>(EncodeConstants.GROUPS_IN_IPV6_ADDRESS);
- switch (countEmpty) {
- case 0:
- ready = addressGroups;
- break;
- case 1:
- int zerosToBePushed = EncodeConstants.GROUPS_IN_IPV6_ADDRESS - addressGroups.size() + 1;
- for (String group : addressGroups) {
- if (group.equals("")) {
- for (int j = 0; j < zerosToBePushed; j++) {
- ready.add("0");
- }
- } else {
- ready.add(group);
- }
- }
- break;
- case 2:
- String[] tmp = new String[EncodeConstants.GROUPS_IN_IPV6_ADDRESS];
- Arrays.fill(tmp, "0");
- tmp[EncodeConstants.GROUPS_IN_IPV6_ADDRESS - 1] =
- addressGroups.get(addressGroups.size() - 1);
- ready = Arrays.asList(tmp);
- break;
- default:
- throw new IllegalStateException("Incorrect ipv6 address");
- }
- return ready;
- }