static List < DiffBean > diff ( Map < String , Object > oldObject , Map < String , Object > newObject ) { if ( oldObject == null ) oldObject = Objects . newHashMap ( ) ; if ( newObject == null ) newObject = Objects . newHashMap ( ) ; oldObject = Objects . copy ( oldObject ) ; newObject = Objects . copy ( newObject ) ; final List < DiffBean > diff = Objects . newArrayList ( ) ; Closure < TwoMapDiffBean , Object > itr = new Closure < TwoMapDiffBean , Object > ( ) { @ Override public Object call ( final TwoMapDiffBean d ) { ObjectIterator . iterate ( d . getM1 ( ) , new Closure < ObjectIterator . IterateBean , Object > ( ) { @ Override public Object call ( ObjectIterator . IterateBean i ) { Object o = i . getValue ( ) ; if ( o instanceof Map ) { } else if ( o instanceof List ) { } else { Object oo = null ; if ( ! Objects . isNullOrEmpty ( i . getPath ( ) ) ) oo = ObjectPath . get ( d . getM2 ( ) , i . getPath ( ) , null ) ; if ( d . isM1Old ( ) ) { if ( ! Objects . equals ( o , oo ) ) { final DiffBean res = new DiffBean ( i . getPath ( ) , o , oo ) ; if ( Objects . find ( diff , new Closure < DiffBean , Boolean > ( ) { @ Override public Boolean call ( DiffBean input ) { return input . getPath ( ) . equals ( res . getPath ( ) ) ; } } ) == null ) diff . add ( res ) ; } } else { if ( ! Objects . equals ( o , oo ) ) { final DiffBean res = new DiffBean ( i . getPath ( ) , oo , o ) ; if ( Objects . find ( diff , new Closure < DiffBean , Boolean > ( ) { @ Override public Boolean call ( DiffBean input ) { return input . getPath ( ) . equals ( res . getPath ( ) ) ; } } ) == null ) diff . add ( res ) ; } } } return o ; } } ) ; return null ; } } ; itr . call ( new TwoMapDiffBean ( oldObject , newObject , true ) ) ; itr . call ( new TwoMapDiffBean ( newObject , oldObject , false ) ) ; return diff ; }
Get difference between two maps