package net.sourceforge.fenixedu.domain.accessControl; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; import net.sourceforge.fenixedu.domain.accessControl.groups.language.Argument; import net.sourceforge.fenixedu.injectionCode.IGroup; public abstract class NodeGroup extends Group { private static final long serialVersionUID = 1L; private final List children; protected NodeGroup() { super(); this.children = new ArrayList(); } public NodeGroup(IGroup... groups) { this(); for (IGroup group : groups) { this.children.add(group); } } public NodeGroup(Collection groups) { this(); this.children.addAll(groups); } public List getChildren() { return Collections.unmodifiableList(this.children); } @Override public boolean equals(Object other) { if (other == null) { return false; } if (!this.getClass().equals(other.getClass())) { return false; } NodeGroup otherNodeGroup = (NodeGroup) other; return this.children.equals(otherNodeGroup.children); } @Override public int hashCode() { return this.children.hashCode(); } @Override public String getExpression() { StringBuilder builder = new StringBuilder(); Iterator iterator = getChildren().iterator(); while (iterator.hasNext()) { builder.append(getChildrenExpression(iterator.next())); if (iterator.hasNext()) { builder.append(" " + getExpressionOperator() + " "); } } return builder.toString(); } private String getChildrenExpression(IGroup group) { if (group instanceof NodeGroup) { return "(" + group.getExpression() + ")"; } else { return group.getExpression(); } } protected abstract String getExpressionOperator(); @Override protected Argument[] getExpressionArguments() { return new Argument[0]; } }