Package de.hsh.graja.comment
Class DiffComment
java.lang.Object
de.hsh.graja.util.comment.Content
de.hsh.graja.util.comment.AbstractElementContent
de.hsh.graja.comment.DiffComment
- All Implemented Interfaces:
Serializable
This class represents a synopsis of expected and observed outcomes of a student program.
Since comparisons between expected an observed outcomes usually is done after some normalizations, this class is capable of printing the normalizations, so that a student can understand the report, since this will deviate from the behaviour of the program when executed on a student computer.
A typical usecase of this comment is like this:
String input= ....; // some file input, that a student submitted method 'm' had to analyze.
Sequence explanation= new Sequence();
String legendString= VerbatimComment.createSymbolLegendForText(input);
if (!legendString.isEmpty()) {
legendString= " ("+legendString+")";
}
explanation.addItem(new Paragraph(includeSpec, String.format("Calling 'm' for the following file content%s:", legendString)));
explanation.addItem(new Verbatim(includeSpec, WhitespaceExpansion.ALL_TO_SYMBOLS, input));
String expected= ...; // prepare a sample output
String observed= ...; // invoke the student method 'm'
DiffHelper.compareStrings(expected, observed)
.normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.IGNORE_NEWLINE_DIFFERENCES))
.includeExplanationInDiffSynopsis(explanation)
.start();
A possible output is this:
Calling 'm' for the following file content (¶=line feed):
this is the first line¶ the next line is empty¶ ¶ this is the last line Expected and observed behaviours differ. In the following diff view the observed output was normalized by the following steps:
Legend: <M=missing in observation, A>=added in observation, :///:=no output, ¶=line feed |
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA diff synopsis can be either detailed with every line of expected and observed outcome compared, or it can be a simple comparison of the number of lines. -
Field Summary
Fields inherited from class de.hsh.graja.util.comment.Content
EXCLUSIVE, renderUuid -
Constructor Summary
ConstructorsConstructorDescriptionDiffComment(ApplicabilitySpec applicability, String expected, String observed, Content explanation, List<String> appliedNormalizersToObservedOutput) Initialize this object with typeDiffComment.DiffSynopsisType.DETAIL. -
Method Summary
Modifier and TypeMethodDescriptionintCalculates the number of lines, that differ.booleanimplements the contract ofObject.equals(Object).inthashCode()implements the contract ofObject.hashCode().booleanvoidrenderHtmlImpl(StringBuilder sb, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript) render content to HTML.voidrenderPlainImpl(StringBuilder sb, IncludeInfo includeInfo, RenderContext ctx) render content to plain text.voidsets the type of the reportThis method is for debugging purposes.voidtrimCRLF()deletes all CR and LF at line endingsMethods inherited from class de.hsh.graja.util.comment.Content
click, dehighlight, disableCallerStacktraceRecording, enableCallerStacktraceRecording, excludeGlobally, getIncludeSpec, getRenderUuid, getStackdump, hide, highlight, include, isCallerStacktraceRecordingEnabled, isHidden, isShowing, onClick, onClick, onHide, onHide, onLoad, onLoad, onShow, onShow, registerCallable, renderHtml, renderHtml, renderIdAttribute, renderJavascriptOncePerClass, renderOnClickAttribute, renderPlain, renderPlain, setGlobalIncludeInfo, setHref, setIncludeSpec, show, toString
-
Constructor Details
-
DiffComment
public DiffComment(ApplicabilitySpec applicability, String expected, String observed, Content explanation, List<String> appliedNormalizersToObservedOutput) Initialize this object with typeDiffComment.DiffSynopsisType.DETAIL.- Parameters:
applicability- the applicability of the commentexpected- the expected outcomeobserved- the observed outcomeexplanation- an optional comment that is printed to explain the synopsisappliedNormalizersToObservedOutput- a list of normalizers that will be reported in the context of the synopsis.
-
-
Method Details
-
setReportType
sets the type of the report- Parameters:
t- type of report
-
getReportType
- Returns:
- the type of the report
-
trimCRLF
public void trimCRLF()deletes all CR and LF at line endings -
getExpectedLines
- Returns:
- lines of expected output. The returned lines may not be original but may be the result of a normalization process.
-
getObservedLines
- Returns:
- lines of observed output. The returned lines may not be original but may be the result of a normalization process.
-
getExplanation
- Returns:
- an explanation comment that is meant to be appended to a diff output
-
getAppliedNormalizersToObservedOutput
- Returns:
- a list of normalizer rules that have been applied to the originally observed thereby changing the observation.
-
countDifferentLines
public int countDifferentLines()Calculates the number of lines, that differ.- Returns:
- number of differing lines.
-
isInlineContent
public boolean isInlineContent()- Specified by:
isInlineContentin classContent- Returns:
- false
- See Also:
-
toString
Description copied from class:ContentThis method is for debugging purposes. -
getNestedContents
- Overrides:
getNestedContentsin classAbstractElementContent- Returns:
- the set of contents nested in this content. Nested contents can be list items in a List, elements in a Sequence, elements in a Grid, elements in a Paragraph, and so on. If this is a leaf content, the returned set is empty.
- See Also:
-
Content#getNestedComments()
-
hashCode
public int hashCode()implements the contract ofObject.hashCode(). -
equals
implements the contract ofObject.equals(Object). -
renderHtmlImpl
public void renderHtmlImpl(StringBuilder sb, IncludeInfo includeInfo, RenderContext ctx, boolean useJavascript) Description copied from class:Contentrender content to HTML. This method is meant to be overriden by subclasses.- Specified by:
renderHtmlImplin classContent- Parameters:
sb- HTML code resultincludeInfo- controls, which content to be rendered.ctx- render contextuseJavascript- if true, the generated HTML code will contain Javascript- See Also:
-
Content#renderHtmlImpl(StringBuilder, IncludeInfo, RenderContext)
-
renderPlainImpl
Description copied from class:Contentrender content to plain text. This method is meant to be overriden by subclasses.- Specified by:
renderPlainImplin classContent- Parameters:
sb- plain text resultincludeInfo- controls, which content to be rendered.ctx- render context (unused).- See Also:
-
Content#renderHtmlImpl(StringBuilder, IncludeInfo, RenderContext)
-