mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Add automatic linter (#4214)
This commit is contained in:
@@ -40,32 +40,22 @@ public class DepthFirstSearch {
|
||||
return Optional.of(node);
|
||||
}
|
||||
|
||||
return node.getSubNodes()
|
||||
.stream()
|
||||
.map(value -> search(value, name))
|
||||
.flatMap(Optional::stream)
|
||||
.findAny();
|
||||
return node.getSubNodes().stream().map(value -> search(value, name)).flatMap(Optional::stream).findAny();
|
||||
}
|
||||
|
||||
public static void assertThat(final Object actual, final Object expected) {
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
throw new AssertionError(
|
||||
String.format("expected=%s but was actual=%s", expected, actual));
|
||||
throw new AssertionError(String.format("expected=%s but was actual=%s", expected, actual));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
final Node rootNode = new Node("A",
|
||||
List.of(
|
||||
new Node("B",
|
||||
List.of(new Node("D"), new Node("F", List.of(new Node("H"), new Node("I"))))),
|
||||
new Node("C", List.of(new Node("G"))), new Node("E")));
|
||||
final Node rootNode = new Node("A", List.of(new Node("B", List.of(new Node("D"), new Node("F", List.of(new Node("H"), new Node("I"))))), new Node("C", List.of(new Node("G"))), new Node("E")));
|
||||
|
||||
{
|
||||
final String expected = "I";
|
||||
|
||||
final Node result = search(rootNode, expected)
|
||||
.orElseThrow(() -> new AssertionError("Node not found!"));
|
||||
final Node result = search(rootNode, expected).orElseThrow(() -> new AssertionError("Node not found!"));
|
||||
|
||||
assertThat(result.getName(), expected);
|
||||
}
|
||||
@@ -73,8 +63,7 @@ public class DepthFirstSearch {
|
||||
{
|
||||
final String expected = "G";
|
||||
|
||||
final Node result = search(rootNode, expected)
|
||||
.orElseThrow(() -> new AssertionError("Node not found!"));
|
||||
final Node result = search(rootNode, expected).orElseThrow(() -> new AssertionError("Node not found!"));
|
||||
|
||||
assertThat(result.getName(), expected);
|
||||
}
|
||||
@@ -82,8 +71,7 @@ public class DepthFirstSearch {
|
||||
{
|
||||
final String expected = "E";
|
||||
|
||||
final Node result = search(rootNode, expected)
|
||||
.orElseThrow(() -> new AssertionError("Node not found!"));
|
||||
final Node result = search(rootNode, expected).orElseThrow(() -> new AssertionError("Node not found!"));
|
||||
|
||||
assertThat(result.getName(), expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user