Skip to content

Commit

Permalink
Cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cowwoc committed May 28, 2024
1 parent eb7463f commit 649273c
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public Configuration()
* {@link Validator#elseGetException()}. The exception matches the original
* failure, but the stack trace points to {@code elseGetException()} as the
* cause.
* @param throwOnFailure {@code true} if an exception is thrown on validation failure.
* @param exceptionTransformer a function that transforms the validation exception into a suitable runtime
* exception or error
* @param throwOnFailure {@code true} if an exception is thrown on validation failure
* @param exceptionTransformer a function that transforms the validation exception before it is thrown or
* returned
* @throws NullPointerException if any of the arguments are null
*/
public Configuration(boolean cleanStackTrace, boolean includeDiff, EqualityMethod equalityMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public StringMappers toImmutable()

/**
* @param object a {@code List}
* @return the String representation of {@code object}
* @return the String representation of an {@code Object}
*/
private String listToString(Object object)
{
Expand All @@ -106,7 +106,7 @@ private String listToString(Object object)

/**
* @param collection a {@code Collection}
* @return the String representation of {@code collection}
* @return the String representation of a {@code Collection}
*/
private String orderedToString(Collection<?> collection)
{
Expand All @@ -131,7 +131,7 @@ private String orderedToString(Collection<?> collection)

/**
* @param object an {@code Object}
* @return the String representation of {@code object}
* @return the String representation of an {@code Object}
*/
private String setToString(Object object)
{
Expand All @@ -157,7 +157,7 @@ private String setToString(Object object)

/**
* @param object an {@code Object}
* @return the String representation of {@code map}
* @return the String representation of a {@code Map}
*/
private String mapToString(Object object)
{
Expand All @@ -174,7 +174,7 @@ private String mapToString(Object object)

/**
* @param entries map entries
* @return the String representation of {@code entries}
* @return the String representation of Map {@code entries}
*/
private String mapEntriesToString(Set<? extends Entry<?, ?>> entries)
{
Expand Down Expand Up @@ -246,7 +246,7 @@ private String arrayToString(Object[] array, Set<Object> seen)

/**
* @param object a {@code Throwable}
* @return the String representation of {@code object}
* @return the String representation of a {@code Throwable}
*/
private String throwableToString(Object object)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public void writeEqual(String text)
if (expectedLineNumber != actualLineNumber)
{
int length = line.length();
String paddingMarker = getPaddingMarker();
lineToExpectedLine.get(actualLineNumber).append(decoratePadding(paddingMarker.repeat(length)));
String padding = decoratePadding(getPaddingMarker().repeat(length));
lineToExpectedLine.get(actualLineNumber).append(padding);
lineToExpectedDecoration.put(actualLineNumber, DecorationType.EQUAL);

lineToActualLine.get(expectedLineNumber).append(decoratePadding(paddingMarker.repeat(length)));
lineToActualLine.get(expectedLineNumber).append(padding);
lineToActualDecoration.put(expectedLineNumber, DecorationType.EQUAL);
}

Expand Down Expand Up @@ -161,7 +161,7 @@ public void writeInserted(String text)
}

@Override
protected void beforeClose()
protected void beforeFlush()
{
for (Entry<Integer, DecorationType> entry : lineToActualDecoration.entrySet())
{
Expand All @@ -185,7 +185,7 @@ protected void beforeClose()
public Queue<String> getDiffLines()
{
if (!flushed)
throw new IllegalStateException("Writer must be closed");
throw new IllegalStateException("Writer must be flushed");
return EMPTY_QUEUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ abstract class AbstractDiffWriter implements DiffWriter
* The current line number of the expected value.
*/
protected int expectedLineNumber;
/**
* {@code true} if the writer has been flushed.
*/
protected boolean flushed;

/**
Expand All @@ -72,14 +75,14 @@ abstract class AbstractDiffWriter implements DiffWriter
}

/**
* Invoked before closing the writer.
* Invoked before flushing the writer.
*/
protected abstract void beforeClose();
protected abstract void beforeFlush();

/**
* Invoked after closing the writer.
* Invoked after flushing the writer.
*/
protected abstract void afterClose();
protected abstract void afterFlush();

@Override
public String getPaddingMarker()
Expand Down Expand Up @@ -176,37 +179,37 @@ public void flush()
if (flushed)
return;
flushed = true;
beforeClose();
beforeFlush();
this.actualLines.addAll(lineToActualLine.entrySet().stream().
sorted(Entry.comparingByKey()).map(Entry::getValue).map(StringBuilder::toString).toList());
this.expectedLines.addAll(lineToExpectedLine.entrySet().stream().
sorted(Entry.comparingByKey()).map(Entry::getValue).map(StringBuilder::toString).toList());
this.equalLines.addAll(lineToEqualLine.entrySet().stream().
sorted(Entry.comparingByKey()).map(Entry::getValue).toList());
afterClose();
afterFlush();
}

@Override
public Queue<String> getActualLines()
{
if (!flushed)
throw new IllegalStateException("Writer must be closed");
throw new IllegalStateException("Writer must be flushed");
return actualLines;
}

@Override
public Queue<String> getExpectedLines()
{
if (!flushed)
throw new IllegalStateException("Writer must be closed");
throw new IllegalStateException("Writer must be flushed");
return expectedLines;
}

@Override
public Queue<Boolean> getEqualLines()
{
if (!flushed)
throw new IllegalStateException("Writer must be closed");
throw new IllegalStateException("Writer must be flushed");
return equalLines;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,12 @@ public void accept(List<AbstractDelta<Integer>> deltas)
findFirstWord();
if (indexOfStartDelta == numberOfDeltas)
return;
while (true)
do
{
findEndOfWord();
updateDeltas();
if (!findNextWord())
return;
}
while (findNextWord());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public void writeEqual(String text)
splitLines(text, line ->
{
lineToActualLine.get(actualLineNumber).append(line);
int length = line.length();
if (expectedLineNumber == actualLineNumber)
lineToDiffBuilder.get(actualLineNumber).append(DIFF_EQUAL.repeat(line.length()));
lineToDiffBuilder.get(actualLineNumber).append(DIFF_EQUAL.repeat(length));
else
{
String paddingMarker = getPaddingMarker();
int length = line.length();
lineToExpectedLine.get(actualLineNumber).append(paddingMarker.repeat(length));
lineToDiffBuilder.get(actualLineNumber).append(DIFF_EQUAL.repeat(length));

Expand Down Expand Up @@ -121,12 +121,12 @@ public void writeInserted(String text)
}

@Override
protected void beforeClose()
protected void beforeFlush()
{
}

@Override
protected void afterClose()
protected void afterFlush()
{
this.diffLines.addAll(lineToDiffBuilder.entrySet().stream().
sorted(Entry.comparingByKey()).
Expand All @@ -137,7 +137,7 @@ protected void afterClose()
public Queue<String> getDiffLines()
{
if (!flushed)
throw new IllegalStateException("Writer must be closed");
throw new IllegalStateException("Writer must be flushed");
return diffLines;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String decoratePadding(String text)
}

@Override
protected void afterClose()
protected void afterFlush()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String decoratePadding(String text)
}

@Override
protected void afterClose()
protected void afterFlush()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String decoratePadding(String text)
}

@Override
protected void afterClose()
protected void afterFlush()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String decoratePadding(String text)
}

@Override
protected void afterClose()
protected void afterFlush()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static String alignLeft(String text, int minLength)

/**
* @param text a {@code String}
* @return the Java String representation of {@code text}
* @return the Java String representation of a {@code String}
*/
public static String asJavaString(String text)
{
Expand All @@ -191,7 +191,7 @@ private static boolean needsEscaping(String text)
for (int codepoint : (Iterable<Integer>) text.codePoints()::iterator)
{
if (codepoint == '\t' || codepoint == '\b' || codepoint == '\n' || codepoint == '\r' ||
codepoint == '\f' || codepoint == '\"' || codepoint == '\\')
codepoint == '\f' || codepoint == '\"' || codepoint == '\\')
{
return true;
}
Expand Down Expand Up @@ -247,6 +247,6 @@ private static String asTextBlock(String text)
text += "\\\n";

return TEXT_BLOCK_DELIMITER + "\n" +
text + TEXT_BLOCK_DELIMITER;
text + TEXT_BLOCK_DELIMITER;
}
}

0 comments on commit 649273c

Please sign in to comment.