public static Multimap<String, String> includeFromKeysWhitelist( Multimap<String, String> records, Collection<String> keysWhitelist) { Check.notNull(records, "records"); Check.notNull(keysWhitelist, "keysWhitelist"); Multimap<String, String> result = Multimaps.filterKeys(records, Predicates.in(keysWhitelist)); return result; }
public static final void strictlyPositive(Long number, String argName) { Check.notNull(number, argName); if (number.intValue() < 1) { rejectEmptyParam(argName); } }
public static final void notEmpty(Map<?, ?> obj, String argName) { Check.notNull(obj, argName); if (obj.keySet().isEmpty()) { rejectEmptyParam(argName); } }
public static final void notEmpty(Long[] obj, String argName) { Check.notNull(obj, argName); if (obj.length <= 0) { rejectEmptyParam(argName); } }
public static final void notEmpty(Collection<?> coll, String argName) { Check.notNull(coll, argName); if (coll.size() < 1) { rejectEmptyParam(argName); } }
public static final void notEmpty(String obj, String argName) { Check.notNull(obj, argName); if (obj.trim().length() == 0) { rejectEmptyParam(argName); } }
public static Multimap<String, String> invertKeyValues(Multimap<String, String> multimap) { Check.notNull(multimap, "multimap"); Multimap<String, String> result = HashMultimap.create(); Multimaps.invertFrom(multimap, result); return result; }
public static Multimap<String, String> forMap(Map<String, Collection<String>> map) { Check.notNull(map, "map"); Multimap<String, String> result = HashMultimap.create(); for (String key : map.keySet()) { result.putAll(key, map.get(key)); } return result; }
public static Collection<List<String>> pairAndFlatten(Multimap<String, String> multimap) { Check.notNull(multimap, "multimap"); // for each key, create a new pairs based on the key + each value for that key // (kind of a narrower cartesian product of the multimap's keys and its values) Multimap<String, List<String>> listsOfPairsIndexedByTag = Multimaps.transformEntries(multimap, FunctionsUtil.asTuplesMultimap); // TODO: these tuples really should be proper DTOs LOG.trace( "listsOfPairsIndexedByTag: {} - {}", listsOfPairsIndexedByTag.size(), listsOfPairsIndexedByTag); // the final result is a list of Tuples (or DTOs) - ie. the flat multimap's values Collection<List<String>> result = listsOfPairsIndexedByTag.values(); LOG.trace("result: {} - {}", result.size(), result); return result; }