protected Map<Entity, T> copyOfValues() { // Don't use ImmutableMap, as can contain null values synchronized (values) { return Collections.unmodifiableMap(MutableMap.copyOf(values)); } }
ParsedSpec(String spec, List<String> partsList, Map<String,String> argsMap) { this.spec = spec; this.partsList = ImmutableList.copyOf(partsList); this.argsMap = Collections.unmodifiableMap(MutableMap.copyOf(argsMap)); } }
/** * Returns policy properties. In this case, type or name are not considered as properties. * @param policyData */ public Map<String, ?> getPolicyProperties(Map<String, ?> policyData){ Map<String, ?> data = MutableMap.copyOf(policyData); data.remove(POLICY_FLAG_NAME); data.remove(POLICY_FLAG_TYPE); return data; } }
/** current values for all entries which have not yet been used * @return non-modifiable map of strings to object */ public synchronized Map<String,Object> getUnusedConfig() { return MutableMap.copyOf(unusedConfig).asUnmodifiable(); }
@Override public Map<String, Object> asMapWithStringKeys() { synchronized (contents) { return MutableMap.copyOf(contents).asUnmodifiable(); } }
@Override protected Map<String, Object> merge(Map<String, Object> base, Map<String, Object> subkeys, boolean unmodifiable) { Map<String, Object> result = MutableMap.copyOf(base).add(subkeys); if (unmodifiable) result = Collections.unmodifiableMap(result); return result; }
public static ServiceCharacteristic of(Map<String, Object> req) { Map<String,Object> attrs = MutableMap.copyOf(req); ServiceCharacteristic result = new ServiceCharacteristic(); result.name = (String) attrs.remove("name"); result.description = (String) attrs.remove("description"); result.characteristicType = (String) Yamls.removeMultinameAttribute(attrs, "characteristicType", "type"); // TODO fulfillment result.customAttributes = attrs; return result; }
private <T> Map<Entity, T> copyValues(Sensor<T> sensor) { synchronized (values) { @SuppressWarnings("unchecked") Map<Entity, T> sv = (Map<Entity, T>) values.get(sensor.getName()); //use MutableMap because of potentially null values return MutableMap.copyOf(sv).asUnmodifiable(); } }
@Override protected Object compute() { Map<Entity, Object> ks = MutableMap.copyOf(Maps.filterValues(getValues(keySensor), valueFilter)); Map<Entity, Object> vs = MutableMap.copyOf(Maps.filterValues(getValues(valueSensor), valueFilter)); MutableMap<Object, Object> result = MutableMap.of(); for (Entity entity : ks.keySet()) { if (vs.containsKey(entity)) { result.put(ks.get(entity), vs.get(entity)); } } return result; }
public void clearConfigKeys() { Map<String, FieldAndValue<ConfigKey<?>>> oldKeys = MutableMap.copyOf(configKeys); configKeys.clear(); invalidateSnapshot(); for (FieldAndValue<ConfigKey<?>> k: oldKeys.values()) { instance.sensors().emit(AbstractEntity.CONFIG_KEY_REMOVED, k.value); } }
public static <K, V> V put(Entity entity, AttributeSensor<Map<K,V>> attribute, K key, V value) { Map<K, V> oldMap = entity.getAttribute(attribute); Map<K, V> newMap = MutableMap.copyOf(oldMap); V oldVal = newMap.put(key, value); ((EntityInternal)entity).sensors().set(attribute, newMap); return oldVal; }
@Override public Map<String, String> getShellEnvironment() { Entity etcdNode = getEntity().config().get(CalicoNode.ETCD_NODE); HostAndPort etcdAuthority = HostAndPort.fromParts(etcdNode.sensors().get(Attributes.SUBNET_ADDRESS), etcdNode.sensors().get(EtcdNode.ETCD_CLIENT_PORT)); Map<String, String> environment = MutableMap.copyOf(super.getShellEnvironment()); environment.put("ETCD_AUTHORITY", etcdAuthority.toString()); return environment; }
@Test(enabled=false) public void testListPutDirectUsageMultiValues() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()), ImmutableList.of("x", "w", "x")); log.info("List-Direct: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "w", "x")); }
public void testMapDirectUsage() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_MAP_OBJ_THING.getName()), ImmutableMap.<String,Object>of("a", 1)); log.info("Map-Direct: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_MAP_OBJ_THING), ImmutableMap.<String,Object>of("a", 1)); }
public void testListModUsage() throws Exception { entity.config().set(TestEntity.CONF_LIST_THING, ListModifications.add("x", "x")); log.info("List-Mod: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "x")); }
public void testSetDotExtensionUsage() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_SET_THING.getName()+".a"), "x"); log.info("Set-DotExt: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of("x")); }
@Test(enabled=false) public void testListSubKeyUsageMultiValues() throws Exception { entity.config().set(TestEntity.CONF_LIST_THING.subKey(), "x"); entity.config().set(TestEntity.CONF_LIST_THING.subKey(), "w"); entity.config().set(TestEntity.CONF_LIST_THING.subKey(), "x"); log.info("List-SubKey: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "w", "x")); }
public void testListDotExtensionUsage() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".a"), "x"); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".b"), "x"); log.info("List-DotExt: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "x")); }
public void testSetManyWays() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_SET_THING.getName()), ImmutableSet.of("directX")); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_SET_THING.getName()+".dotext"), "dotextX"); entity.config().set(TestEntity.CONF_SET_THING.subKey(), "subkeyX"); log.info("Set-ManyWays: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of("directX", "subkeyX", "dotextX")); }
@Test(enabled=false) public void testListDotExtensionUsageMultiValues() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".a"), "x"); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".c"), "w"); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".b"), "x"); log.info("List-DotExt: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "w", "x")); }