Skip to content

Commit 437b3d9

Browse files
committed
A little cleanup, mostly whitespace. (#241)
1 parent fe63bad commit 437b3d9

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public void apply(final Metafix metafix, final Record record, final List<String>
124124
record.addNested(newName, oldValue); // we're actually aliasing
125125
}));
126126
}
127-
128127
},
129128
format {
130129
@Override

metafix/src/main/java/org/metafacture/metafix/FixPath.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ private FixPath(final String[] path) {
6464
}
6565

6666
/*package-private*/ Value findIn(final Array array) {
67-
6867
final Value result;
68+
6969
if (path.length == 0) {
7070
result = new Value(array);
7171
}
@@ -96,8 +96,8 @@ else if (isReference(currentSegment)) {
9696
result = Value.newArray(a -> array.forEach(v -> a.add(findInValue(v, path))));
9797
}
9898
}
99-
return result;
10099

100+
return result;
101101
}
102102

103103
private Value findInValue(final Value value, final String[] p) {
@@ -124,6 +124,7 @@ public String toString() {
124124

125125
/*package-private*/ FixPath to(final Value value, final int i) {
126126
final FixPath result;
127+
127128
// One *, no matching path: replace with index of current result
128129
if (countAsterisks() == 1 && !matches(value.getPath())) {
129130
result = new FixPath(replaceInPath(ASTERISK, i));
@@ -135,6 +136,7 @@ else if (value.getPath() != null && hasWildcard()) {
135136
else {
136137
result = this;
137138
}
139+
138140
return result;
139141
}
140142

@@ -154,7 +156,7 @@ private long countAsterisks() {
154156
return Arrays.asList(path).stream().filter(s -> s.equals(ASTERISK)).count();
155157
}
156158

157-
/* package-private */ enum InsertMode {
159+
/*package-private*/ enum InsertMode {
158160

159161
REPLACE {
160162
@Override
@@ -246,10 +248,10 @@ private void removeNestedFrom(final Value value) {
246248
}
247249
}
248250

249-
/*package-private*/ private Value insertInto(final Array array, final InsertMode mode, final Value newValue) {
251+
private Value insertInto(final Array array, final InsertMode mode, final Value newValue) {
250252
// basic idea: reuse findIn logic here? setIn(findIn(array), newValue)
251-
252253
final String field = path[0];
254+
253255
if (path.length == 1) {
254256
mode.apply(array, field, newValue);
255257
}
@@ -261,12 +263,14 @@ else if (isReference(field)) {
261263
insertInto(getReferencedValue(array, field, newValue.getPath()), mode, newValue, field, tail(path));
262264
}
263265
}
266+
264267
return new Value(array);
265268
}
266269

267270
/*package-private*/ Value insertInto(final Hash hash, final InsertMode mode, final Value newValue) {
268271
// basic idea: reuse findIn logic here? setIn(findIn(hash), newValue)
269272
final String field = path[0];
273+
270274
if (path.length == 1) {
271275
mode.apply(hash, field, newValue);
272276
}
@@ -276,11 +280,11 @@ else if (isReference(field)) {
276280
}
277281
insertInto(hash.get(field), mode, newValue, field, tail(path));
278282
}
283+
279284
return new Value(hash);
280285
}
281286

282-
private Value insertInto(final Value value, final InsertMode mode, final Value newValue, final String field,
283-
final String[] tail) {
287+
private Value insertInto(final Value value, final InsertMode mode, final Value newValue, final String field, final String[] tail) {
284288
if (value != null) {
285289
final FixPath fixPath = new FixPath(tail);
286290
newValue.withPathSet(value.getPath());
@@ -320,10 +324,12 @@ private boolean isReference(final String field) {
320324
// TODO replace switch, extract to method on array?
321325
private Value getReferencedValue(final Array array, final String field, final String p) {
322326
Value referencedValue = null;
327+
323328
if (Value.isNumber(field)) {
324329
final int index = Integer.valueOf(field) - 1;
325330
return 0 <= index && index < array.size() ? array.get(index) : null;
326331
}
332+
327333
final ReservedField reservedField = ReservedField.fromString(field);
328334
if (reservedField != null) {
329335
switch (reservedField) {
@@ -341,6 +347,7 @@ private Value getReferencedValue(final Array array, final String field, final St
341347
break;
342348
}
343349
}
350+
344351
return referencedValue;
345352
}
346353

metafix/src/main/java/org/metafacture/metafix/Value.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ public Value(final Map<String, Value> hash) {
100100
}
101101
}
102102

103-
public Value(final int integer) {
104-
this(String.valueOf(integer));
105-
}
106-
107103
public Value(final String string) {
108104
this(string != null ? Type.String : null, null, null, string);
109105
}
110106

107+
public Value(final int integer) {
108+
this(String.valueOf(integer));
109+
}
110+
111111
public static Value newArray() {
112112
return newArray(null);
113113
}
@@ -257,17 +257,12 @@ public String getPath() {
257257
return this;
258258
}
259259

260-
/*package-private*/ Value withPathAppend(final int i) {
260+
private Value withPathAppend(final int i) {
261261
return withPathAppend(String.valueOf(i));
262262
}
263263

264-
/*package-private*/ Value withPathAppend(final String field) {
265-
if (path == null || path.isEmpty()) {
266-
return this.withPathSet(field);
267-
}
268-
else {
269-
return this.withPathSet(path + "." + field);
270-
}
264+
private Value withPathAppend(final String field) {
265+
return withPathSet(path == null || path.isEmpty() ? field : path + "." + field);
271266
}
272267

273268
/*package-private*/ Value copy() {
@@ -437,8 +432,7 @@ public void remove(final int index) {
437432
}
438433

439434
/*package-private*/ void set(final int index, final Value value) {
440-
list.set(index, value);
441-
value.withPathAppend(index + 1);
435+
list.set(index, value.withPathAppend(index + 1));
442436
}
443437

444438
/*package-private*/ void removeIf(final Predicate<Value> predicate) {
@@ -622,8 +616,8 @@ public void add(final String field, final Value newValue) {
622616
oldValue.withPathAppend(1);
623617
}
624618

625-
put(field, oldValue.asList(oldVals -> newValue
626-
.asList(newVals -> newVals.forEach(newVal -> oldVals.add(newVal.withPathSet(basePath))))));
619+
put(field, oldValue.asList(oldVals -> newValue.asList(newVals ->
620+
newVals.forEach(newVal -> oldVals.add(newVal.withPathSet(basePath))))));
627621
}
628622
}
629623

0 commit comments

Comments
 (0)