22
22
import java .nio .charset .StandardCharsets ;
23
23
import java .nio .file .Files ;
24
24
import java .nio .file .Path ;
25
- import java .util .AbstractMap ;
26
25
import java .util .List ;
27
26
import java .util .ListIterator ;
28
27
import java .util .Map ;
@@ -237,19 +236,19 @@ private void addIntendedLine(String indent, String line) {
237
236
* sequence (\n, \r, \r\n).
238
237
*/
239
238
private String diff (File file ) throws IOException {
240
- return diff (formatter , file ).getKey ();
239
+ return diff (formatter , file ).getValue ();
241
240
}
242
241
243
242
/**
244
- * Returns a map entry with key being a git-style diff between the contents of the given file and what those contents would
243
+ * Returns a map entry with value being a git-style diff between the contents of the given file and what those contents would
245
244
* look like if formatted using the given formatter. Does not end with any newline
246
- * sequence (\n, \r, \r\n). The value of the map entry is the line where the first difference occurred.
245
+ * sequence (\n, \r, \r\n). The key of the map entry is the 0-based line where the first difference occurred.
247
246
*/
248
- public static Map .Entry <String , Integer > diff (Formatter formatter , File file ) throws IOException {
247
+ public static Map .Entry <Integer , String > diff (Formatter formatter , File file ) throws IOException {
249
248
return diff (new CleanProviderFormatter (formatter ), file );
250
249
}
251
250
252
- private static Map .Entry <String , Integer > diff (CleanProvider formatter , File file ) throws IOException {
251
+ private static Map .Entry <Integer , String > diff (CleanProvider formatter , File file ) throws IOException {
253
252
String raw = new String (Files .readAllBytes (file .toPath ()), formatter .getEncoding ());
254
253
String rawUnix = LineEnding .toUnix (raw );
255
254
String formatted = formatter .getFormatted (file , rawUnix );
@@ -264,13 +263,13 @@ private static Map.Entry<String, Integer> diff(CleanProvider formatter, File fil
264
263
}
265
264
266
265
/**
267
- * Returns a map entry with key being a git-style diff between the two unix strings and value being the line of the first difference (in the dirty string)
266
+ * Returns a map entry with value being a git-style diff between the two unix strings and key being the 0-based line of the first difference (in the dirty string)
268
267
* <p>
269
268
* Output has no trailing newlines.
270
269
* <p>
271
270
* Boolean args determine whether whitespace or line endings will be visible.
272
271
*/
273
- private static Map .Entry <String , Integer > diffWhitespaceLineEndings (String dirty , String clean , boolean whitespace , boolean lineEndings ) throws IOException {
272
+ private static Map .Entry <Integer , String > diffWhitespaceLineEndings (String dirty , String clean , boolean whitespace , boolean lineEndings ) throws IOException {
274
273
dirty = visibleWhitespaceLineEndings (dirty , whitespace , lineEndings );
275
274
clean = visibleWhitespaceLineEndings (clean , whitespace , lineEndings );
276
275
@@ -287,7 +286,7 @@ private static Map.Entry<String, Integer> diffWhitespaceLineEndings(String dirty
287
286
288
287
// we don't need the diff to show this, since we display newlines ourselves
289
288
formatted = formatted .replace ("\\ No newline at end of file\n " , "" );
290
- return new AbstractMap . SimpleEntry <>( NEWLINE_MATCHER . trimTrailingFrom ( formatted ), getLineOfFirstDifference ( edits ));
289
+ return Map . entry ( getLineOfFirstDifference ( edits ), NEWLINE_MATCHER . trimTrailingFrom ( formatted ));
291
290
}
292
291
293
292
private static int getLineOfFirstDifference (EditList edits ) {
0 commit comments