1 | package com.github.valid8j.pcond.core.printable; | |
2 | ||
3 | import com.github.valid8j.pcond.core.identifieable.Identifiable; | |
4 | import com.github.valid8j.pcond.experimentals.currying.CurryingUtils; | |
5 | import com.github.valid8j.pcond.core.Evaluable; | |
6 | import com.github.valid8j.pcond.experimentals.currying.multi.MultiFunction; | |
7 | import com.github.valid8j.pcond.internals.InternalChecks; | |
8 | ||
9 | import java.lang.reflect.Method; | |
10 | import java.util.*; | |
11 | import java.util.function.Function; | |
12 | import java.util.function.Supplier; | |
13 | import java.util.stream.Stream; | |
14 | ||
15 | import static com.github.valid8j.pcond.core.refl.ReflUtils.formatMethodName; | |
16 | import static com.github.valid8j.pcond.core.refl.ReflUtils.invokeStaticMethod; | |
17 | import static java.lang.String.format; | |
18 | import static java.util.Arrays.asList; | |
19 | import static java.util.Collections.emptyList; | |
20 | import static java.util.Objects.requireNonNull; | |
21 | import static java.util.stream.Collectors.toList; | |
22 | ||
23 | public enum PrintableFunctionFactory { | |
24 | COMPOSE, | |
25 | ; | |
26 | ||
27 | public enum Simple { | |
28 | IDENTITY("identity", Function.identity()), | |
29 | STRINGIFY("stringify", Object::toString), | |
30 | LENGTH("length", (Function<String, Integer>) String::length), | |
31 | SIZE("size", (Function<Collection<?>, Integer>) Collection::size), | |
32 | STREAM("stream", (Function<Collection<?>, Stream<?>>) Collection::stream), | |
33 | STREAM_OF("streamOf", Stream::of), | |
34 | ARRAY_TO_LIST("arrayToList", (Function<Object[], List<Object>>) Arrays::asList), | |
35 |
1
1. lambda$static$0 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Simple::lambda$static$0 → KILLED |
COUNT_LINES("countLines", (String v) -> v.split(String.format("%n")).length), |
36 |
1
1. lambda$static$1 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Simple::lambda$static$1 → KILLED |
COLLECTION_TO_LIST("collectionToList", (Collection<?> c) -> new ArrayList<Object>() { |
37 | { | |
38 | addAll(c); | |
39 | } | |
40 | }), | |
41 |
1
1. lambda$static$2 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Simple::lambda$static$2 → NO_COVERAGE |
CAST_TO("cast@compileTime", (v) -> v), |
42 | ; | |
43 | private final Function<?, ?> instance; | |
44 | ||
45 | Simple(String name, Function<?, ?> function) { | |
46 |
1
1. lambda$new$3 : replaced return value with "" for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Simple::lambda$new$3 → KILLED |
instance = PrintableFunctionFactory.function(() -> name, function, this); |
47 | } | |
48 | ||
49 | @SuppressWarnings("unchecked") | |
50 | public <T, R> Function<T, R> instance() { | |
51 |
1
1. instance : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Simple::instance → KILLED |
return (Function<T, R>) this.instance; |
52 | } | |
53 | } | |
54 | ||
55 | public enum Parameterized { | |
56 |
4
1. lambda$null$0 : replaced return value with "" for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$null$0 → KILLED 2. lambda$null$2 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$null$2 → KILLED 3. lambda$static$1 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$static$1 → KILLED 4. lambda$static$3 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$static$3 → KILLED |
ELEMENT_AT((args) -> () -> format("at[%s]", args.get(0)), (args) -> (List<?> v) -> v.get((int) args.get(0))), |
57 |
4
1. lambda$null$4 : replaced return value with "" for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$null$4 → KILLED 2. lambda$null$6 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$null$6 → KILLED 3. lambda$static$5 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$static$5 → KILLED 4. lambda$static$7 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::lambda$static$7 → KILLED |
CAST((args) -> () -> format("castTo[%s]", requireNonNull((Class<?>) args.get(0)).getSimpleName()), (args) -> (Object v) -> ((Class<?>) args.get(0)).cast(v)), |
58 | ; | |
59 | final Function<List<Object>, Supplier<String>> formatterFactory; | |
60 | final Function<List<Object>, Function<?, ?>> functionFactory; | |
61 | ||
62 | Parameterized(Function<List<Object>, Supplier<String>> formatterFactory, Function<List<Object>, Function<?, ?>> functionFactory) { | |
63 | this.formatterFactory = formatterFactory; | |
64 | this.functionFactory = functionFactory; | |
65 | } | |
66 | ||
67 | @SuppressWarnings({ "unchecked", "rawtypes" }) | |
68 | public <T, R> Function<T, R> create(List<Object> args) { | |
69 |
1
1. create : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory$Parameterized::create → KILLED |
return PrintableFunctionFactory.create(this.formatterFactory, (Function) this.functionFactory, args, this); |
70 | } | |
71 | } | |
72 | ||
73 | @SuppressWarnings("unchecked") | |
74 | public static <T, R, S> PrintableFunction<T, S> compose(Function<? super T, ? extends R> before, Function<? super R, ? extends S> after) { | |
75 | PrintableFunction<? super T, ? extends R> before_ = toPrintableFunction(before); | |
76 | PrintableFunction<? super R, ? extends S> after_ = toPrintableFunction(after); | |
77 | PrintableFunction<Object, S> other = (PrintableFunction<Object, S>) after_; | |
78 |
1
1. compose : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::compose → KILLED |
return new PrintableFunction<>( |
79 | COMPOSE, | |
80 | asList(before_, after_), | |
81 |
1
1. lambda$compose$0 : replaced return value with "" for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$compose$0 → KILLED |
() -> format("%s->%s", before, after), |
82 |
1
1. lambda$compose$1 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$compose$1 → KILLED |
(T v) -> PrintableFunction.unwrap(after).apply(PrintableFunction.unwrap(before).apply(v)), |
83 | PrintableFunctionFactory.<T>extractHeadOf(before_), | |
84 | (Evaluable<?>) PrintableFunctionFactory.<T, R>extractTailOf(before) | |
85 |
1
1. lambda$compose$2 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$compose$2 → KILLED |
.map((Function<?, R> t) -> PrintableFunctionFactory.<Object, R, S>compose((Function<Object, R>) t, after)) |
86 | .orElse(other)); | |
87 | } | |
88 | ||
89 | @SuppressWarnings("unchecked") | |
90 | private static <T> Function<? super T, Object> extractHeadOf(Function<? super T, ?> f) { | |
91 | Function<? super T, Object> func = (Function<? super T, Object>) f; | |
92 | Function<? super T, Object> ret; | |
93 |
1
1. extractHeadOf : negated conditional → KILLED |
if (func instanceof PrintableFunction) { |
94 | ret = ((PrintableFunction<? super T, Object>) func).head(); | |
95 | } else { | |
96 | ret = func; | |
97 | } | |
98 |
1
1. extractHeadOf : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::extractHeadOf → KILLED |
return requireNonNull(ret); |
99 | } | |
100 | ||
101 | @SuppressWarnings("unchecked") | |
102 | private static <T, R> Optional<Function<?, R>> extractTailOf(Function<? super T, ? extends R> f) { | |
103 | Function<? super T, Object> func = (Function<? super T, Object>) f; | |
104 | Optional<Function<?, R>> ret; | |
105 |
1
1. extractTailOf : negated conditional → KILLED |
if (func instanceof PrintableFunction) { |
106 |
1
1. lambda$extractTailOf$3 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$extractTailOf$3 → KILLED |
ret = ((PrintableFunction<?, ?>) func).tail().map(e -> (Function<?, R>) e); |
107 | } else { | |
108 | ret = Optional.empty(); | |
109 | } | |
110 |
1
1. extractTailOf : replaced return value with Optional.empty for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::extractTailOf → KILLED |
return ret; |
111 | } | |
112 | ||
113 | public static <R> MultiFunction<R> multifunction(Method method, List<Integer> paramOrder) { | |
114 | InternalChecks.validateParamOrderList(paramOrder, method.getParameterCount()); | |
115 | InternalChecks.requireStaticMethod(method); | |
116 |
2
1. lambda$multifunction$4 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$multifunction$4 → KILLED 2. multifunction : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::multifunction → KILLED |
return new MultiFunction.Builder<R>(args -> invokeStaticMethod(method, (paramOrder).stream().map(args::get).toArray())) |
117 | .name(method.getName()) | |
118 |
1
1. lambda$multifunction$5 : replaced return value with "" for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$multifunction$5 → KILLED |
.formatter(() -> formatMethodName(method) + CurryingUtils.formatParameterOrder(paramOrder)) |
119 |
1
1. lambda$multifunction$6 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$multifunction$6 → KILLED |
.addParameters(paramOrder.stream().map(i -> method.getParameterTypes()[i]).collect(toList())) |
120 | .identityArgs(asList(method, InternalChecks.validateParamOrderList(paramOrder, method.getParameterCount()))) | |
121 | .$(); | |
122 | } | |
123 | ||
124 | public static <T, R> Function<T, R> function(Function<T, R> function) { | |
125 |
1
1. function : negated conditional → KILLED |
if (function instanceof PrintableFunction) |
126 |
1
1. function : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::function → KILLED |
return function; |
127 |
1
1. function : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::function → KILLED |
return function("noname:" + function.toString(), function); |
128 | } | |
129 | ||
130 | public static < | |
131 | T, R> Function<T, R> function(String name, Function<T, R> function) { | |
132 |
2
1. function : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::function → KILLED 2. lambda$function$7 : replaced return value with "" for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$function$7 → KILLED |
return function(() -> name, function); |
133 | } | |
134 | ||
135 | public static < | |
136 | T, R> Function<T, R> function(Supplier<String> formatter, Function<T, R> function) { | |
137 |
1
1. function : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::function → KILLED |
return function(formatter, function, PrintableFunctionFactory.class); |
138 | } | |
139 | ||
140 | public static < | |
141 | T, R> Function<T, R> function(Supplier<String> formatter, Function<T, R> function, Object fallbackCreator) { | |
142 |
1
1. function : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::function → KILLED |
return create( |
143 |
1
1. lambda$function$8 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$function$8 → KILLED |
(args) -> formatter, |
144 |
1
1. lambda$function$9 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$function$9 → KILLED |
(args) -> function, |
145 | emptyList(), | |
146 | fallbackCreator); | |
147 | } | |
148 | ||
149 | public static <T, R> PrintableFunction<T, R> create( | |
150 | Function<List<Object>, Supplier<String>> formatterFactory, Function<List<Object>, Function<T, R>> functionFactory, List<Object> args, | |
151 | Object fallbackCreator) { | |
152 | Supplier<String> formatter = formatterFactory.apply(args); | |
153 | Function<T, R> function = functionFactory.apply(args); | |
154 |
1
1. create : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::create → KILLED |
return Identifiable.creatorOf(function) |
155 |
1
1. lambda$create$10 : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::lambda$create$10 → KILLED |
.map(c -> new PrintableFunction<>(c, Identifiable.argsOf(function), formatter, function)) |
156 | .orElse(new PrintableFunction<>(fallbackCreator, args, formatter, function)); | |
157 | } | |
158 | ||
159 | private static < | |
160 | T, R> PrintableFunction<T, R> toPrintableFunction(Function<T, R> function) { | |
161 |
1
1. toPrintableFunction : replaced return value with null for com/github/valid8j/pcond/core/printable/PrintableFunctionFactory::toPrintableFunction → KILLED |
return (PrintableFunction<T, R>) function(function); |
162 | } | |
163 | } | |
Mutations | ||
35 |
1.1 |
|
36 |
1.1 |
|
41 |
1.1 |
|
46 |
1.1 |
|
51 |
1.1 |
|
56 |
1.1 2.2 3.3 4.4 |
|
57 |
1.1 2.2 3.3 4.4 |
|
69 |
1.1 |
|
78 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
85 |
1.1 |
|
93 |
1.1 |
|
98 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
110 |
1.1 |
|
116 |
1.1 2.2 |
|
118 |
1.1 |
|
119 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
132 |
1.1 2.2 |
|
137 |
1.1 |
|
142 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
161 |
1.1 |