1 26 28 package de.nava.informa.utils; 29 30 import java.util.Comparator ; 31 import java.util.Iterator ; 32 33 import de.nava.informa.core.ChannelIF; 34 35 48 public final class ChannelComparator implements Comparator { 49 50 52 53 public static final int CHANNEL_MISMATCH = -1; 54 55 56 public static final int CHANNEL_IDENTICAL = 0; 57 58 59 public static final int CHANNEL_CHANGED = 1; 60 61 public ChannelComparator() { 62 } 63 64 public int compare(Object obj1, Object obj2) { 65 66 if (obj1 instanceof ChannelIF) { 67 ChannelIF channel1 = (ChannelIF) obj1; 68 69 if (obj2 instanceof ChannelIF) { 70 ChannelIF channel2 = (ChannelIF) obj2; 71 72 if (!channel1.equals(channel2)) { 73 return CHANNEL_MISMATCH; 74 } 75 76 if (channel1.getItems().size() != channel2.getItems().size()) { 77 return CHANNEL_CHANGED; 78 } 79 80 Iterator items = channel1.getItems().iterator(); 81 82 while (items.hasNext()) { 83 if (!channel2.getItems().contains(items.next())) { 84 return CHANNEL_CHANGED; 85 } 86 } 87 88 return CHANNEL_IDENTICAL; 89 90 } else { 91 throw new IllegalArgumentException ("Not instance of ChannelIF " + obj2); 92 } 93 94 } else { 95 throw new IllegalArgumentException ("Not instance of ChannelIF " + obj1); 96 } 97 } 98 99 } 100 | Popular Tags |