1 | package com.github.dakusui.pcond.experimentals.currying.context; | |
2 | ||
3 | import com.github.dakusui.pcond.internals.InternalUtils; | |
4 | ||
5 | import java.util.Formattable; | |
6 | import java.util.Formatter; | |
7 | import java.util.List; | |
8 | ||
9 | import static com.github.dakusui.pcond.experimentals.currying.context.CurriedContext.PrivateUtils.variableBundleToString; | |
10 | import static java.util.Collections.singletonList; | |
11 | ||
12 | /** | |
13 | * `Context` is a concept to handle multiple values in the `pcond`. | |
14 | */ | |
15 | public interface CurriedContext extends Formattable { | |
16 | /** | |
17 | * Returns the number of context values. | |
18 | * | |
19 | * @return The number of context values. | |
20 | */ | |
21 | default int size() { | |
22 |
1
1. size : replaced int return with 0 for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext::size → KILLED |
return values().size(); |
23 | } | |
24 | ||
25 | /** | |
26 | * Returns the context value specified by the index. | |
27 | * | |
28 | * @param i The index of the context value to be returned. | |
29 | * @param <T> Expected type of the returned context value. | |
30 | * @return The specified context value. | |
31 | */ | |
32 | @SuppressWarnings("unchecked") | |
33 | default <T> T valueAt(int i) { | |
34 |
1
1. valueAt : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext::valueAt → KILLED |
return (T) values().get(i); |
35 | } | |
36 | ||
37 | /** | |
38 | * Creates a new context with an appended value. | |
39 | * | |
40 | * @param o A value to appended | |
41 | * @return A new context with the appended value. | |
42 | */ | |
43 | default CurriedContext append(Object o) { | |
44 |
1
1. append : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext::append → KILLED |
return new CurriedContext() { |
45 | @Override | |
46 | public List<Object> values() { | |
47 |
1
1. values : replaced return value with Collections.emptyList for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext$1::values → KILLED |
return InternalUtils.append(CurriedContext.this.values(), o); |
48 | } | |
49 | ||
50 | @Override | |
51 | public String toString() { | |
52 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext$1::toString → KILLED |
return variableBundleToString(this); |
53 | } | |
54 | }; | |
55 | } | |
56 | ||
57 | @Override | |
58 | default void formatTo(Formatter formatter, int flags, int width, int precision) { | |
59 | formatter.format("%s", variableBundleToString(this)); | |
60 | } | |
61 | ||
62 | /** | |
63 | * Returns context values. | |
64 | * | |
65 | * @return context values. | |
66 | */ | |
67 | List<Object> values(); | |
68 | ||
69 | /** | |
70 | * Creates a new context which has the given value as its only context value. | |
71 | * | |
72 | * @param o The value for which a new context is created. | |
73 | * @return A new context. | |
74 | */ | |
75 | static CurriedContext from(Object o) { | |
76 |
1
1. from : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext::from → KILLED |
return new CurriedContext() { |
77 | @Override | |
78 | public List<Object> values() { | |
79 |
1
1. values : replaced return value with Collections.emptyList for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext$2::values → KILLED |
return singletonList(o); |
80 | } | |
81 | ||
82 | @Override | |
83 | public String toString() { | |
84 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext$2::toString → NO_COVERAGE |
return variableBundleToString(this); |
85 | } | |
86 | ||
87 | }; | |
88 | } | |
89 | ||
90 | enum PrivateUtils { | |
91 | ; | |
92 | ||
93 | static String variableBundleToString(CurriedContext curriedContext) { | |
94 |
1
1. variableBundleToString : replaced return value with "" for com/github/dakusui/pcond/experimentals/currying/context/CurriedContext$PrivateUtils::variableBundleToString → KILLED |
return "variables:" + curriedContext.values(); |
95 | } | |
96 | } | |
97 | } | |
Mutations | ||
22 |
1.1 |
|
34 |
1.1 |
|
44 |
1.1 |
|
47 |
1.1 |
|
52 |
1.1 |
|
76 |
1.1 |
|
79 |
1.1 |
|
84 |
1.1 |
|
94 |
1.1 |