@Test public void shouldReuseTarget() { final IArrayNode<?> firstArray = createArrayNode(null, IntNode.valueOf(2), IntNode.valueOf(3)); final IArrayNode<?> secondArray = createArrayNode(IntNode.valueOf(1)); final ArrayMerger arrayMerger = new ArrayMerger(); final IJsonNode result1 = arrayMerger.evaluate(createArrayNode(firstArray, secondArray)); final IJsonNode result2 = arrayMerger.evaluate(createArrayNode(firstArray, secondArray)); Assert.assertEquals(createArrayNode(IntNode.valueOf(1), IntNode.valueOf(2), IntNode.valueOf(3)), result2); Assert.assertSame(result1, result2); }
@Override public IJsonNode evaluate(final IJsonNode node) { this.result.clear(); for (final IJsonNode nextNode : (IArrayNode<?>) node) if (nextNode != NullNode.getInstance()) { final IArrayNode<?> array = (IArrayNode<?>) nextNode; for (int index = 0; index < array.size(); index++) if (this.result.size() <= index) this.result.add(array.get(index)); else if (this.isNull(this.result.get(index)) && !this.isNull(array.get(index))) this.result.set(index, array.get(index)); } return this.result; }
ArrayMerger extends EvaluationExpression { @Override public IJsonNode evaluate(final IJsonNode node) { this.result.clear(); for (final IJsonNode nextNode : (IArrayNode<?>) node) if (nextNode != NullNode.getInstance()) { final IArrayNode<?> array = (IArrayNode<?>) nextNode; for (int index = 0; index < array.size(); index++) if (this.result.size() <= index) this.result.add(array.get(index)); else if (this.isNull(this.result.get(index)) && !this.isNull(array.get(index))) this.result.set(index, array.get(index)); } return this.result; } }
ArrayMerger extends EvaluationExpression { @Override public IJsonNode evaluate(final IJsonNode node) { this.result.clear(); for (final IJsonNode nextNode : (IArrayNode<?>) node) if (nextNode != NullNode.getInstance()) { final IArrayNode<?> array = (IArrayNode<?>) nextNode; for (int index = 0; index < array.size(); index++) if (this.result.size() <= index) this.result.add(array.get(index)); else if (this.isNull(this.result.get(index)) && !this.isNull(array.get(index))) this.result.set(index, array.get(index)); } return this.result; }  }
ArrayMerger extends EvaluationExpression { @Override public IJsonNode evaluate(final IJsonNode node) { this.result.clear(); for (final IJsonNode nextNode : (IArrayNode<?>) node) if (nextNode != NullNode.getInstance()) { final IArrayNode<?> array = (IArrayNode<?>) nextNode; for (int index = 0; index < array.size(); index++) if (this.result.size() <= index) this.result.add(array.get(index)); else if (this.isNull(this.result.get(index)) && !this.isNull(array.get(index))) this.result.set(index, array.get(index)); } return this.result; }  @Override void appendAsString(final Appendable appendable); @Override IJsonNode evaluate(final IJsonNode node); }
ArrayMerger extends EvaluationExpression { @Override public IJsonNode evaluate(final IJsonNode node) { this.result.clear(); for (final IJsonNode nextNode : (IArrayNode<?>) node) if (nextNode != NullNode.getInstance()) { final IArrayNode<?> array = (IArrayNode<?>) nextNode; for (int index = 0; index < array.size(); index++) if (this.result.size() <= index) this.result.add(array.get(index)); else if (this.isNull(this.result.get(index)) && !this.isNull(array.get(index))) this.result.set(index, array.get(index)); } return this.result; }  @Override void appendAsString(final Appendable appendable); @Override IJsonNode evaluate(final IJsonNode node);  }