ConfigBag { @Beta @SuppressWarnings("unchecked") public <T> ConfigBag copyKeyAs(ConfigBag source, ConfigKey<T> sourceKey, ConfigKey<T> targetKey) { Maybe<Object> sourceValue = source.getRawKeyMaybe(sourceKey, true); if (sourceValue.isPresent()) { put(targetKey, (T) sourceValue.get()); } return this; } ConfigBag(); private  ConfigBag(Map<String,Object> storage); static ConfigBag newInstance(); static ConfigBag newLiveInstance(Map<String,Object> storage); static ConfigBag newInstance(Map<?, ?> config); static ConfigBag newInstanceCopying(final ConfigBag configBag); @Beta static ConfigBag newInstanceExtending(final ConfigBag parentBag); @Beta static ConfigBag newInstanceExtending(final ConfigBag configBag, Map<?,?> optionalAdditionalValues); ConfigBag setDescription(String description); String getDescription(); synchronized Map<String,Object> getAllConfig(); synchronized Map<ConfigKey<?>, ?> getAllConfigAsConfigKeyMap(); Map<String,Object> getAllConfigMutable(); synchronized Map<String,Object> getUnusedConfig(); Map<String,Object> getUnusedConfigMutable(); ConfigBag putAll(Map<?,?> addlConfig); ConfigBag putAll(ConfigBag addlConfig); void forEach(BiConsumer<String,Object> action); ConfigBag putIfAbsent(ConfigKey<T> key, T value); ConfigBag putAsStringKeyIfAbsent(Object key, Object value); synchronized ConfigBag putIfAbsent(Map<?, ?> propertiesToSet); ConfigBag putIfAbsent(ConfigBag addlConfig); @SuppressWarnings("unchecked") T put(ConfigKey<T> key, T value); ConfigBag putIfNotNull(ConfigKey<T> key, T value); ConfigBag putIfAbsentAndNotNull(ConfigKey<T> key, T value); ConfigBag configure(ConfigKey<T> key, T value); ConfigBag configureStringKey(String key, T value); synchronized Object putStringKey(String key, Object value); Object putStringKeyIfHasValue(String key, Maybe<?> value); Object putStringKeyIfNotNull(String key, Object value); boolean containsKey(HasConfigKey<?> key); boolean containsKey(ConfigKey<?> key); synchronized boolean containsKey(String key); T get(ConfigKey<T> key); Object getStringKey(String key); @Nonnull Maybe<Object> getStringKeyMaybe(String key); @Beta Maybe<Object> getObjKeyMaybe(Object key); @Beta ConfigBag copyKey(ConfigBag source, ConfigKey<T> key); @Beta ConfigBag copyKeys(ConfigBag source, ConfigKey<T> ...keys); @Beta @SuppressWarnings("unchecked") ConfigBag copyKeyAs(ConfigBag source, ConfigKey<T> sourceKey, ConfigKey<T> targetKey); T peek(ConfigKey<T> key); synchronized T getFirst(ConfigKey<T> preferredKey, ConfigKey<T> ...otherCurrentKeysInOrderOfPreference); @Deprecated Object getWithDeprecation(ConfigKey<?> key, ConfigKey<?> ...deprecatedKeys); @Deprecated synchronized Object getWithDeprecation(ConfigKey<?>[] currentKeysInOrderOfPreference, ConfigKey<?> ...deprecatedKeys); Maybe<T> ifPresent(ConfigKey<T> key); static T coerceFirstNonNullKeyValue(ConfigKey<T> key, Object ...values); synchronized void markUsed(String key); synchronized void clear(); ConfigBag removeAll(ConfigKey<?> ...keys); synchronized void remove(ConfigKey<?> key); ConfigBag removeAll(Iterable<String> keys); synchronized void remove(String key); ConfigBag copy(ConfigBag other); synchronized int size(); synchronized boolean isEmpty(); ConfigBag markAll(Iterable<String> usedFlags); synchronized boolean isUnused(ConfigKey<?> key); ConfigBag seal(); Map<String, Object> getAllConfigRaw(); @Override String toString(); static final ConfigBag EMPTY; }
@Test public void testCopyKeyAs() throws InterruptedException { ConfigBag bag = ConfigBag.newInstance(); bag.put(K1, "v1"); ConfigBag bag2 = ConfigBag.newInstance(); bag2.copyKeyAs(bag, K1, K2); assertEquals(bag2.get(K2), "v1"); assertFalse(bag2.containsKey(K1)); }