public static List<List<Channel>> compareChannels(List<Channel> localChannels,List<Channel> serverChannels){
  List<Channel> channelsToAdd=new ArrayList<>();
  List<Channel> channelsToDelete=new ArrayList<>();
  List<Channel> channelsToUpdate=new ArrayList<>();
  Map<String,Channel> localChannelMap=new ArrayMap<>();
  Map<String,Channel> serverChannelMap=new ArrayMap<>();
  for (  Channel channel : localChannels) {
    localChannelMap.put(channel.getGeneratedId(),channel);
  }
  for (  Channel channel : serverChannels) {
    serverChannelMap.put(channel.getGeneratedId(),channel);
  }
  for (  Channel channel : serverChannelMap.values()) {
    if (!localChannelMap.containsKey(channel.getGeneratedId())) {
      channelsToAdd.add(channel);
    }
  }
  for (  Channel channel : localChannelMap.values()) {
    if (!serverChannelMap.containsKey(channel.getGeneratedId())) {
      channelsToDelete.add(channel);
    }
  }
  for (  Channel channel : serverChannelMap.values()) {
    Channel localChannel=localChannelMap.get(channel.getGeneratedId());
    if (localChannel != null) {
      if (!localChannel.metadataEquals(channel)) {
        channel.setId(localChannel.getId());
        channelsToUpdate.add(channel);
      }
    }
  }
  List<List<Channel>> channelComparison=new ArrayList<>();
  channelComparison.add(channelsToUpdate);
  channelComparison.add(channelsToAdd);
  channelComparison.add(channelsToDelete);
  return channelComparison;
}

public static List < List < Channel > > compareChannels ( List < Channel > localChannels , List < Channel > serverChannels ) { List < Channel > channelsToAdd = new ArrayList < > ( ) ; List < Channel > channelsToDelete = new ArrayList < > ( ) ; List < Channel > channelsToUpdate = new ArrayList < > ( ) ; Map < String , Channel > localChannelMap = new ArrayMap < > ( ) ; Map < String , Channel > serverChannelMap = new ArrayMap < > ( ) ; for ( Channel channel : localChannels ) { localChannelMap . put ( channel . getGeneratedId ( ) , channel ) ; } for ( Channel channel : serverChannels ) { serverChannelMap . put ( channel . getGeneratedId ( ) , channel ) ; } for ( Channel channel : serverChannelMap . values ( ) ) { if ( ! localChannelMap . containsKey ( channel . getGeneratedId ( ) ) ) { channelsToAdd . add ( channel ) ; } } for ( Channel channel : localChannelMap . values ( ) ) { if ( ! serverChannelMap . containsKey ( channel . getGeneratedId ( ) ) ) { channelsToDelete . add ( channel ) ; } } for ( Channel channel : serverChannelMap . values ( ) ) { Channel localChannel = localChannelMap . get ( channel . getGeneratedId ( ) ) ; if ( localChannel != null ) { if ( ! localChannel . metadataEquals ( channel ) ) { channel . setId ( localChannel . getId ( ) ) ; channelsToUpdate . add ( channel ) ; } } } List < List < Channel > > channelComparison = new ArrayList < > ( ) ; channelComparison . add ( channelsToUpdate ) ; channelComparison . add ( channelsToAdd ) ; channelComparison . add ( channelsToDelete ) ; return channelComparison ; }
compares channels stored locally to channels from the server , and returns whats new what to delete whats changed
