public List<InetAddress> addresses(String inetHost, ResolvedAddressTypes resolvedAddressTypes) {
        String normalized = normalize(inetHost);
        ensureHostsFileEntriesAreFresh();

        switch (resolvedAddressTypes) {
            case IPV4_ONLY:
                return inet4Entries.get(normalized);
            case IPV6_ONLY:
                return inet6Entries.get(normalized);
            case IPV4_PREFERRED:
                List<InetAddress> allInet4Addresses = inet4Entries.get(normalized);
                return allInet4Addresses != null ? allAddresses(allInet4Addresses, inet6Entries.get(normalized)) :
                        inet6Entries.get(normalized);
            case IPV6_PREFERRED:
                List<InetAddress> allInet6Addresses = inet6Entries.get(normalized);
                return allInet6Addresses != null ? allAddresses(allInet6Addresses, inet4Entries.get(normalized)) :
                        inet4Entries.get(normalized);
            default:
                throw new IllegalArgumentException("Unknown ResolvedAddressTypes " + resolvedAddressTypes);
        }
    }
@Test
    public void shouldPickIpv4FirstWhenBothAreDefinedButIpv4IsPreferred() {
        HostsFileEntriesProvider.Parser parser = givenHostsParserWith(
                LOCALHOST_V4_ADDRESSES,
                LOCALHOST_V6_ADDRESSES
        );

        DefaultHostsFileEntriesResolver resolver = new DefaultHostsFileEntriesResolver(parser, ENTRIES_TTL);

        List<InetAddress> addresses = resolver.addresses("localhost", ResolvedAddressTypes.IPV4_PREFERRED);
        assertNotNull(addresses);
        assertEquals(2, addresses.size());
        assertThat("Should pick an IPv4 address", addresses.get(0), instanceOf(Inet4Address.class));
        assertThat("Should pick an IPv6 address", addresses.get(1), instanceOf(Inet6Address.class));
    }