public AutoExpandingMap(Mapper<K, V> valueFactory) { super(Coll.synchronizedMap()); this.valueFactory = valueFactory; }
public static <K1, K2, V> Map<K1, Map<K2, V>> mapOfMaps() { return autoExpandingMap(src -> synchronizedMap()); }
public static BeanProperties from(List<Prop> properties) { Map<String, Prop> map = Coll.synchronizedMap(); for (Prop prop : properties) { map.put(prop.getName(), prop); } return new BeanProperties(map); }
public static BeanProperties from(Map<String, ?> map) { Map<String, Prop> properties = Coll.synchronizedMap(); for (Entry<?, ?> e : map.entrySet()) { Object key = e.getKey(); Prop prop = new MapProp(String.valueOf(key), key, Cls.of(e.getValue())); properties.put(prop.getName(), prop); } return new BeanProperties(properties); }
private Map<String, Object> asMap() { makeSureIsInitialized(); if (isRoot) { return base.properties; } else { synchronized (base.properties) { Map<String, Object> props = base.properties; for (String key : baseKeys) { Object value = props.computeIfAbsent(key, k -> Coll.synchronizedMap()); if (value instanceof Map<?, ?>) { props = (Map<String, Object>) value; } else { throw U.rte("Expected a Map for configuration section '%s', but found value of type: %s", sectionTo(key), value.getClass().getSimpleName()); } } return props; } } }
@Override public synchronized Screen addSubMenuItem(String targetUrl, int order, String caption, int subItemOrder, String subItemCaption) { U.must(U.notEmpty(targetUrl), "The target URL cannot be empty!"); String key = menuKey(order, caption); Map<String, Object> subMenu = U.cast(menu.computeIfAbsent(key, x -> Coll.synchronizedMap())); String subKey = menuKey(subItemOrder, subItemCaption); subMenu.put(subKey, targetUrl); return this; }
@SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> clazz) { Err.argMust(clazz != AutoExpandingMap.class, "Cannot instantiate AutoExpandingMap!"); if (clazz == List.class) { return (T) U.list(); } else if (clazz == Set.class) { return (T) U.set(); } else if (clazz == Map.class) { return (T) U.map(); } else if (clazz == ConcurrentMap.class) { return (T) Coll.concurrentMap(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedSet")) { return (T) Coll.synchronizedSet(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedList")) { return (T) Coll.synchronizedList(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedMap")) { return (T) Coll.synchronizedMap(); } else if (clazz == Var.class) { return (T) Vars.var("<new>", null); } else if (clazz == Object.class) { return (T) new Object(); } return newBeanInstance(clazz); }