List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:Main.java
public static void main(String[] a) { // create singleton map Map<String, String> map = Collections.singletonMap("key", "Value"); System.out.println("Singleton map is: " + map); }
From source file:MainClass.java
public static void main(String[] a) { System.out.println(Collections.singletonList("a")); System.out.println(Collections.singleton("a")); System.out.println(Collections.singletonMap("a", "b")); }
From source file:Main.java
public static <K, V> Map<K, V> map1(K key, V value) { return Collections.singletonMap(key, value); }
From source file:Maps.java
public static <K, V> Map<K, V> create(K key, V value) { return Collections.singletonMap(key, value); }
From source file:Main.java
public static <K, V> Entry<K, V> mapEntry(K key, V value) { return Collections.singletonMap(key, value).entrySet().iterator().next(); }
From source file:Main.java
/** * Create a map with one key and a corresponding value. * * @param key0 the key//from ww w . ja v a 2s. co m * @param value0 the value * @param <K> key type * @param <V> value type * @return map with one entry */ public static <K, V> Map<K, V> map(K key0, V value0) { return Collections.singletonMap(key0, value0); }
From source file:Main.java
private static Map<Object, Object> createMap(Object... keysAndValues) { switch (keysAndValues.length) { case 0://from w w w . j a va 2s .co m return Collections.emptyMap(); case 2: return Collections.singletonMap(keysAndValues[0], keysAndValues[1]); } if (keysAndValues.length % 2 == 1) { throw new IllegalArgumentException("Odd number of createMap arguments"); } final Map<Object, Object> map = new HashMap<Object, Object>(); for (int i = 0; i < keysAndValues.length; i += 2) { map.put(keysAndValues[i], keysAndValues[i + 1]); } return map; }
From source file:Main.java
static <K, V> Map<K, V> getMap(Map<K, V> orig) { if (orig == null || orig.size() == 0) { return Collections.emptyMap(); } else if (orig.size() == 1) { final Map.Entry<K, V> entry = orig.entrySet().iterator().next(); return Collections.singletonMap(entry.getKey(), entry.getValue()); } else {//from w ww . ja va 2s .c om return Collections.unmodifiableMap(new TreeMap<>(orig)); } }
From source file:com.joshlong.activiti.coordinator.registration1.distribution.producer.RegistrationProducerMain.java
/** * continues generating new processes until it reaches a certain count *///from w ww.ja v a 2s .c o m static void doContinuousIterationUpUntil(ApplicationContext ctx, int counter) throws Throwable { ProcessEngine processEngine = ctx.getBean(ProcessEngine.class); for (int customerId = 0; customerId < counter; customerId++) { Map<String, Object> vars = Collections.singletonMap("customerId", (Object) customerId); processEngine.getRuntimeService().startProcessInstanceByKey("customer-fullfillment-process", vars); } while (true) Thread.sleep(10000); }
From source file:Maps.java
public static <K, V> Map<K, V> put(Map<K, V> map, K key, V value) { switch (map.size()) { case 0://from ww w . j ava 2s .c o m // Empty -> Singleton return Collections.singletonMap(key, value); case 1: { if (map.containsKey(key)) { return create(key, value); } // Singleton -> HashMap Map<K, V> result = new HashMap<K, V>(); result.put(map.keySet().iterator().next(), map.values().iterator().next()); result.put(key, value); return result; } default: // HashMap map.put(key, value); return map; } }