private void buildSetOfAllUpstreamDependencies(final Set<String> results, final String downstreamDependency) { final Set<String> upstreams = downstreamKeyed.get(downstreamDependency); if (upstreams == null) { return; } for (final String upstream : upstreams) { results.add(upstream); buildSetOfAllUpstreamDependencies(results, upstream); } }
public void deregisterDependencies(final String downstreamDependency) { Validate.isTrue(MetadataIdentificationUtils.isValid(downstreamDependency), "Downstream dependency is an invalid metadata identification string ('%s')", downstreamDependency); // Acquire the keys to delete final Set<String> upstream = downstreamKeyed.get(downstreamDependency); if (upstream == null) { return; } final Set<String> upstreamToDelete = new HashSet<String>(upstream); // Delete them normally for (final String deleteUpstream : upstreamToDelete) { deregisterDependency(deleteUpstream, downstreamDependency); } }
public void registerDependency(final String upstreamDependency, final String downstreamDependency) { Validate.isTrue(isValidDependency(upstreamDependency, downstreamDependency), "Invalid dependency between upstream '%s' and downstream '%s'", upstreamDependency, downstreamDependency); // Maintain the upstream-keyed map Set<String> downstream = upstreamKeyed.get(upstreamDependency); if (downstream == null) { downstream = new HashSet<String>(); upstreamKeyed.put(upstreamDependency, downstream); } downstream.add(downstreamDependency); // Maintain the downstream-keyed map Set<String> upstream = downstreamKeyed.get(downstreamDependency); if (upstream == null) { upstream = new HashSet<String>(); downstreamKeyed.put(downstreamDependency, upstream); } upstream.add(upstreamDependency); }
Set<String> downstreams = getDownstream(upstreamDependency); for (final String downstream : downstreams) { if (metadataLogger.getTraceLevel() > 0) { downstreams = getDownstream(asClass); for (final String downstream : downstreams) {
public boolean isValidDependency(final String upstreamDependency, final String downstreamDependency) { Validate.isTrue(MetadataIdentificationUtils.isValid(upstreamDependency), "Upstream dependency is an invalid metadata identification string ('%s')", upstreamDependency); Validate.isTrue(MetadataIdentificationUtils.isValid(downstreamDependency), "Downstream dependency is an invalid metadata identification string ('%s')", downstreamDependency); Validate.isTrue(!upstreamDependency.equals(downstreamDependency), "Upstream dependency cannot be the same as the downstream dependency ('%s')", downstreamDependency); // The simplest possible outcome is the relationship already exists, so // quickly return in that case Set<String> downstream = upstreamKeyed.get(upstreamDependency); if (downstream != null && downstream.contains(downstreamDependency)) { return true; } // Don't need the variable anymore, as we don't care about the other // downstream dependencies downstream = null; // Need to walk the upstream dependency's parent dependency graph, // verifying no presence of the proposed downstream dependency // Need to build a set representing every eventual upstream dependency // of the indicated upstream dependency final Set<String> allUpstreams = new HashSet<String>(); buildSetOfAllUpstreamDependencies(allUpstreams, upstreamDependency); // The dependency is valid if none of the upstreams depend on the // proposed downstream return !allUpstreams.contains(downstreamDependency); }