| 1 | package com.github.dakusui.symfonion.song; | |
| 2 | ||
| 3 | import com.github.dakusui.json.JsonException; | |
| 4 | import com.github.dakusui.json.JsonInvalidPathException; | |
| 5 | import com.github.dakusui.json.JsonUtils; | |
| 6 | import com.github.dakusui.symfonion.exceptions.FractionFormatException; | |
| 7 | import com.github.dakusui.symfonion.exceptions.SymfonionException; | |
| 8 | import com.github.dakusui.symfonion.utils.Fraction; | |
| 9 | import com.google.gson.JsonArray; | |
| 10 | import com.google.gson.JsonElement; | |
| 11 | import com.google.gson.JsonObject; | |
| 12 | ||
| 13 | import java.util.*; | |
| 14 | import java.util.Map.Entry; | |
| 15 | ||
| 16 | import static com.github.dakusui.json.JsonUtils.asJsonElement; | |
| 17 | import static com.github.dakusui.symfonion.exceptions.ExceptionThrower.*; | |
| 18 | import static com.github.dakusui.symfonion.exceptions.ExceptionThrower.ContextKey.JSON_ELEMENT_ROOT; | |
| 19 | import static com.github.dakusui.symfonion.exceptions.SymfonionIllegalFormatException.FRACTION_EXAMPLE; | |
| 20 | import static com.github.dakusui.symfonion.exceptions.SymfonionTypeMismatchException.ARRAY; | |
| 21 | ||
| 22 | public class Bar { | |
| 23 | private final Map<String, Groove> grooves; | |
| 24 | private final Map<String, Pattern> patterns; | |
| 25 | private final JsonObject rootJsonObject; | |
| 26 | Fraction beats; | |
| 27 | Map<String, List<List<Pattern>>> patternLists = new HashMap<>(); | |
| 28 | Groove groove; | |
| 29 | private final JsonObject json; | |
| 30 | ||
| 31 | ||
| 32 | public Bar(JsonObject jsonObject, JsonObject root, Map<String, Groove> grooves, Map<String, Pattern> patterns) throws SymfonionException, JsonException { | |
| 33 | this.grooves = grooves; | |
| 34 | this.patterns = patterns; | |
| 35 | this.json = jsonObject; | |
| 36 | this.rootJsonObject = root; | |
| 37 |
1
1. <init> : removed call to com/github/dakusui/symfonion/song/Bar::init → KILLED |
init(jsonObject, root); |
| 38 | } | |
| 39 | ||
| 40 | private void init(JsonObject jsonObject, JsonObject root) throws SymfonionException, JsonException { | |
| 41 | try (Context ignored = context($(JSON_ELEMENT_ROOT, root))) { | |
| 42 | try { | |
| 43 | this.beats = Fraction.parseFraction(JsonUtils.asString(jsonObject, Keyword.$beats)); | |
| 44 | } catch (FractionFormatException e) { | |
| 45 | throw illegalFormatException(asJsonElement(jsonObject, Keyword.$beats), FRACTION_EXAMPLE); | |
| 46 | } | |
| 47 |
1
1. init : negated conditional → SURVIVED |
this.beats = this.beats == null ? Fraction.one : this.beats; |
| 48 | this.groove = Groove.DEFAULT_INSTANCE; | |
| 49 | Groove g = Groove.DEFAULT_INSTANCE; | |
| 50 |
1
1. init : negated conditional → KILLED |
if (JsonUtils.hasPath(jsonObject, Keyword.$groove)) { |
| 51 | String grooveName = JsonUtils.asString(jsonObject, Keyword.$groove.name()); | |
| 52 | g = grooves.get(grooveName); | |
| 53 |
1
1. init : negated conditional → KILLED |
if (g == null) { |
| 54 | throw grooveNotDefinedException(asJsonElement(jsonObject, Keyword.$groove), grooveName); | |
| 55 | } | |
| 56 | } | |
| 57 | this.groove = g; | |
| 58 | JsonObject patternsJsonObject = JsonUtils.asJsonObject(jsonObject, Keyword.$patterns); | |
| 59 |
1
1. init : negated conditional → KILLED |
if (patternsJsonObject == null) { |
| 60 | throw requiredElementMissingException(jsonObject, Keyword.$patterns); | |
| 61 | } | |
| 62 | for (Entry<String, JsonElement> stringJsonElementEntry : patternsJsonObject.entrySet()) { | |
| 63 | String partName = stringJsonElementEntry.getKey(); | |
| 64 | List<List<Pattern>> patterns = new LinkedList<>(); | |
| 65 | JsonArray partPatternsJsonArray = JsonUtils.asJsonArray(patternsJsonObject, partName); | |
| 66 |
1
1. init : negated conditional → KILLED |
if (!partPatternsJsonArray.isJsonArray()) { |
| 67 | throw typeMismatchException(partPatternsJsonArray, ARRAY); | |
| 68 | } | |
| 69 | int len = partPatternsJsonArray.size(); | |
| 70 |
2
1. init : negated conditional → KILLED 2. init : changed conditional boundary → KILLED |
for (int j = 0; j < len; j++) { |
| 71 | JsonElement jsonPatterns = partPatternsJsonArray.get(j); | |
| 72 | String patternNames = jsonPatterns.getAsString(); | |
| 73 | List<Pattern> p = new LinkedList<>(); | |
| 74 | for (String each : patternNames.split(";")) { | |
| 75 | Pattern cur = this.patterns.get(each); | |
| 76 |
1
1. init : negated conditional → KILLED |
if (cur == null) { |
| 77 | throw patternNotFound(jsonPatterns, patternNames); | |
| 78 | } | |
| 79 | p.add(cur); | |
| 80 | } | |
| 81 | patterns.add(p); | |
| 82 | } | |
| 83 | patternLists.put(partName, patterns); | |
| 84 | } | |
| 85 | } | |
| 86 | } | |
| 87 | ||
| 88 | public Set<String> partNames() { | |
| 89 |
1
1. partNames : replaced return value with Collections.emptySet for com/github/dakusui/symfonion/song/Bar::partNames → KILLED |
return Collections.unmodifiableSet(this.patternLists.keySet()); |
| 90 | } | |
| 91 | ||
| 92 | public List<List<Pattern>> part(String instrumentName) { | |
| 93 |
1
1. part : replaced return value with Collections.emptyList for com/github/dakusui/symfonion/song/Bar::part → KILLED |
return Collections.unmodifiableList(this.patternLists.get(instrumentName)); |
| 94 | } | |
| 95 | ||
| 96 | public Fraction beats() { | |
| 97 |
1
1. beats : replaced return value with null for com/github/dakusui/symfonion/song/Bar::beats → KILLED |
return this.beats; |
| 98 | } | |
| 99 | ||
| 100 | public Groove groove() { | |
| 101 |
1
1. groove : replaced return value with null for com/github/dakusui/symfonion/song/Bar::groove → KILLED |
return this.groove; |
| 102 | } | |
| 103 | ||
| 104 | public JsonElement lookUpJsonNode(String partName) { | |
| 105 | try { | |
| 106 |
1
1. lookUpJsonNode : replaced return value with null for com/github/dakusui/symfonion/song/Bar::lookUpJsonNode → KILLED |
return asJsonElement(this.json, Keyword.$patterns, partName); |
| 107 | } catch (JsonInvalidPathException e) { | |
| 108 | return null; | |
| 109 | } | |
| 110 | } | |
| 111 | ||
| 112 | public JsonObject rootJsonObject() { | |
| 113 |
1
1. rootJsonObject : replaced return value with null for com/github/dakusui/symfonion/song/Bar::rootJsonObject → KILLED |
return this.rootJsonObject; |
| 114 | } | |
| 115 | } | |
Mutations | ||
| 37 |
1.1 |
|
| 47 |
1.1 |
|
| 50 |
1.1 |
|
| 53 |
1.1 |
|
| 59 |
1.1 |
|
| 66 |
1.1 |
|
| 70 |
1.1 2.2 |
|
| 76 |
1.1 |
|
| 89 |
1.1 |
|
| 93 |
1.1 |
|
| 97 |
1.1 |
|
| 101 |
1.1 |
|
| 106 |
1.1 |
|
| 113 |
1.1 |