public static void compareProviders ( List < ProviderInfo > oldList , List < ProviderInfo > newList , List < ProviderInfo > add , List < ProviderInfo > remove ) { // 比较老列表和当前列表 if ( CommonUtils . isEmpty ( oldList ) ) { // 空变成非空 if ( CommonUtils . isNotEmpty ( newList ) ) { add . addAll ( newList ) ; } // 空到空，忽略 } else { // 非空变成空 if ( CommonUtils . isEmpty ( newList ) ) { remove . addAll ( oldList ) ; } else { // 非空变成非空，比较 if ( CommonUtils . isNotEmpty ( oldList ) ) { List < ProviderInfo > tmpList = new ArrayList < ProviderInfo > ( newList ) ; // 遍历老的 for ( ProviderInfo oldProvider : oldList ) { if ( tmpList . contains ( oldProvider ) ) { tmpList . remove ( oldProvider ) ; } else { // 新的没有，老的有，删掉 remove . add ( oldProvider ) ; } } add . addAll ( tmpList ) ; } } } }
Compare two provider list return add list and remove list