/** * {@inheritDoc}. * * <p> * If the result is already in cache, return the result. * Otherwise, delegate the functionality to the fallback object * </p> */ @Override public List<ConfigKeyPath> getOwnImports(ConfigKeyPath configKey) { return getOwnImports(configKey, Optional.<Config>absent()); }
public List<ConfigKeyPath> getImportsRecursively(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { return new ImportTraverser<>(key -> { if (key.isRootPath()) { return new LinkedList<>(); } List<ConfigKeyPath> imports = Lists.newArrayList(); imports.addAll(Lists.reverse(getOwnImports(key, runtimeConfig))); imports.add(key.getParent()); return imports; }, this.recursiveImportMap).traverseGraphRecursively(configKey); }
private synchronized void computeImportedByMap(Optional<Config> runtimeConfig) { if (this.fullImportedByMap != null) { return; } ImmutableMultimap.Builder<ConfigKeyPath, ConfigKeyPath> importedByBuilder = ImmutableMultimap.builder(); // breath first search the whole topology to build ownImports map and ownImportedByMap // calls to retrieve cache / set cache if not present Collection<ConfigKeyPath> currentLevel = this.getChildren(SingleLinkedListConfigKeyPath.ROOT); List<ConfigKeyPath> rootImports = this.getOwnImports(SingleLinkedListConfigKeyPath.ROOT, runtimeConfig); Preconditions.checkArgument(rootImports == null || rootImports.size() == 0, "Root can not import other nodes, otherwise circular dependency will happen"); while (!currentLevel.isEmpty()) { Collection<ConfigKeyPath> nextLevel = new ArrayList<>(); for (ConfigKeyPath configKeyPath : currentLevel) { // calls to retrieve cache / set cache if not present List<ConfigKeyPath> ownImports = this.getOwnImports(configKeyPath, runtimeConfig); this.ownImportMap.put(configKeyPath, ownImports); for (ConfigKeyPath importedPath : ownImports) { importedByBuilder.put(importedPath, configKeyPath); } // calls to retrieve cache / set cache if not present Collection<ConfigKeyPath> tmp = this.getChildren(configKeyPath); nextLevel.addAll(tmp); } currentLevel = nextLevel; } this.fullImportedByMap = importedByBuilder.build(); }
result = inMemory.getOwnImports(identity); Assert.assertTrue(result.size()==2); Iterator<ConfigKeyPath> it = result.iterator();
/** * {@inheritDoc}. * * <p> * If the result is already in cache, return the result. * Otherwise, delegate the functionality to the fallback object * </p> */ @Override public List<ConfigKeyPath> getOwnImports(ConfigKeyPath configKey) { return getOwnImports(configKey, Optional.<Config>absent()); }
public List<ConfigKeyPath> getImportsRecursively(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { return new ImportTraverser<>(key -> { if (key.isRootPath()) { return new LinkedList<>(); } List<ConfigKeyPath> imports = Lists.newArrayList(); imports.addAll(Lists.reverse(getOwnImports(key, runtimeConfig))); imports.add(key.getParent()); return imports; }, this.recursiveImportMap).traverseGraphRecursively(configKey); }
private synchronized void computeImportedByMap(Optional<Config> runtimeConfig) { if (this.fullImportedByMap != null) { return; } ImmutableMultimap.Builder<ConfigKeyPath, ConfigKeyPath> importedByBuilder = ImmutableMultimap.builder(); // breath first search the whole topology to build ownImports map and ownImportedByMap // calls to retrieve cache / set cache if not present Collection<ConfigKeyPath> currentLevel = this.getChildren(SingleLinkedListConfigKeyPath.ROOT); List<ConfigKeyPath> rootImports = this.getOwnImports(SingleLinkedListConfigKeyPath.ROOT, runtimeConfig); Preconditions.checkArgument(rootImports == null || rootImports.size() == 0, "Root can not import other nodes, otherwise circular dependency will happen"); while (!currentLevel.isEmpty()) { Collection<ConfigKeyPath> nextLevel = new ArrayList<>(); for (ConfigKeyPath configKeyPath : currentLevel) { // calls to retrieve cache / set cache if not present List<ConfigKeyPath> ownImports = this.getOwnImports(configKeyPath, runtimeConfig); this.ownImportMap.put(configKeyPath, ownImports); for (ConfigKeyPath importedPath : ownImports) { importedByBuilder.put(importedPath, configKeyPath); } // calls to retrieve cache / set cache if not present Collection<ConfigKeyPath> tmp = this.getChildren(configKeyPath); nextLevel.addAll(tmp); } currentLevel = nextLevel; } this.fullImportedByMap = importedByBuilder.build(); }