FunctionArguments implements ImmutableBean { public FunctionArguments mergedWith(FunctionArguments other, FunctionArguments... others) { ArgumentChecker.notNull(other, "other"); Map<String, Object> arguments = new HashMap<>(); List<FunctionArguments> reversedOthers = new ArrayList<>(Arrays.asList(others)); Collections.reverse(reversedOthers); for (FunctionArguments args : reversedOthers) { arguments.putAll(args._arguments); } arguments.putAll(other._arguments); arguments.putAll(_arguments); return new FunctionArguments(arguments); } @ImmutableConstructor  FunctionArguments(Map<String, Object> arguments); Object getArgument(String parameterName); FunctionArguments mergedWith(FunctionArguments other, FunctionArguments... others); static FunctionArguments.Meta meta(); static FunctionArguments.Builder builder(); @Override FunctionArguments.Meta metaBean(); @Override Property<R> property(String propertyName); @Override Set<String> propertyNames(); ImmutableMap<String, Object> getArguments(); Builder toBuilder(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static final FunctionArguments EMPTY; }
@Test public void mergedWith() { FunctionArguments args1 = new FunctionArguments(ImmutableMap.<String, Object>of("foo", "FOO", "bar", "BAR")); FunctionArguments args2 = new FunctionArguments(ImmutableMap.<String, Object>of("bar", "BAR2", "baz", "BAZ")); FunctionArguments args3 = new FunctionArguments(ImmutableMap.<String, Object>of("boz", "BOZ", "baz", "BAZ2")); FunctionArguments args4 = new FunctionArguments(ImmutableMap.<String, Object>of("aaa", "AAA", "baz", "BAZ3")); FunctionArguments expected = new FunctionArguments(ImmutableMap.<String, Object>of("foo", "FOO", "bar", "BAR", "baz", "BAZ", "boz", "BOZ", "aaa", "AAA")); assertEquals(expected, args1.mergedWith(args2, args3, args4)); }