@Override public Optional<TreeNode> get(String path) { return treeNode.get(path).map(UnmodifiableTreeNode::of); }
@Override public Optional<TreeNode> get(String path) { if (path.isEmpty()) { return Optional.of(this); } Path path2 = new Path(path); Optional<TreeNode> treeNode = Optional.empty(); if (path2.isArray()) { int index = path2.getIndex(); if (index >= 0 && index < children.size()) { treeNode = Optional.ofNullable(children.get(index)); } if (treeNode.isPresent() && path2.hasTail()) { return treeNode.get().get(path2.getTail()); } } return treeNode; }
public synchronized void refresh() { LOGGER.debug("Refreshing configuration"); MapNode pendingConfigurationTree; if (provider != null) { pendingConfigurationTree = provider.provide(); } else { pendingConfigurationTree = new MapNode(); } if (processor != null) { processor.process(pendingConfigurationTree); } TreeNode oldConfigurationTree = configurationTree; configurationTree = UnmodifiableTreeNode.of(pendingConfigurationTree); dirty = false; String lastPath = null; for (Map.Entry<String, List<ConfigChangeListener>> entry : listeners.entrySet()) { String path = entry.getKey(); if (lastPath != null && lastPath.startsWith(path) || !Objects.equals(oldConfigurationTree.get(path), configurationTree.get(path))) { for (ConfigChangeListener listener : entry.getValue()) { listener.onChange(this); } lastPath = path; } else { lastPath = null; } } }
T map(TreeNode rootNode) { if (rootNode.type() == TreeNode.Type.VALUE_NODE && valueFieldInfo != null) { Optional.ofNullable(coffig.getMapper().map(rootNode, valueFieldInfo.type)) .ifPresent(valueFieldInfo.consumer); } else if (rootNode.type() == TreeNode.Type.MAP_NODE) { fieldInfo.forEach(fieldInfo -> rootNode.get(fieldInfo.alias != null ? fieldInfo.alias : fieldInfo.name) .map(treeNode -> coffig.getMapper().map(treeNode, fieldInfo.type)) .ifPresent(fieldInfo.consumer)); } return holder; }
result.append(VALUE_SEPARATOR).append(part); } else { Optional<TreeNode> node = rootNode.get(processValue(rootNode, part)); if (node.isPresent()) { result.append(processValue(rootNode, node.get().value()));
public Optional<Object> getOptional(Type configurationType, String... path) { LOGGER.trace( "Accessing configuration path '" + Arrays.toString(path) + "' and mapping it to '" + configurationType .getTypeName() + "'"); if (isDirty()) { refresh(); } String joinedPath; if (path != null && path.length > 0) { joinedPath = String.join(".", (CharSequence[]) path); } else { joinedPath = pathOf(rawClassOf(configurationType)); } Optional<TreeNode> resolvedTree; if (joinedPath == null || joinedPath.isEmpty()) { resolvedTree = Optional.of(this.configurationTree); } else { resolvedTree = this.configurationTree.get(joinedPath); } return resolvedTree.map(treeNode -> mapper.map(treeNode, configurationType)); }
@Override public Optional<TreeNode> get(String path) { if (path.isEmpty()) { return Optional.of(this); } Path path2 = new Path(path); if (path2.hasHead()) { TreeNode child = children.get(path2.getHead()); if (child != null) { if (path2.hasTail()) { return child.get(path2.getTail()); } else { return Optional.of(child); } } } return Optional.empty(); }
private TreeNode processArgument(TreeNode tree, String value) throws Exception { if (value.startsWith("'") && value.endsWith("'")) { return new ValueNode(value.substring(1, value.length() - 1)); } CallSiteInfo callSiteInfo = findFunctionCall(value, 0); if (callSiteInfo == null) { TreeNode refNode = tree.get(value).orElse(new ValueNode("")); if (refNode.type() == TreeNode.Type.VALUE_NODE) { // References value nodes can be processed... return new ValueNode(processValue(tree, refNode.value())); } else { // ... whereas other node types are passed directly return refNode; } } else { return new ValueNode(processValue(tree, value)); } }