@Test public void testGetStringList() throws Exception { Assert.assertEquals(ConfigUtils.getStringList(ConfigFactory.parseMap(ImmutableMap.of("a.b", "1,2,3")), "a.b"), ImmutableList.of("1", "2", "3")); Assert.assertEquals(ConfigUtils.getStringList(ConfigFactory.parseMap(ImmutableMap.of("a.b", "\"1\",\"2\",\"3\"")), "a.b"), ImmutableList.of("1", "2", "3")); Assert.assertEquals(ConfigUtils.getStringList(ConfigFactory.parseMap(ImmutableMap.of("a.b", "\"1\",\"2,3\"")), "a.b"), ImmutableList.of("1", "2,3")); Assert.assertEquals(ConfigUtils.getStringList( ConfigFactory.empty().withValue("a.b", ConfigValueFactory.fromIterable(ImmutableList.of("1", "2","3"))), "a.b"), ImmutableList.of("1", "2", "3")); Assert.assertEquals(ConfigUtils.getStringList( ConfigFactory.empty().withValue("a.b", ConfigValueFactory.fromIterable(ImmutableList.of("\"1\"", "\"2\"","\"3\""))), "a.b"), ImmutableList.of("1", "2", "3")); Assert.assertEquals(ConfigUtils.getStringList( ConfigFactory.empty().withValue("a.b", ConfigValueFactory.fromIterable(ImmutableList.of("\"1\"", "\"2,3\""))), "a.b"), ImmutableList.of("1", "2,3")); Assert.assertEquals(ConfigUtils.getStringList(ConfigFactory.parseMap(ImmutableMap.of("key1", "value1,value2")), "key2"), ImmutableList.of()); Map<String,String> configMap = Maps.newHashMap(); configMap.put("key1", null); Assert.assertEquals(ConfigUtils.getStringList(ConfigFactory.parseMap(configMap), "key1"), ImmutableList.of()); configMap = Maps.newHashMap(); configMap.put("key2", ""); Assert.assertEquals(ConfigUtils.getStringList(ConfigFactory.parseMap(configMap), "key2"), ImmutableList.of()); }
public static List<String> getStringList(Config config, String path) { if (!config.hasPath(path)) { return Collections.emptyList(); } List<String> valueList = Lists.newArrayList(); try { valueList = config.getStringList(path); } catch (ConfigException.WrongType e) { if (StringUtils.isEmpty(config.getString(path))) { return Collections.emptyList(); } try (CSVReader csvr = new CSVReader(new StringReader(config.getString(path)));) { valueList = Lists.newArrayList(csvr.readNext()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } return Lists.newArrayList(Lists.transform(valueList, new Function<String, String>() { @Override public String apply(String input) { if (input == null) { return input; } return input.replaceAll("^\"|\"$", ""); } })); }
ConfigUtils { public static List<String> getStringList(Config config, String path) { if (!config.hasPath(path)) { return Collections.emptyList(); } List<String> valueList = Lists.newArrayList(); try { valueList = config.getStringList(path); } catch (ConfigException.WrongType e) { if (StringUtils.isEmpty(config.getString(path))) { return Collections.emptyList(); } try (CSVReader csvr = new CSVReader(new StringReader(config.getString(path)));) { valueList = Lists.newArrayList(csvr.readNext()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } return Lists.newArrayList(Lists.transform(valueList, new Function<String, String>() { @Override public String apply(String input) { if (input == null) { return input; } return input.replaceAll("^\"|\"$", ""); } })); } }
ConfigUtils { public static List<String> getStringList(Config config, String path) { if (!config.hasPath(path)) { return Collections.emptyList(); } List<String> valueList = Lists.newArrayList(); try { valueList = config.getStringList(path); } catch (ConfigException.WrongType e) { if (StringUtils.isEmpty(config.getString(path))) { return Collections.emptyList(); } try (CSVReader csvr = new CSVReader(new StringReader(config.getString(path)));) { valueList = Lists.newArrayList(csvr.readNext()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } return Lists.newArrayList(Lists.transform(valueList, new Function<String, String>() { @Override public String apply(String input) { if (input == null) { return input; } return input.replaceAll("^\"|\"$", ""); } })); } ConfigUtils(FileUtils fileUtils); }
ConfigUtils { public static List<String> getStringList(Config config, String path) { if (!config.hasPath(path)) { return Collections.emptyList(); } List<String> valueList = Lists.newArrayList(); try { valueList = config.getStringList(path); } catch (ConfigException.WrongType e) { if (StringUtils.isEmpty(config.getString(path))) { return Collections.emptyList(); } try (CSVReader csvr = new CSVReader(new StringReader(config.getString(path)));) { valueList = Lists.newArrayList(csvr.readNext()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } return Lists.newArrayList(Lists.transform(valueList, new Function<String, String>() { @Override public String apply(String input) { if (input == null) { return input; } return input.replaceAll("^\"|\"$", ""); } })); } ConfigUtils(FileUtils fileUtils); void saveConfigToFile(final Config config, final Path destPath); static Properties configToProperties(Config config); static Properties configToProperties(Config config, Optional<String> prefix); static Properties configToProperties(Config config, String prefix); static Config getConfigOrEmpty(Config config, String key); static State configToState(Config config); static Config propertiesToConfig(Properties properties); static Set<String> findFullPrefixKeys(Properties properties,
                                               Optional<String> keyPrefix); static Config propertiesToConfig(Properties properties, Optional<String> prefix); static String sanitizeFullPrefixKey(String propKey); static boolean sanitizedKey(String propKey); static String desanitizeKey(String propKey); static Config propertiesToTypedConfig(Properties properties, Optional<String> prefix); static String emptyIfNotPresent(Config config, String path); static String getString(Config config, String path, String def); static TimeUnit getTimeUnit(Config config, String path, TimeUnit def); static Long getLong(Config config, String path, Long def); static Integer getInt(Config config, String path, Integer def); static boolean getBoolean(Config config, String path, boolean def); static double getDouble(Config config, String path, double def); static Config getConfig(Config config, String path, Config def); static List<String> getStringList(Config config, String path); static boolean hasNonEmptyPath(Config config, String key); static boolean verifySubset(Config superConfig, Config subConfig); static Config resolveEncrypted(Config config, Optional<String> encConfigPath); }
ConfigUtils { public static List<String> getStringList(Config config, String path) { if (!config.hasPath(path)) { return Collections.emptyList(); } List<String> valueList = Lists.newArrayList(); try { valueList = config.getStringList(path); } catch (ConfigException.WrongType e) { if (StringUtils.isEmpty(config.getString(path))) { return Collections.emptyList(); } try (CSVReader csvr = new CSVReader(new StringReader(config.getString(path)));) { valueList = Lists.newArrayList(csvr.readNext()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } return Lists.newArrayList(Lists.transform(valueList, new Function<String, String>() { @Override public String apply(String input) { if (input == null) { return input; } return input.replaceAll("^\"|\"$", ""); } })); } ConfigUtils(FileUtils fileUtils); void saveConfigToFile(final Config config, final Path destPath); static Properties configToProperties(Config config); static Properties configToProperties(Config config, Optional<String> prefix); static Properties configToProperties(Config config, String prefix); static Config getConfigOrEmpty(Config config, String key); static State configToState(Config config); static Config propertiesToConfig(Properties properties); static Set<String> findFullPrefixKeys(Properties properties,
                                               Optional<String> keyPrefix); static Config propertiesToConfig(Properties properties, Optional<String> prefix); static String sanitizeFullPrefixKey(String propKey); static boolean sanitizedKey(String propKey); static String desanitizeKey(String propKey); static Config propertiesToTypedConfig(Properties properties, Optional<String> prefix); static String emptyIfNotPresent(Config config, String path); static String getString(Config config, String path, String def); static TimeUnit getTimeUnit(Config config, String path, TimeUnit def); static Long getLong(Config config, String path, Long def); static Integer getInt(Config config, String path, Integer def); static boolean getBoolean(Config config, String path, boolean def); static double getDouble(Config config, String path, double def); static Config getConfig(Config config, String path, Config def); static List<String> getStringList(Config config, String path); static boolean hasNonEmptyPath(Config config, String key); static boolean verifySubset(Config superConfig, Config subConfig); static Config resolveEncrypted(Config config, Optional<String> encConfigPath); static final String STRIP_SUFFIX; }