1 | package com.github.valid8j.pcond.core; | |
2 | ||
3 | import static java.util.Objects.requireNonNull; | |
4 | ||
5 | public class ValueHolder<V> implements Cloneable { | |
6 | ||
7 | private final State state; | |
8 | private final CreatorFormType creatorFormType; | |
9 | V value; | |
10 | Throwable exception; | |
11 | ||
12 | private ValueHolder(State state, V value, Throwable exception, CreatorFormType creatorFormType) { | |
13 | this.state = state; | |
14 | this.value = value; | |
15 | this.exception = exception; | |
16 | this.creatorFormType = creatorFormType; | |
17 | } | |
18 | ||
19 | @SuppressWarnings("unchecked") | |
20 | public ValueHolder<V> clone() { | |
21 | try { | |
22 |
1
1. clone : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::clone → KILLED |
return (ValueHolder<V>) super.clone(); |
23 | } catch (CloneNotSupportedException e) { | |
24 | throw new RuntimeException(e); | |
25 | } | |
26 | } | |
27 | ||
28 | public State state() { | |
29 |
1
1. state : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::state → KILLED |
return this.state; |
30 | } | |
31 | ||
32 | public V returnedValue() { | |
33 |
1
1. returnedValue : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::returnedValue → KILLED |
return this.state.value(this); |
34 | } | |
35 | ||
36 | public Throwable thrownException() { | |
37 |
1
1. thrownException : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::thrownException → KILLED |
return this.state.exception(this); |
38 | } | |
39 | ||
40 | public Object value() { | |
41 |
1
1. value : negated conditional → KILLED |
if (isValueReturned()) |
42 |
1
1. value : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::value → KILLED |
return this.returnedValue(); |
43 |
1
1. value : negated conditional → KILLED |
if (isEvaluationSkipped()) |
44 |
1
1. value : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::value → SURVIVED |
return Evaluator.Impl.EVALUATION_SKIPPED; |
45 |
1
1. value : negated conditional → KILLED |
if (isExceptionThrown()) |
46 |
1
1. value : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::value → KILLED |
return this.thrownException(); |
47 | throw new IllegalStateException(); | |
48 | } | |
49 | ||
50 | public static <V> ValueHolder<V> forValue(V value) { | |
51 |
1
1. forValue : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::forValue → KILLED |
return new ValueHolder<>(State.VALUE_RETURNED, value, null, CreatorFormType.UNKNOWN); |
52 | } | |
53 | ||
54 | @Override | |
55 | public String toString() { | |
56 |
1
1. toString : negated conditional → NO_COVERAGE |
if (isValueReturned()) |
57 |
1
1. toString : replaced return value with "" for com/github/valid8j/pcond/core/ValueHolder::toString → NO_COVERAGE |
return String.format("state:%s, value:%s, creator:%s", state, value, creatorFormType); |
58 |
1
1. toString : negated conditional → NO_COVERAGE |
if (isEvaluationSkipped()) |
59 |
1
1. toString : replaced return value with "" for com/github/valid8j/pcond/core/ValueHolder::toString → NO_COVERAGE |
return String.format("state:%s, exception:%s, creator:%s", state, exception, creatorFormType); |
60 |
1
1. toString : replaced return value with "" for com/github/valid8j/pcond/core/ValueHolder::toString → NO_COVERAGE |
return String.format("state:%s, creator:%s", state, creatorFormType); |
61 | } | |
62 | ||
63 | public boolean isValueReturned() { | |
64 |
2
1. isValueReturned : negated conditional → KILLED 2. isValueReturned : replaced boolean return with true for com/github/valid8j/pcond/core/ValueHolder::isValueReturned → KILLED |
return this.state() == State.VALUE_RETURNED; |
65 | } | |
66 | ||
67 | public boolean isExceptionThrown() { | |
68 |
2
1. isExceptionThrown : replaced boolean return with true for com/github/valid8j/pcond/core/ValueHolder::isExceptionThrown → SURVIVED 2. isExceptionThrown : negated conditional → KILLED |
return this.state() == State.EXCEPTION_THROWN; |
69 | } | |
70 | ||
71 | public boolean isEvaluationSkipped() { | |
72 |
2
1. isEvaluationSkipped : negated conditional → KILLED 2. isEvaluationSkipped : replaced boolean return with true for com/github/valid8j/pcond/core/ValueHolder::isEvaluationSkipped → KILLED |
return this.state() == State.EVALUATION_SKIPPED; |
73 | } | |
74 | ||
75 | public CreatorFormType creatorFormType() { | |
76 |
1
1. creatorFormType : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::creatorFormType → KILLED |
return this.creatorFormType; |
77 | } | |
78 | ||
79 | public ValueHolder<V> valueReturned(V value) { | |
80 | // requireState(this.state, v -> v.equals(State.NOT_YET_EVALUATED), v -> messageNotYetEvaluatedStateIsRequired(v, this)); | |
81 |
1
1. valueReturned : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::valueReturned → KILLED |
return new ValueHolder<>(State.VALUE_RETURNED, value, null, this.creatorFormType); |
82 | } | |
83 | ||
84 | public ValueHolder<V> exceptionThrown(Throwable throwable) { | |
85 | // requireState(this.state, v -> v.equals(State.NOT_YET_EVALUATED), v -> messageNotYetEvaluatedStateIsRequired(v, this)); | |
86 |
1
1. exceptionThrown : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::exceptionThrown → KILLED |
return new ValueHolder<>(State.EXCEPTION_THROWN, null, requireNonNull(throwable), this.creatorFormType); |
87 | } | |
88 | ||
89 | public ValueHolder<V> evaluationSkipped() { | |
90 | // requireState(this.state, v -> v.equals(State.NOT_YET_EVALUATED), v -> messageNotYetEvaluatedStateIsRequired(v, this)); | |
91 |
1
1. evaluationSkipped : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::evaluationSkipped → KILLED |
return new ValueHolder<>(State.EVALUATION_SKIPPED, null, null, this.creatorFormType); |
92 | } | |
93 | ||
94 | public ValueHolder<V> creatorFormType(CreatorFormType creatorFormType) { | |
95 |
1
1. creatorFormType : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::creatorFormType → KILLED |
return new ValueHolder<>(this.state, this.value, this.exception, creatorFormType); |
96 | } | |
97 | ||
98 | static <E> ValueHolder<E> create() { | |
99 |
1
1. create : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::create → KILLED |
return create(CreatorFormType.UNKNOWN); |
100 | } | |
101 | ||
102 | public static <E> ValueHolder<E> create(CreatorFormType creatorFormType) { | |
103 |
1
1. create : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::create → KILLED |
return new ValueHolder<>(State.NOT_YET_EVALUATED, null, null, creatorFormType); |
104 | } | |
105 | ||
106 | public enum State { | |
107 | NOT_YET_EVALUATED { | |
108 | }, | |
109 | VALUE_RETURNED { | |
110 | <V> V value(ValueHolder<V> valueHolder) { | |
111 |
1
1. value : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder$State$2::value → KILLED |
return valueHolder.value; |
112 | } | |
113 | }, | |
114 | EXCEPTION_THROWN { | |
115 | <V> Throwable exception(ValueHolder<V> vContextVariable) { | |
116 |
1
1. exception : replaced return value with null for com/github/valid8j/pcond/core/ValueHolder$State$3::exception → KILLED |
return vContextVariable.exception; |
117 | } | |
118 | }, | |
119 | EVALUATION_SKIPPED { | |
120 | }; | |
121 | ||
122 | <V> V value(ValueHolder<V> valueHolder) { | |
123 | throw new IllegalStateException("current state=" + valueHolder.state); | |
124 | } | |
125 | ||
126 | <V> Throwable exception(ValueHolder<V> vContextVariable) { | |
127 | throw new IllegalStateException(); | |
128 | } | |
129 | } | |
130 | ||
131 | enum CreatorFormType { | |
132 | FUNC_HEAD, | |
133 | FUNC_TAIL, | |
134 | TRANSFORM, | |
135 | UNKNOWN | |
136 | } | |
137 | } | |
Mutations | ||
22 |
1.1 |
|
29 |
1.1 |
|
33 |
1.1 |
|
37 |
1.1 |
|
41 |
1.1 |
|
42 |
1.1 |
|
43 |
1.1 |
|
44 |
1.1 |
|
45 |
1.1 |
|
46 |
1.1 |
|
51 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
59 |
1.1 |
|
60 |
1.1 |
|
64 |
1.1 2.2 |
|
68 |
1.1 2.2 |
|
72 |
1.1 2.2 |
|
76 |
1.1 |
|
81 |
1.1 |
|
86 |
1.1 |
|
91 |
1.1 |
|
95 |
1.1 |
|
99 |
1.1 |
|
103 |
1.1 |
|
111 |
1.1 |
|
116 |
1.1 |