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