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