class ImmutableMapFactory {

    public static <K, V> ImmutableMap<K, V> parseAndFilter(
            String s,
            Function<String, K> keyParser,
            Function<String, V> valueParser,
            BiPredicate<K, V> filter) {
        Builder<K, V> mapBuilder = ImmutableMap.builder();

        for (String objectAndWeight : s.split(";")) {
            String[] keyAndWeight = objectAndWeight.split(":");
            K key = keyParser.apply(keyAndWeight[0]);
            V value = valueParser.apply(keyAndWeight[1]);

            if (filter.test(key, value)) {
                mapBuilder.put(key, value);
            }
        }

        return mapBuilder.build();
    }

}