1 | package com.github.dakusui.pcond.core.printable; | |
2 | ||
3 | import com.github.dakusui.pcond.core.Evaluable; | |
4 | import com.github.dakusui.pcond.core.Evaluator; | |
5 | import com.github.dakusui.pcond.experimentals.currying.CurriedFunction; | |
6 | import com.github.dakusui.pcond.core.identifieable.Identifiable; | |
7 | ||
8 | import java.util.List; | |
9 | import java.util.Objects; | |
10 | import java.util.Optional; | |
11 | import java.util.function.Function; | |
12 | import java.util.function.Supplier; | |
13 | ||
14 | public class PrintableFunction<T, R> extends | |
15 | Identifiable.Base implements | |
16 | Evaluable.Func<T>, | |
17 | CurriedFunction<T, R>, | |
18 | Evaluator.Explainable, | |
19 | Cloneable { | |
20 | final Function<? super T, ? extends R> function; | |
21 | private final Function<? super T, Object> head; | |
22 | private final Evaluable<Object> tail; | |
23 | private final Supplier<String> formatter; | |
24 | private final Function<?, R> tailAsFunction; | |
25 | ||
26 | boolean trivial = false; | |
27 | ||
28 | @SuppressWarnings("unchecked") | |
29 | protected PrintableFunction(Object creator, List<Object> args, Supplier<String> s, Function<? super T, ? extends R> function, Function<? super T, ?> head, Evaluable<?> tail) { | |
30 | super(creator, args); | |
31 | this.formatter = Objects.requireNonNull(s); | |
32 | this.function = requireNonPrintableFunction(unwrap(Objects.requireNonNull(function))); | |
33 |
1
1. <init> : negated conditional → KILLED |
this.head = head != null ? (Function<? super T, Object>) head : (Function<? super T, Object>) this; |
34 | this.tail = (Evaluable<Object>) tail; | |
35 | this.tailAsFunction = (Function<?, R>) tail; | |
36 | } | |
37 | ||
38 | protected PrintableFunction(Object creator, List<Object> args, Supplier<String> s, Function<? super T, ? extends R> function) { | |
39 | this(creator, args, s, function, null, null); | |
40 | } | |
41 | ||
42 | @Override | |
43 | public String toString() { | |
44 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/core/printable/PrintableFunction::toString → KILLED |
return this.formatter.get(); |
45 | } | |
46 | ||
47 | @Override | |
48 | public <V> Function<V, R> compose(Function<? super V, ? extends T> before) { | |
49 | Objects.requireNonNull(before); | |
50 |
1
1. compose : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::compose → KILLED |
return PrintableFunctionFactory.<V, T, R>compose(before, this); |
51 | } | |
52 | ||
53 | @SuppressWarnings("unchecked") | |
54 | @Override | |
55 | public <V> Function<T, V> andThen(Function<? super R, ? extends V> after) { | |
56 | Objects.requireNonNull(after); | |
57 |
1
1. andThen : negated conditional → KILLED |
@SuppressWarnings("rawtypes") Function f = this.tailAsFunction == null ? after : PrintableFunctionFactory.compose((Function) this.tailAsFunction, after); |
58 |
1
1. andThen : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::andThen → KILLED |
return PrintableFunctionFactory.compose(this.head, f); |
59 | } | |
60 | ||
61 | @Override | |
62 | public Function<? super T, Object> head() { | |
63 |
1
1. head : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::head → KILLED |
return this.head; |
64 | } | |
65 | ||
66 | @Override | |
67 | public Optional<Evaluable<Object>> tail() { | |
68 |
1
1. tail : replaced return value with Optional.empty for com/github/dakusui/pcond/core/printable/PrintableFunction::tail → KILLED |
return Optional.ofNullable(this.tail); |
69 | } | |
70 | ||
71 | @Override | |
72 | public R applyFunction(T value) { | |
73 |
1
1. applyFunction : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::applyFunction → KILLED |
return this.function.apply(value); |
74 | } | |
75 | ||
76 | @SuppressWarnings("unchecked") | |
77 | @Override | |
78 | public Class<?> parameterType() { | |
79 |
2
1. parameterType : negated conditional → KILLED 2. parameterType : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::parameterType → KILLED |
return function instanceof CurriedFunction ? |
80 | ((CurriedFunction<? super T, ? extends R>) function).parameterType() : | |
81 | Object.class; | |
82 | } | |
83 | ||
84 | @SuppressWarnings("unchecked") | |
85 | @Override | |
86 | public Class<? extends R> returnType() { | |
87 |
2
1. returnType : negated conditional → KILLED 2. returnType : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::returnType → KILLED |
return function instanceof CurriedFunction ? |
88 | (Class<? extends R>) ((CurriedFunction<? super T, ? extends R>) function).returnType() : | |
89 | (Class<? extends R>) Object.class; | |
90 | } | |
91 | ||
92 | @Override | |
93 | public Object explainOutputExpectation() { | |
94 |
1
1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::explainOutputExpectation → KILLED |
return this.head(); |
95 | } | |
96 | ||
97 | @Override | |
98 | public Object explainActual(Object actualValue) { | |
99 |
1
1. explainActual : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::explainActual → SURVIVED |
return actualValue; |
100 | } | |
101 | ||
102 | @SuppressWarnings("unchecked") | |
103 | public static <T, R> Function<T, R> unwrap(Function<T, R> function) { | |
104 | Function<T, R> ret = function; | |
105 |
1
1. unwrap : negated conditional → KILLED |
if (function instanceof PrintableFunction) { |
106 | ret = (Function<T, R>) ((PrintableFunction<T, R>) function).function; | |
107 | assert !(ret instanceof PrintableFunction); | |
108 | } | |
109 |
1
1. unwrap : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::unwrap → KILLED |
return ret; |
110 | } | |
111 | ||
112 | ||
113 | @SuppressWarnings({ "CloneDoesntDeclareCloneNotSupportedException", "unchecked" }) | |
114 | @Override | |
115 | protected PrintableFunction<T, R> clone() { | |
116 | try { | |
117 |
1
1. clone : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::clone → NO_COVERAGE |
return (PrintableFunction<T, R>) super.clone(); |
118 | } catch (CloneNotSupportedException e) { | |
119 | throw new AssertionError(); | |
120 | } | |
121 | } | |
122 | ||
123 | ||
124 | public boolean isSquashable() { | |
125 |
2
1. isSquashable : replaced boolean return with false for com/github/dakusui/pcond/core/printable/PrintableFunction::isSquashable → SURVIVED 2. isSquashable : replaced boolean return with true for com/github/dakusui/pcond/core/printable/PrintableFunction::isSquashable → SURVIVED |
return this.trivial; |
126 | } | |
127 | ||
128 | @Override | |
129 | public PrintableFunction<T, R> makeTrivial() { | |
130 | PrintableFunction<T, R> ret = this.clone(); | |
131 | ret.trivial = true; | |
132 |
1
1. makeTrivial : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::makeTrivial → NO_COVERAGE |
return ret; |
133 | } | |
134 | ||
135 | private static <T, R> Function<T, R> requireNonPrintableFunction(Function<T, R> function) { | |
136 | assert !(function instanceof PrintableFunction); | |
137 |
1
1. requireNonPrintableFunction : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::requireNonPrintableFunction → KILLED |
return function; |
138 | } | |
139 | } | |
Mutations | ||
33 |
1.1 |
|
44 |
1.1 |
|
50 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
63 |
1.1 |
|
68 |
1.1 |
|
73 |
1.1 |
|
79 |
1.1 2.2 |
|
87 |
1.1 2.2 |
|
94 |
1.1 |
|
99 |
1.1 |
|
105 |
1.1 |
|
109 |
1.1 |
|
117 |
1.1 |
|
125 |
1.1 2.2 |
|
132 |
1.1 |
|
137 |
1.1 |