ConfigUtils { public static List<String> mergeValues(Class<?> type, String cfg, List<String> def) { List<String> defaults = new ArrayList<String>(); if (def != null) { for (String name : def) { if (ExtensionLoader.getExtensionLoader(type).hasExtension(name)) { defaults.add(name); } } } List<String> names = new ArrayList<String>(); String[] configs = (cfg == null || cfg.trim().length() == 0) ? new String[0] : COMMA_SPLIT_PATTERN.split(cfg); for (String config : configs) { if (config != null && config.trim().length() > 0) { names.add(config); } } if (!names.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) { int i = names.indexOf(DEFAULT_KEY); if (i > 0) { names.addAll(i, defaults); } else { names.addAll(0, defaults); } names.remove(DEFAULT_KEY); } else { names.remove(DEFAULT_KEY); } for (String name : new ArrayList<String>(names)) { if (name.startsWith(REMOVE_VALUE_PREFIX)) { names.remove(name); names.remove(name.substring(1)); } } return names; } private  ConfigUtils(); static boolean isNotEmpty(String value); static boolean isEmpty(String value); static boolean isDefault(String value); static List<String> mergeValues(Class<?> type, String cfg, List<String> def); static String replaceProperty(String expression, Map<String, String> params); static Properties getProperties(); static void setProperties(Properties properties); static void addProperties(Properties properties); static String getProperty(String key); @SuppressWarnings({"unchecked", "rawtypes"}) static String getProperty(String key, String defaultValue); static String getSystemProperty(String key); static Properties loadProperties(String fileName); static Properties loadProperties(String fileName, boolean allowMultiFile); static Properties loadProperties(String fileName, boolean allowMultiFile, boolean optional); static int getPid();  }
@Test public void testMergeValues() { List<String> merged = ConfigUtils.mergeValues(ThreadPool.class, "aaa,bbb,default.custom", asList("fixed", "default.limited", "cached")); assertEquals(asList("fixed", "cached", "aaa", "bbb", "default.custom"), merged); }
@Test public void testMergeValuesAddDefault() { List<String> merged = ConfigUtils.mergeValues(ThreadPool.class, "aaa,bbb,default,zzz", asList("fixed", "default.limited", "cached")); assertEquals(asList("aaa", "bbb", "fixed", "cached", "zzz"), merged); }
@Test public void testMergeValuesDeleteDefault() { List<String> merged = ConfigUtils.mergeValues(ThreadPool.class, "-default", asList("fixed", "default.limited", "cached")); assertEquals(asList(), merged); }
@Test public void testMergeValuesDeleteDefault_2() { List<String> merged = ConfigUtils.mergeValues(ThreadPool.class, "-default,aaa", asList("fixed", "default.limited", "cached")); assertEquals(asList("aaa"), merged); }
@Test public void testMergeValuesDelete() { List<String> merged = ConfigUtils.mergeValues(ThreadPool.class, "-fixed,aaa", asList("fixed", "default.limited", "cached")); assertEquals(asList("cached", "aaa"), merged); }