in src/main/java/org/apache/neethi/AbstractPolicyOperator.java [165:209]
private static PolicyComponent computeResultantComponent(List<PolicyComponent> normalizedInnerComponets,
short componentType) {
ExactlyOne exactlyOne = new ExactlyOne();
if (componentType == Constants.TYPE_EXACTLYONE) {
for (PolicyComponent comp : normalizedInnerComponets) {
ExactlyOne innerExactlyOne = (ExactlyOne)comp;
exactlyOne.addPolicyComponents(innerExactlyOne.getPolicyComponents());
}
} else if ((componentType == Constants.TYPE_POLICY) || (componentType == Constants.TYPE_ALL)) {
// if the parent type is All then we have to get the cross product
if (normalizedInnerComponets.size() > 1) {
// then we have to get the cross product with each other to process all elements
Iterator<PolicyComponent> iter = normalizedInnerComponets.iterator();
// first get the first element
exactlyOne = (ExactlyOne) iter.next();
// if this is empty, this is an not admissible policy and total result is equivalent to that
if (!exactlyOne.isEmpty()) {
ExactlyOne currentExactlyOne;
while (iter.hasNext()) {
currentExactlyOne = (ExactlyOne) iter.next();
if (currentExactlyOne.isEmpty()) {
// if this is empty, this is an not admissible policy and total
// result is equivalent to that
exactlyOne = currentExactlyOne;
break;
} else {
exactlyOne = getCrossProduct(exactlyOne, currentExactlyOne);
}
}
}
} else {
// i.e only one element exists in the list then we can safely
// return that element this is ok even if it is an empty element
exactlyOne = (ExactlyOne) normalizedInnerComponets.get(0);
}
}
return exactlyOne;
}