1 11 package org.eclipse.team.core.variants; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.team.core.TeamException; 15 import org.eclipse.team.internal.core.TeamPlugin; 16 17 26 public class ThreeWayResourceComparator implements IResourceVariantComparator { 27 28 private ThreeWaySynchronizer synchronizer; 29 30 35 public ThreeWayResourceComparator(ThreeWaySynchronizer synchronizer) { 36 this.synchronizer = synchronizer; 37 } 38 39 42 public boolean compare(IResource local, IResourceVariant remote) { 43 if ((local.getType() == IResource.FILE) == remote.isContainer()) { 45 return false; 46 } 47 try { 48 if (local.getType() == IResource.FILE && getSynchronizer().isLocallyModified(local)) { 50 return false; 51 } 52 if (getSynchronizer().getBaseBytes(local) == null) return false; 54 return equals(getSynchronizer().getBaseBytes(local), getBytes(remote)); 56 } catch (TeamException e) { 57 TeamPlugin.log(e); 58 return false; 59 } 60 } 61 62 65 public boolean compare(IResourceVariant base, IResourceVariant remote) { 66 byte[] bytes1 = getBytes(base); 67 byte[] bytes2 = getBytes(remote); 68 return equals(bytes1, bytes2); 69 } 70 71 74 public boolean isThreeWay() { 75 return true; 76 } 77 78 private ThreeWaySynchronizer getSynchronizer() { 79 return synchronizer; 80 } 81 82 private byte[] getBytes(IResourceVariant remote) { 83 return remote.asBytes(); 84 } 85 86 private boolean equals(byte[] syncBytes, byte[] oldBytes) { 87 if (syncBytes.length != oldBytes.length) return false; 88 for (int i = 0; i < oldBytes.length; i++) { 89 if (oldBytes[i] != syncBytes[i]) return false; 90 } 91 return true; 92 } 93 } 94 | Popular Tags |