fix warnings

This commit is contained in:
Shautvast 2023-07-26 17:37:45 +02:00
parent 4d4ebe9c7f
commit 5d9f74ff1e
4 changed files with 13 additions and 19 deletions

View file

@ -13,7 +13,6 @@ import java.util.concurrent.atomic.LongAdder;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@SuppressWarnings({"unchecked", "rawtypes"})
/** /**
* Deep (recursive) comparison of two objects * Deep (recursive) comparison of two objects
* - floating point comparison with optional precision * - floating point comparison with optional precision
@ -21,6 +20,7 @@ import java.util.stream.Stream;
* *
* In case of maps or differing object types, every item in apple is expected in orange, so apple can be subset of orange. * In case of maps or differing object types, every item in apple is expected in orange, so apple can be subset of orange.
*/ */
@SuppressWarnings({"unchecked", "rawtypes"})
public class Compare { public class Compare {
private final static Map<Character, String> CHAR_ESCAPES = Map.of('\t', "\\t", '\b', "\\b", '\n', "\\n", '\r', "\\r", '\f', "\\f", '\\', "\\\\"); private final static Map<Character, String> CHAR_ESCAPES = Map.of('\t', "\\t", '\b', "\\b", '\n', "\\n", '\r', "\\r", '\f', "\\f", '\\', "\\\\");
@ -84,7 +84,7 @@ public class Compare {
if (apple.getClass() != orange.getClass()) { if (apple.getClass() != orange.getClass()) {
if (allowDifferingTypes) { if (allowDifferingTypes) {
// convert objects to maps and compare their keys/values // convert objects to maps and compare their keys/values
return compareMaps(property, ToMap.map(apple), (Map<?, ?>) ToMap.map(orange), allowDifferingTypes); return compareMaps(property, ToMap.map(apple), ToMap.map(orange), allowDifferingTypes);
} else { } else {
return Result.unequal(property, asString(apple) + " != " + asString(orange)); return Result.unequal(property, asString(apple) + " != " + asString(orange));
} }

View file

@ -6,6 +6,7 @@ import java.util.Objects;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@SuppressWarnings("unused")
public class Result { public class Result {
private final boolean areEqual; private final boolean areEqual;
private final List<String> diffs; private final List<String> diffs;
@ -70,6 +71,14 @@ public class Result {
return areEqual; return areEqual;
} }
public boolean hasException(){
return e != null;
}
public Throwable getException() {
return e;
}
public static Result merge(Result... result) { public static Result merge(Result... result) {
boolean areEqual = Arrays.stream(result).allMatch(r -> r.areEqual); boolean areEqual = Arrays.stream(result).allMatch(r -> r.areEqual);
List<String> diffs = Arrays.stream(result) List<String> diffs = Arrays.stream(result)

View file

@ -1,15 +0,0 @@
import nl.sander.reflective.tomap.AbstractToMap;
import nl.sander.reflective.compare.PlumBean;
import java.util.HashMap;
import java.util.Map;
public class ExampleMappifier extends AbstractToMap {
public Map<String, Object> toMap(Object o) {
HashMap<String, Object> m = new HashMap<>();
add(m, "core", ((PlumBean) o).getCore());
add(m, "number", ((PlumBean) o).getNumber());
return m;
}
}

View file

@ -10,7 +10,7 @@ public class DifferentTypesTest {
assertTrue(Compare.any(new Apple("orange"), new Orange("orange")).areEqual()); assertTrue(Compare.any(new Apple("orange"), new Orange("orange")).areEqual());
} }
class Apple { static class Apple {
final String color; final String color;
Apple(String color) { Apple(String color) {
@ -18,7 +18,7 @@ public class DifferentTypesTest {
} }
} }
class Orange { static class Orange {
final String color; final String color;
Orange(String color) { Orange(String color) {