boolean disjoint2sets(String[] one, String[] theOther) { for (int i=0; i<one.length; i++) { if (elementInSet(one[i], theOther)) return false; } return true; }
boolean subset2sets(String[] subSet, String[] superSet){ for (int i=0; i<subSet.length; i++) { if (!elementInSet(subSet[i], superSet)) return false; } return true; }
/** * Wildcard constraints - helper methods */ boolean areSame(XSWildcardDecl wildcard, XSWildcardDecl otherWildcard) { if (wildcard.fType == otherWildcard.fType) { // ##any, true if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) { return true; } // ##other, only check the negated value // * when we support not(list), we need to check in the same way // as for NSCONSTRAINT_LIST. // not(list) is supported - no need for that check if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) { return wildcard.fNamespaceList[0] == otherWildcard.fNamespaceList[0]; } // ## list, must have the same length, // and each item in one list must appear in the other one // (we are assuming that there are no duplicate items in a list) if (wildcard.fNamespaceList.length == otherWildcard.fNamespaceList.length) { for (int i=0; i<wildcard.fNamespaceList.length; i++) { if (!elementInSet(wildcard.fNamespaceList[i], otherWildcard.fNamespaceList)) { return false; } } return true; } } return false; } // areSame
String[] intersect2sets(String[] one, String[] theOther){ String[] result = new String[Math.min(one.length,theOther.length)]; // simple implemention, int count = 0; for (int i=0; i<one.length; i++) { if (elementInSet(one[i], theOther)) result[count++] = one[i]; } String[] result2 = new String[count]; System.arraycopy(result, 0, result2, 0, count); return result2; }
String[] union2sets(String[] one, String[] theOther){ String[] result1 = new String[one.length]; // simple implemention, int count = 0; for (int i=0; i<one.length; i++) { if (!elementInSet(one[i], theOther)) result1[count++] = one[i]; } String[] result2 = new String[count+theOther.length]; System.arraycopy(result1, 0, result2, 0, count); System.arraycopy(theOther, 0, result2, count, theOther.length); return result2; }