Package org.spdx.utility.compare
Class CompareTemplateOutputHandler
- java.lang.Object
-
- org.spdx.utility.compare.CompareTemplateOutputHandler
-
- All Implemented Interfaces:
org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
public class CompareTemplateOutputHandler extends Object implements org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
Compares the output of a parsed license template to text. The method matches is called after the document is parsed to determine if the text matches.- Author:
- Gary O'Neall
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCompareTemplateOutputHandler.DifferenceDescriptionInformation about any difference found
-
Constructor Summary
Constructors Constructor Description CompareTemplateOutputHandler(String compareText)Construct a newCompareTemplateOutputHandlerwith the specified text to compare
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)voidcompleteParsing()voidendOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)CompareTemplateOutputHandler.DifferenceDescriptiongetDifferences()Retrieve the details of the differences found during the comparison processbooleanmatches()Performs the actual parsing if it has not been completedvoidtext(String text)inttextEquivalent(String text, int startToken)Compares the text against the compareTextvoidvariableRule(org.spdx.licenseTemplate.LicenseTemplateRule rule)
-
-
-
Constructor Detail
-
CompareTemplateOutputHandler
public CompareTemplateOutputHandler(String compareText) throws IOException
Construct a newCompareTemplateOutputHandlerwith the specified text to compareThis handler is used to compare the output of a parsed SPDX license template to the provided text. It tokenizes the input text and prepares it for comparison against the parsed license template.
- Parameters:
compareText- The text to compare the parsed SPDX license template to.- Throws:
IOException- This is not to be expected since we are using StringReaders
-
-
Method Detail
-
text
public void text(String text)
- Specified by:
textin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
variableRule
public void variableRule(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
variableRulein interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
beginOptional
public void beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
beginOptionalin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
endOptional
public void endOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
endOptionalin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
matches
public boolean matches() throws org.spdx.licenseTemplate.LicenseParserExceptionPerforms the actual parsing if it has not been completedNOTE: This should only be called after all text has been added.
- Returns:
- true if no differences were found
- Throws:
org.spdx.licenseTemplate.LicenseParserException- on license parsing error
-
getDifferences
public CompareTemplateOutputHandler.DifferenceDescription getDifferences()
Retrieve the details of the differences found during the comparison process- Returns:
- details on the differences found
-
completeParsing
public void completeParsing() throws org.spdx.licenseTemplate.LicenseParserException- Specified by:
completeParsingin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler- Throws:
org.spdx.licenseTemplate.LicenseParserException
-
textEquivalent
public int textEquivalent(String text, int startToken)
Compares the text against the compareText- Parameters:
text- text to comparestartToken- token of the compareText to being the comparison- Returns:
- next token index (positive) if there is a match, negative first token where this is a miss-match if no match
-
-