diff --git a/metafix/src/main/java/org/metafacture/metafix/Value.java b/metafix/src/main/java/org/metafacture/metafix/Value.java index 496abeda..17dfef5a 100644 --- a/metafix/src/main/java/org/metafacture/metafix/Value.java +++ b/metafix/src/main/java/org/metafacture/metafix/Value.java @@ -305,21 +305,6 @@ void apply(final Hash hash, final String field, final Value value) { void apply(final Hash hash, final String field, final Value value) { hash.add(field, value); } - }, - /* For an indexed representation of arrays as hashes with 1, 2, 3 etc. keys. - * i.e. ["a", "b", "c"] as { "1":"a", "2":"b", "3": "c" } - * This is what is produced by JsonDecoder and Metafix itself for arrays. - * TODO? maybe this would be a good general internal representation, resulting - * in every value being either a hash or a string, no more separate array type.*/ - INDEXED { - @Override - void apply(final Hash hash, final String field, final Value value) { - hash.add(nextIndex(hash), field.equals(ReservedField.$append.name()) ? value : newHash(h -> h.put(field, value))); - } - - private String nextIndex(final Hash hash) { - return "" + (hash.size() + 1) /* TODO? check if keys are actually all ints? */; - } }; abstract void apply(Hash hash, String field, Value value); @@ -697,7 +682,7 @@ private Value insert(final InsertMode mode, final String[] fields, final Value n // TODO: move impl into enum elements, here call only value.insert value.matchType() .ifArray(a -> a.insert(mode, tail, newValue)) - .ifHash(h -> h.insert(insertMode(mode, field, tail), tail, newValue)) + .ifHash(h -> h.insert(mode, tail, newValue)) .orElseThrow(); } } @@ -708,7 +693,7 @@ private Value insert(final InsertMode mode, final String[] fields, final Value n private Value processRef(final InsertMode mode, final Value newValue, final String field, final String[] tail) { final Value referencedValue = getReferencedValue(field); if (referencedValue != null) { - return referencedValue.asHash().insert(insertMode(mode, field, tail), tail, newValue); + return referencedValue.asHash().insert(mode, tail, newValue); } else { throw new IllegalArgumentException("Using ref, but can't find: " + field + " in: " + this); @@ -738,16 +723,6 @@ private Value getReferencedValue(final String field) { return referencedValue; } - private InsertMode insertMode(final InsertMode mode, final String field, final String[] tail) { - // if the field is marked as array, this hash should be smth. like { 1=a, 2=b } - final boolean isIndexedArray = field.endsWith(Metafix.ARRAY_MARKER); - final boolean nextIsRef = tail.length > 0 && ( - tail[0].startsWith(ReservedField.$first.name()) || - tail[0].startsWith(ReservedField.$last.name()) || - isNumber(tail[0])); - return isIndexedArray && !nextIsRef ? InsertMode.INDEXED : mode; - } - /** * Removes the given field/value pair from this hash. * diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index 9374be67..14c3624b 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -477,6 +477,7 @@ public void complexAppendWithArrayOfObjects() { @Test public void appendWithWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('stringimals[]')", "copy_field('?nimal', 'stringimals[].$append')" ), i -> { @@ -542,6 +543,7 @@ public void simpleCopyWithWildcard() { @Test public void appendWithMultipleWildcards() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('stringimals[]')", "copy_field('?ni??l', 'stringimals[].$append')" ), i -> { @@ -572,6 +574,7 @@ public void appendWithMultipleWildcards() { @Test public void appendWithAsteriksWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('stringimals[]')", "copy_field('*al', 'stringimals[].$append')" ), i -> { @@ -601,6 +604,7 @@ public void appendWithAsteriksWildcard() { @Test public void appendWithBracketWildcard() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('stringimals[]')", "copy_field('[ac]nimal', 'stringimals[].$append')" ), i -> { @@ -630,6 +634,7 @@ public void appendWithBracketWildcard() { // See https://github.com/metafacture/metafacture-fix/issues/89 public void appendWithAsteriksWildcardAtTheEnd() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "set_array('stringimals[]')", "copy_field('ani*', 'stringimals[].$append')" ), i -> {