Java Code Examples for com.electronwill.nightconfig.core.Config#wrap()

The following examples show how to use com.electronwill.nightconfig.core.Config#wrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HoconParser.java    From night-config with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Object unwrap(Object o) {
	if (o instanceof Map) {
		Map<String, ?> map = (Map)o;
		Map<String, Object> unwrappedMap = new HashMap<>(map.size());
		for (Map.Entry<String, ?> entry : map.entrySet()) {
			unwrappedMap.put(entry.getKey(), unwrap(entry.getValue()));
		}
		return Config.wrap(unwrappedMap, HoconFormat.instance());
	} else if (o instanceof List) {
		List<?> list = (List<?>)o;
		if (!list.isEmpty() && list.get(0) instanceof Map) {
			List<Config> configList = new ArrayList<>();
			for (Object element : list) {
				configList.add((Config)unwrap(element));
			}
			return configList;
		}
	} else if (o == null) {
		return NULL_OBJECT;
	}
	return o;
}
 
Example 2
Source File: YamlParser.java    From night-config with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Object wrap(Object value) {
	if (value instanceof Map) {
		Map<String, Object> map = wrap((Map)value);
		return Config.wrap(map, configFormat);
	}
	if (value == null) {
		return NULL_OBJECT;
	}
	return value;
}