1 11 package org.eclipse.team.ui.synchronize; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.team.core.diff.IThreeWayDiff; 17 import org.eclipse.team.core.diff.provider.Diff; 18 import org.eclipse.team.ui.mapping.ITeamStateDescription; 19 20 26 public class TeamStateDescription implements ITeamStateDescription { 27 28 private int state; 29 private Map properties = new HashMap (); 30 31 35 public TeamStateDescription(int state) { 36 this.state = state; 37 } 38 39 42 public int getStateFlags() { 43 return state; 44 } 45 46 49 public int getKind() { 50 return getStateFlags() & Diff.KIND_MASK; 51 } 52 53 56 public int getDirection() { 57 return getStateFlags() & IThreeWayDiff.DIRECTION_MASK; 58 } 59 60 63 public String [] getPropertyNames() { 64 return (String []) properties.keySet().toArray(new String [properties.size()]); 65 } 66 67 70 public Object getProperty(String property) { 71 return properties.get(property); 72 } 73 74 79 public void setProperty(String property, Object value) { 80 properties.put(property, value); 81 } 82 83 86 public boolean equals(Object obj) { 87 if (obj instanceof TeamStateDescription) { 88 TeamStateDescription dsd = (TeamStateDescription) obj; 89 if (dsd.getStateFlags() == state) { 90 if (haveSameProperties(this, dsd)) { 91 String [] properties = getPropertyNames(); 92 for (int i = 0; i < properties.length; i++) { 93 String property = properties[i]; 94 Object o1 = this.getProperty(property); 95 Object o2 = dsd.getProperty(property); 96 if (!o1.equals(o2)) { 97 return false; 98 } 99 } 100 return true; 101 } 102 } 103 return false; 104 } 105 return super.equals(obj); 106 } 107 108 private boolean haveSameProperties(TeamStateDescription d1, TeamStateDescription d2) { 109 String [] p1 = d1.getPropertyNames(); 110 String [] p2 = d2.getPropertyNames(); 111 if (p1.length != p2.length) { 112 return false; 113 } 114 for (int i = 0; i < p1.length; i++) { 115 String s1 = p1[i]; 116 boolean found = false; 117 for (int j = 0; j < p2.length; j++) { 118 String s2 = p2[j]; 119 if (s1.equals(s2)) { 120 found = true; 121 break; 122 } 123 } 124 if (!found) 125 return false; 126 } 127 return true; 128 } 129 130 } 131 | Popular Tags |