Tag.java
/**
*
* This file is part of TRIO.
*
* TRIO is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TRIO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TRIO. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.diversify.trio.core;
import eu.diversify.trio.util.Require;
import java.util.*;
/**
* A 'tag' used to classify the components of the system
*/
public class Tag implements SystemPart {
private final String label;
private final Set<String> targets;
public Tag(String label, String... targets) {
this(label, Arrays.asList(targets));
}
public Tag(String label, Collection<String> targets) {
Require.notNull(label, "Invalid 'null' value given a tag label!");
this.label = label;
Require.notNull(targets, "Invalid 'null' values given as tag's target");
Require.notEmpty(targets, "Invalid tags without any target ([] found)!");
this.targets = new HashSet<String>(targets);
}
public Collection<SystemPart> subParts() {
final List<SystemPart> subparts = new ArrayList<SystemPart>(0);
return subparts;
}
public void begin(SystemVisitor visitor) {
visitor.enter(this);
}
public void end(SystemVisitor visitor) {
visitor.exit(this);
}
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + this.label.hashCode();
hash = 97 * hash + this.targets.hashCode();
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Tag other = (Tag) obj;
return label.equals(other.label) && targets.equals(other.targets);
}
public String getLabel() {
return label;
}
public Set<String> getTargets() {
return Collections.unmodifiableSet(targets);
}
@Override
public String toString() {
return String.format("%s on %s", label, targets.toString());
}
}