Skip to content

Instantly share code, notes, and snippets.

@techtangents
Created March 3, 2015 20:55
Show Gist options
  • Save techtangents/046fa08e522717dbb27d to your computer and use it in GitHub Desktop.
Save techtangents/046fa08e522717dbb27d to your computer and use it in GitHub Desktop.
package demo.maps;
import java.util.HashMap;
import java.util.Map;
import static demo.maps.MapUtils.P.p;
public class MapUtils {
private MapUtils() {
}
public static class P<A, B> {
public final A a;
public final B b;
public P(final A a, final B b) {
this.a = a;
this.b = b;
}
public static <A, B> P<A, B> p(final A a, final B b) {
return new P<A, B>(a, b);
}
}
public static <K, V> Map<K, V> m(final P<K, V>... ps) {
final Map<K, V> map = new HashMap<K, V>();
for (final P<K, V> p : ps) {
map.put(p.a, p.b);
}
return map;
}
static {
final Map<String, Integer> mymap = m(p("hello", 3), p("blah", 4), p("frog", 7));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment