1 11 package org.eclipse.core.internal.watson; 12 13 21 public final class DefaultElementComparator implements IElementComparator { 22 private static DefaultElementComparator singleton; 23 24 27 protected DefaultElementComparator() { 28 super(); 29 } 30 31 34 public int compare(Object oldInfo, Object newInfo) { 35 if (oldInfo == null && newInfo == null) 36 return 0; 37 if (oldInfo == null || newInfo == null) 38 return 1; 39 return testEquality(oldInfo, newInfo) ? 0 : 1; 40 } 41 42 45 public static IElementComparator getComparator() { 46 if (singleton == null) { 47 singleton = new DefaultElementComparator(); 48 } 49 return singleton; 50 } 51 52 55 protected boolean testEquality(Object oldInfo, Object newInfo) { 56 if (oldInfo == null && newInfo == null) 57 return true; 58 if (oldInfo == null || newInfo == null) 59 return false; 60 61 return oldInfo.equals(newInfo); 62 } 63 } 64 | Popular Tags |