Deletes the specified relation. @param relation the relation to be deleted. @return true if the given relation was deleted, or false if it was not found.
(Relation relation)
| 323 | * <code>false</code> if it was not found. |
| 324 | */ |
| 325 | public boolean deleteRelation(Relation relation) { |
| 326 | |
| 327 | // don't do anything if this relation isn't part of this set |
| 328 | if(!indexById.containsValue(relation)) return false; |
| 329 | |
| 330 | // find all relations which include the annotation and remove them |
| 331 | for(Relation r : getReferencing(relation.getId())) { |
| 332 | deleteRelation(r); |
| 333 | } |
| 334 | |
| 335 | // delete this relation from the type index |
| 336 | indexByType.get(relation.getType()).clear(relation.getId()); |
| 337 | |
| 338 | // delete this relation from the ID index |
| 339 | indexById.remove(relation.getId()); |
| 340 | |
| 341 | // delete from the member index |
| 342 | for(int memeberPos = 0; memeberPos < relation.getMembers().length; memeberPos++) { |
| 343 | int member = relation.getMembers()[memeberPos]; |
| 344 | |
| 345 | Map<Integer, BitSet> indexByMember = indexesByMember.get(memeberPos); |
| 346 | BitSet sameMember = indexByMember.get(member); |
| 347 | sameMember.clear(relation.getId()); |
| 348 | } |
| 349 | |
| 350 | // notify anyone who cares enough to listen that we have deleted a |
| 351 | // relation |
| 352 | fireRelationRemoved(new RelationSetEvent(this, |
| 353 | RelationSetEvent.RELATION_REMOVED, relation)); |
| 354 | return true; |
| 355 | |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Returns a collection of all {@link Relation} instances within this |
no test coverage detected