1 11 package org.eclipse.team.core.mapping.provider; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.runtime.Assert; 15 import org.eclipse.team.core.diff.provider.TwoWayDiff; 16 import org.eclipse.team.core.history.IFileRevision; 17 import org.eclipse.team.core.mapping.IResourceDiff; 18 19 26 public class ResourceDiff extends TwoWayDiff implements IResourceDiff { 27 28 private final IFileRevision before; 29 private final IFileRevision after; 30 private final IResource resource; 31 32 40 public ResourceDiff(IResource resource, int kind, int flags, IFileRevision before, IFileRevision after) { 41 super(resource.getFullPath(), kind, flags); 42 this.resource = resource; 43 this.before = before; 44 this.after = after; 45 } 46 47 54 public ResourceDiff(IResource resource, int kind) { 55 this(resource, kind, 0, null, null); 56 Assert.isTrue(resource.getType() != IResource.FILE); 57 } 58 59 62 public IFileRevision getBeforeState() { 63 return before; 64 } 65 66 69 public IFileRevision getAfterState() { 70 return after; 71 } 72 73 76 public IResource getResource() { 77 return resource; 78 } 79 80 83 public boolean equals(Object obj) { 84 if (obj == this) 85 return true; 86 if (super.equals(obj)) { 87 if (obj instanceof ResourceDiff) { 88 ResourceDiff other = (ResourceDiff) obj; 89 return getResource().equals(getResource()) 90 && revisionsEqual(getBeforeState(), other.getBeforeState()) 91 && revisionsEqual(getAfterState(), other.getAfterState()); 92 } 93 } 94 return false; 95 } 96 97 private boolean revisionsEqual(IFileRevision revision, IFileRevision revision2) { 98 if (revision == null) 99 return revision2 == null; 100 if (revision2 == null) 101 return false; 102 return revision.equals(revision2); 103 } 104 105 } 106 | Popular Tags |