Skip to content

Commit

Permalink
a reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 12, 2024
1 parent a9560b2 commit 46bf879
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ public static <T> ParseInput<T> createFromParts(String expected, Function1<Query
return new Tuple<>(s, transformer.call(temp));
});
}

public static <IN1, IN2, T> ParseInput<T> createFromParts(String expected, Function2<IN1, IN2, T> transformer, Class<IN1> in1, Class<IN2> in2)
public static <IN1, IN2, T> ParseInput<T> createFromParts(String expected, Function2<IN1, IN2, T> transformer,
Class<IN1> in1, Class<IN2> in2)
{
Function1<String, IN1> t1 = getTransformerForClass(in1);
Function1<String, IN2> t2 = getTransformerForClass(in2);

Function1<String, IN1> t1 = getTransformerForClass(in1);
Function1<String, IN2> t2 = getTransformerForClass(in2);
return new ParseInput<T>(expected, s -> {
var temp = Queryable.as(s.split(",")).select(String::trim);
IN1 v1 = t1.call(temp.get(0));
Expand All @@ -47,14 +46,13 @@ public static <IN1, IN2, T> ParseInput<T> createFromParts(String expected, Funct
return new Tuple<>(s, out);
});
}

public static <T> ParseInput<T> create(String expected, Class<T> tranformTo)
{
Function1<String, T> transformer1 = getTransformerForClass(tranformTo);
return ParseInput.create(expected, transformer1);
}

private static <T> Function1<String, T> getTransformerForClass(Class<T> tranformTo) {
private static <T> Function1<String, T> getTransformerForClass(Class<T> tranformTo)
{
var transformers = new HashMap<Class<?>, Function1<String, Object>>()
{
{
Expand All @@ -70,7 +68,6 @@ private static <T> Function1<String, T> getTransformerForClass(Class<T> tranform
Function1<String, T> transformer1 = (Function1<String, T>) transformers.get(tranformTo);
return transformer1;
}

public Queryable<Tuple<String, T>> parse(String expected)
{
return Queryable.as(expected.lines()).select(l -> l.split("->")[0].trim()).select(l -> transformer.call(l));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void testPeopleEasyLoad()
Llewellyn, 25 -> adult
Oliver, 15 -> teenager
""";
ParseInput.createFromParts(expected, (n,a) -> new Person(n,a), String.class, Integer.class)
.verifyAll(s -> s.getAgeLabel());
ParseInput.createFromParts(expected, (n, a) -> new Person(n, a), String.class, Integer.class)
.verifyAll(s -> s.getAgeLabel());
}
}

0 comments on commit 46bf879

Please sign in to comment.