
com.yahoo.component.chain.dependencies.Dependencies Maven / Gradle / Ivy
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.component.chain.dependencies;
import java.util.*;
import com.google.common.collect.ImmutableSet;
/**
* Constraints for ordering ChainedComponents in chains. Immutable.
*
* @author Tony Vaagenes
*/
public class Dependencies {
private final Set provides;
private final Set before;
private final Set after;
/**
* Create from collections of strings, typically from config.
*/
public Dependencies(Collection provides, Collection before, Collection after) {
this.provides = immutableSet(provides);
this.before = immutableSet(before);
this.after = immutableSet(after);
}
public static Dependencies emptyDependencies() {
return new Dependencies(null, null, null);
}
public Dependencies union(Dependencies dependencies) {
return new Dependencies(
union(provides, dependencies.provides),
union(before, dependencies.before),
union(after, dependencies.after));
}
private Set immutableSet(Collection set) {
if (set == null) return ImmutableSet.of();
return ImmutableSet.copyOf(set);
}
private Set union(Set s1, Set s2) {
Set result = new LinkedHashSet<>(s1);
result.addAll(s2);
return result;
}
@Override
public String toString() {
return "Dependencies{" +
"provides=" + provides +
", before=" + before +
", after=" + after +
'}';
}
public Set provides() {
return provides;
}
public Set before() {
return before;
}
public Set after() {
return after;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy