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