- Timestamp:
- 2010-06-27T12:22:37+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r3262 r3347 2 2 3 3 import java.util.ArrayList; 4 import java.util.Arrays; 4 5 import java.util.Collection; 5 6 import java.util.HashSet; … … 18 19 public final class Relation extends OsmPrimitive { 19 20 20 private final List<RelationMember> members = new ArrayList<RelationMember>();21 private RelationMember[] members = new RelationMember[0]; 21 22 22 23 private BBox bbox; … … 28 29 */ 29 30 public List<RelationMember> getMembers() { 30 return new CopyList<RelationMember>(members .toArray(new RelationMember[members.size()]));31 return new CopyList<RelationMember>(members); 31 32 } 32 33 … … 41 42 } 42 43 43 this.members.clear();44 44 if (members != null) { 45 this.members .addAll(members);45 this.members = members.toArray(new RelationMember[members.size()]); 46 46 } 47 47 for (RelationMember rm:this.members) { … … 56 56 */ 57 57 public int getMembersCount() { 58 return members. size();58 return members.length; 59 59 } 60 60 61 61 public RelationMember getMember(int index) { 62 return members .get(index);62 return members[index]; 63 63 } 64 64 65 65 public void addMember(RelationMember member) { 66 members.add(member); 66 RelationMember[] newMembers = new RelationMember[members.length + 1]; 67 System.arraycopy(members, 0, newMembers, 0, members.length); 68 newMembers[members.length] = member; 69 members = newMembers; 67 70 member.getMember().addReferrer(this); 68 71 fireMembersChanged(); … … 70 73 71 74 public void addMember(int index, RelationMember member) { 72 members.add(index, member); 75 RelationMember[] newMembers = new RelationMember[members.length + 1]; 76 System.arraycopy(members, 0, newMembers, 0, index); 77 System.arraycopy(members, index, newMembers, index + 1, members.length - index); 78 newMembers[index] = member; 79 members = newMembers; 73 80 member.getMember().addReferrer(this); 74 81 fireMembersChanged(); … … 82 89 */ 83 90 public RelationMember setMember(int index, RelationMember member) { 84 RelationMember result = members.set(index, member); 85 if (result.getMember() != member.getMember()) { 91 RelationMember originalMember = members[index]; 92 members[index] = member; 93 if (originalMember.getMember() != member.getMember()) { 86 94 member.getMember().addReferrer(this); 87 result.getMember().removeReferrer(this);95 originalMember.getMember().removeReferrer(this); 88 96 fireMembersChanged(); 89 97 } 90 return result;98 return originalMember; 91 99 } 92 100 … … 97 105 */ 98 106 public RelationMember removeMember(int index) { 107 List<RelationMember> members = getMembers(); 99 108 RelationMember result = members.remove(index); 100 for (RelationMember rm:members) { 101 // Do not remove referrer if this primitive is used in relation twice 102 if (rm.getMember() == result.getMember()) 103 return result; 104 } 105 result.getMember().removeReferrer(this); 106 fireMembersChanged(); 109 setMembers(members); 107 110 return result; 108 111 } … … 216 219 return false; 217 220 Relation r = (Relation)other; 218 return members.equals(r.members);221 return Arrays.equals(members, r.members); 219 222 } 220 223 … … 225 228 public RelationMember firstMember() { 226 229 if (isIncomplete()) return null; 227 return (members. size() == 0) ? null : members.get(0);230 return (members.length == 0) ? null : members[0]; 228 231 } 229 232 public RelationMember lastMember() { 230 233 if (isIncomplete()) return null; 231 return (members. size() == 0) ? null : members.get(members.size() -1);234 return (members.length == 0) ? null : members[members.length - 1]; 232 235 } 233 236 … … 241 244 return; 242 245 243 ArrayList<RelationMember> todelete = new ArrayList<RelationMember>();246 List<RelationMember> todelete = new ArrayList<RelationMember>(); 244 247 for (RelationMember member: members) { 245 248 if (member.getMember() == primitive) { … … 247 250 } 248 251 } 249 primitive.removeReferrer(this);252 List<RelationMember> members = getMembers(); 250 253 members.removeAll(todelete); 251 fireMembersChanged();254 setMembers(members); 252 255 } 253 256 … … 279 282 } 280 283 } 284 List<RelationMember> members = getMembers(); 281 285 members.removeAll(todelete); 282 for (OsmPrimitive primitive:primitives) { 283 primitive.removeReferrer(this); 284 } 285 fireMembersChanged(); 286 setMembers(members); 286 287 } 287 288 … … 314 315 @Override 315 316 public BBox getBBox() { 316 if (members. isEmpty())317 if (members.length == 0) 317 318 return new BBox(0, 0, 0, 0); 318 319 if (getDataSet() == null) … … 333 334 return null; 334 335 visitedRelations.add(this); 335 if (members. isEmpty())336 if (members.length == 0) 336 337 return null; 337 338 else {
Note:
See TracChangeset
for help on using the changeset viewer.