#29 - Workspace.LineCallback now uses Optional as return type.
That allows us to replace non-null checks with a simple ….ifPresent(…).
This commit is contained in:
@@ -30,6 +30,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
@@ -190,12 +191,7 @@ public class Workspace {
|
||||
long number = 0;
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
|
||||
String result = callback.doWith(scanner.nextLine(), number++);
|
||||
|
||||
if (result != null) {
|
||||
builder.append(result).append("\n");
|
||||
}
|
||||
callback.doWith(scanner.nextLine(), number++).ifPresent(it -> builder.append(it).append("\n"));
|
||||
}
|
||||
|
||||
writeContentToFile(filename, project, builder.toString());
|
||||
@@ -229,6 +225,6 @@ public class Workspace {
|
||||
}
|
||||
|
||||
public interface LineCallback {
|
||||
String doWith(String line, long number);
|
||||
Optional<String> doWith(String line, long number);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.release.git.GitOperations;
|
||||
@@ -83,9 +84,9 @@ public class ReleaseOperations {
|
||||
builder.append(line).append("\n\n");
|
||||
builder.append(changelog.toString());
|
||||
|
||||
return builder.toString();
|
||||
return Optional.of(builder.toString());
|
||||
} else {
|
||||
return line;
|
||||
return Optional.of(line);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -104,7 +105,7 @@ public class ReleaseOperations {
|
||||
iteration.stream().forEach(module -> {
|
||||
|
||||
boolean processed = workspace.processFile("src/main/resources/notice.txt", module.getProject(),
|
||||
(line, number) -> number != 0 ? line : module.toString());
|
||||
(line, number) -> Optional.of(number != 0 ? line : module.toString()));
|
||||
|
||||
if (processed) {
|
||||
logger.log(module, "Updated notice.txt.");
|
||||
|
||||
Reference in New Issue
Block a user