private StdRestxConfig(Iterable<ConfigElement> elements) { Map<String, ConfigElement> m = new LinkedHashMap<>(); for (ConfigElement element : elements) { ConfigElement curElement = m.get(element.getKey()); if (curElement == null) { m.put(element.getKey(), element); } else { if (isNullOrEmpty(curElement.getDoc()) && !isNullOrEmpty(element.getDoc())) { m.put(element.getKey(), curElement.withDoc(element.getDoc())); } } } this.elements = ImmutableMap.copyOf(m); }
public static ConfigElement of(String key, String val) { return new ConfigElement("", "", key, val); }
elements.add(ConfigElement.of("system", "", (String) entry.getKey(), (String) entry.getValue())); for (NamedComponent<String> s : satisfiedBOM.get(stringsQuery)) { Optional<ConfigElement> element = config.getElement(s.getName().getName()); if (element.isPresent() && element.get().getValue().equals(s.getComponent())) { factoryElements.add(ConfigElement.of("factory", element.isPresent() ? element.get().getDoc() : "", s.getName().getName(), s.getComponent()));
public static RestxConfig parse(String origin, CharSource charSource) throws IOException { List<ConfigElement> elements = new ArrayList<>(); StringBuilder doc = new StringBuilder(); ImmutableList<String> lines = charSource.readLines(); for (int lineCount = 0; lineCount < lines.size(); lineCount++) { String line = lines.get(lineCount); if (line.startsWith("#")) { doc.append(line.substring(1).trim()).append("\n"); } else if (!line.trim().isEmpty()) { int equalIndex = line.indexOf('='); if (equalIndex == -1) { throw new IOException("invalid config " + origin + " at line " + lineCount + ":" + " line does not contain the equals sign '='"); } String key = line.substring(0, equalIndex).trim(); StringBuilder value = new StringBuilder(); String lineValue = line.substring(equalIndex + 1).trim(); while(lineValue.endsWith("\\") && lineCount+1 < lines.size()) { value.append(lineValue.substring(0, lineValue.length() - "\\".length())); lineCount++; lineValue = lines.get(lineCount).trim(); } value.append(lineValue); elements.add(ConfigElement.of(origin, doc.toString().trim(), key, value.toString())); doc.setLength(0); } } return new StdRestxConfig(elements); }
public static RestxConfig parse(String origin, CharSource charSource) throws IOException { List<ConfigElement> elements = new ArrayList<>(); StringBuilder doc = new StringBuilder(); ImmutableList<String> lines = charSource.readLines(); for (int lineCount = 0; lineCount < lines.size(); lineCount++) { String line = lines.get(lineCount); if (line.startsWith("#")) { doc.append(line.substring(1).trim()).append("\n"); } else if (!line.trim().isEmpty()) { int equalIndex = line.indexOf('='); if (equalIndex == -1) { throw new IOException("invalid config " + origin + " at line " + lineCount + ":" + " line does not contain the equals sign '='"); } String key = line.substring(0, equalIndex).trim(); StringBuilder value = new StringBuilder(); String lineValue = line.substring(equalIndex + 1).trim(); while(lineValue.endsWith("\\") && lineCount+1 < lines.size()) { value.append(lineValue.substring(0, lineValue.length() - "\\".length())); lineCount++; lineValue = lines.get(lineCount).trim(); } value.append(lineValue); elements.add(ConfigElement.of(origin, doc.toString().trim(), key, value.toString())); doc.setLength(0); } } return new StdRestxConfig(elements); }
private StdRestxConfig(Iterable<ConfigElement> elements) { Map<String, ConfigElement> m = new LinkedHashMap<>(); for (ConfigElement element : elements) { ConfigElement curElement = m.get(element.getKey()); if (curElement == null) { m.put(element.getKey(), element); } else { if (isNullOrEmpty(curElement.getDoc()) && !isNullOrEmpty(element.getDoc())) { m.put(element.getKey(), curElement.withDoc(element.getDoc())); } } } this.elements = ImmutableMap.copyOf(m); }
public ConfigElement withDoc(String doc) { return new ConfigElement(origin, doc, key, value); }
public ConfigElement withDoc(String doc) { return new ConfigElement(origin, doc, key, value); }
@Override public Optional<Integer> getInt(String elementKey) { ConfigElement element = elements.get(elementKey); if (element == null || isNullOrEmpty(element.getValue())) { return Optional.absent(); } try { return Optional.of(Integer.parseInt(element.getValue())); } catch (NumberFormatException e) { throw new RuntimeException("can't access " + element + " as int" + " (parse exception " + e.getMessage() + ")"); } }
public static ConfigElement of(String origin, String doc, String key, String val) { return new ConfigElement(origin, doc, key, val); }
@Override public Optional<Integer> getInt(String elementKey) { ConfigElement element = elements.get(elementKey); if (element == null || isNullOrEmpty(element.getValue())) { return Optional.absent(); } try { return Optional.of(Integer.parseInt(element.getValue())); } catch (NumberFormatException e) { throw new RuntimeException("can't access " + element + " as int" + " (parse exception " + e.getMessage() + ")"); } }
public static ConfigElement of(String origin, String doc, String key, String val) { return new ConfigElement(origin, doc, key, val); }
@Override public Optional<Long> getLong(String elementKey) { ConfigElement element = elements.get(elementKey); if (element == null || isNullOrEmpty(element.getValue())) { return Optional.absent(); } try { return Optional.of(Long.parseLong(element.getValue())); } catch (NumberFormatException e) { throw new RuntimeException("can't access " + element + " as long" + " (parse exception " + e.getMessage() + ")"); } }
public static ConfigElement of(String key, String val) { return new ConfigElement("", "", key, val); }
@Override public Optional<Long> getLong(String elementKey) { ConfigElement element = elements.get(elementKey); if (element == null || isNullOrEmpty(element.getValue())) { return Optional.absent(); } try { return Optional.of(Long.parseLong(element.getValue())); } catch (NumberFormatException e) { throw new RuntimeException("can't access " + element + " as long" + " (parse exception " + e.getMessage() + ")"); } }