/* (non-Javadoc) * @see org.spdx.rdfparser.license.AnyLicenseInfo#equals(java.lang.Object) */ @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof ConjunctiveLicenseSet)) { // covers o == null, as null is not an instance of anything return false; } ConjunctiveLicenseSet comp = (ConjunctiveLicenseSet) o; AnyLicenseInfo[] compInfos = comp.getFlattenedMembers(); AnyLicenseInfo[] myInfos = this.getFlattenedMembers(); if (compInfos.length != myInfos.length) { return false; } for (int j = 0; j < myInfos.length; j++) { AnyLicenseInfo li = myInfos[j]; boolean found = false; for (int i = 0; i < compInfos.length; i++) { if (li.equals(compInfos[i])) { found = true; break; } } if (!found) { return false; } } return true; }
/** * Compares two licenses from potentially two different documents which may have different license * ID's for the same license * * @param license1 * @param license2 * @param xlationMap Mapping the license ID's from license 1 to license 2 * @return * @throws SpdxCompareException */ public static boolean isLicenseEqual( AnyLicenseInfo license1, AnyLicenseInfo license2, Map<String, String> xlationMap) throws SpdxCompareException { if (license1 instanceof ConjunctiveLicenseSet) { if (!(license2 instanceof ConjunctiveLicenseSet)) { return false; } else { return isLicenseSetsEqual( (ConjunctiveLicenseSet) license1, (ConjunctiveLicenseSet) license2, xlationMap); } } else if (license1 instanceof DisjunctiveLicenseSet) { if (!(license2 instanceof DisjunctiveLicenseSet)) { return false; } else { return isLicenseSetsEqual( (DisjunctiveLicenseSet) license1, (DisjunctiveLicenseSet) license2, xlationMap); } } else if (license1 instanceof ExtractedLicenseInfo) { if (!(license2 instanceof ExtractedLicenseInfo)) { return false; } else { String licenseid1 = ((ExtractedLicenseInfo) license1).getLicenseId(); String licenseid2 = ((ExtractedLicenseInfo) license2).getLicenseId(); String xlatedLicenseId = xlationMap.get(licenseid1); if (xlatedLicenseId == null) { return false; // no equivalent license was found } return xlatedLicenseId.equals(licenseid2); } } else { return license1.equals(license2); } }