juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Bognar (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (JUNEAU-65) utility for merging two like POJOs
Date Sat, 02 Sep 2017 17:24:00 GMT

    [ https://issues.apache.org/jira/browse/JUNEAU-65?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16151545#comment-16151545
] 

James Bognar commented on JUNEAU-65:
------------------------------------

Added this class....
http://juneau.incubator.apache.org/site/apidocs/org/apache/juneau/utils/PojoMerge.html

> utility for merging two like POJOs
> ----------------------------------
>
>                 Key: JUNEAU-65
>                 URL: https://issues.apache.org/jira/browse/JUNEAU-65
>             Project: Juneau
>          Issue Type: New Feature
>            Reporter: Steve Blackmon
>             Fix For: 6.3.2
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> I think it would be useful to have a juneau utility to merge two pojos of the same class,
with a primary and a fallback.
> typesafe config has something like this: delta.withFallback(base) gives you a view where
anything not defined in delta is pulled from base
> the interface would look something like:
> PojoMerge<T> {
>   public T merge(T delta, T base);
> }
> the test case would be something like:
> class Bean { 
>   String foo;
>   String bar;
> }
> Bean blank = new Bean()
> Bean foo = new Bean(); foo.setFoo("foo")
> Bean bar = new Bean(); bar.setBar("bar")
> Bean foobar = new Bean(); foobar.setFoo("foo"), foobar.setBar("bar")
> assert( merge( blank, foo).equals(foo) )
> assert( merge( foo, blank).equals(foo) )
> assert( merge( foo, bar).equals(foobar) )
> assert( merge( bar, foo).equals(foobar) )
> assert( merge( blank, blank).equals(blank) )
> assert( merge( foo, foo ).equals(foo) )
> assert( merge( foo, foobar ).equals(foobar) )
> assert( merge( foobar, bar ).equals(foobar) )



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message