You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found that the names of the various different permutations of the matching methods in the org.spdx.utility.compare.LicenseCompareHelper class are pretty confusing, and wonder if a more consistent naming scheme would be valuable?
This is partly fueled by:
There is no overall pattern to how the various methods are named, making "at a glance inference of method variations" difficult.
There are inconsistencies in how exceptions are referred to (some methods use "LicenseException", while others use "Exception").
There's conflation of "pure" matching methods (i.e. methods that answer the question "did this text contains one or more licenses / exceptions, and (optionally) if so, which ones?") with the methods that calculate diffs (i.e. methods that answer the question "what, if any, differences exist between this text and a given license / exception?").
It seems to me that the methods in this class fall into a sparse matrix defined by these criteria:
Whether the method operates on licenses, or exceptions
Whether the method performs exact matching of the text, or "finding" within the text
Whether the method considers only one listed license / exception, or multiple listed licenses / exceptions (and in the latter case, whether that's all listed licenses / exceptions, or a subset provided by the caller)
Whether the method returns the first match, or all matches
Whether the method is concerned with "pure" matching, or calculating differences
Coming up with a systematic naming scheme informed by these criteria has substantial value in helping to communicate how the LicenseCompareHelper class can be used for different matching / diffing scenarios.
A Proposed Naming Scheme
Methods that perform exact matching of the entire text:
Returns the ids of all of the listed licenses in lics that matched, or null if no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).
Returns the ids of all of the listed exceptions in excs that matched, or null if no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).
List<String> listAllLicensesMatched(String text)
Returns the ids of all of the listed licenses that matched, or null if no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).
Returns the ids of all of the listed exceptions that matched, or null if no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).
Methods that perform finds within the text, but only return the first match:
Many of these methods will share a common implementation - in fact in many cases they can be implemented as simple delegation calls to other methods (sometimes in a loop).
Obviously the old method names can't be removed until the next major release of the library, but they could be re-implemented to simply delegate to the new methods, and marked as deprecated before then.
I don't believe any of the method signatures listed above conflict with existing method signatures, but haven't done an exhaustive check.
Problem Statement
I've found that the names of the various different permutations of the matching methods in the
org.spdx.utility.compare.LicenseCompareHelperclass are pretty confusing, and wonder if a more consistent naming scheme would be valuable?This is partly fueled by:
It seems to me that the methods in this class fall into a sparse matrix defined by these criteria:
Coming up with a systematic naming scheme informed by these criteria has substantial value in helping to communicate how the
LicenseCompareHelperclass can be used for different matching / diffing scenarios.A Proposed Naming Scheme
Methods that perform exact matching of the entire text:
boolean isLicense(ListedLicense lic, String text)boolean isException(ListedLicenseException exc, String text)String isOneOfTheseLicenses(List<ListedLicense> lics, String text)licsthat matched, ornullif no match was foundString isOneOfTheseExceptions(List<ListedLicenseException> excs, String text)excsthat matched, ornullif no match was foundString isAnyLicense(String text)nullif no match was foundString isAnyException(String text)nullif no match was foundList<String> listAllLicensesMatched(List<ListedLicense> lics, String text)licsthat matched, ornullif no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).List<String> listAllExceptionsMatched(List<ListedLicenseException> excs, String text)excsthat matched, ornullif no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).List<String> listAllLicensesMatched(String text)nullif no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).List<String> listAllExceptionsMatched(String text)nullif no match was found. Might not be necessary, as this is a corner case for overlapping matching templates (e.g. GPL).Methods that perform finds within the text, but only return the first match:
boolean containsLicense(ListedLicense lic, String text)boolean containsException(ListedLicenseException exc, String text)String containsOneOfTheseLicenses(List<ListedLicense> lics, String text)licsthat matched, ornullif no match was foundString containsOneOfTheseExceptions(List<ListedLicenseException> excs, String text)excsthat matched, ornullif no match was foundString containsAnyLicense(String text)nullif no match was foundString containsAnyException(String text)nullif no match was foundMethods that perform finds within the text, and return all matches:
List<String> listAllLicensesFound(List<ListedLicense> lics, String text)licsthat matched, ornullif no match was foundList<String> listAllExceptionsFound(List<ListedLicenseException> excs, String text)excsthat matched, ornullif no match was foundList<String> listAllLicensesFound(String text)nullif no match was foundList<String> listAllExceptionsFound(String text)nullif no match was foundMethods that calculate diffs:
CompareTemplateOutputHandler.DifferenceDescription diffLicense(ListedLicense lic, String text)CompareTemplateOutputHandler.DifferenceDescription diffException(ListedLicenseException exc, String text)Notes: