1 17 18 package org.apache.lenya.ac.impl; 19 20 import java.util.Arrays ; 21 import java.util.HashSet ; 22 import java.util.Set ; 23 24 import org.apache.lenya.ac.Accreditable; 25 import org.apache.lenya.ac.Group; 26 import org.apache.lenya.ac.Groupable; 27 28 32 public abstract class AbstractGroupable extends AbstractItem implements Groupable, Accreditable { 33 private Set groups = new HashSet (); 34 35 38 public void addedToGroup(Group group) { 39 assert group != null; 40 assert group.contains(this); 41 groups.add(group); 42 } 43 44 47 public void removedFromGroup(Group group) { 48 assert group != null; 49 assert !group.contains(this); 50 groups.remove(group); 51 } 52 53 56 public Group[] getGroups() { 57 return (Group[]) groups.toArray(new Group[groups.size()]); 58 } 59 60 63 public void removeFromAllGroups() { 64 Group[] groups = getGroups(); 65 66 for (int i = 0; i < groups.length; i++) { 67 groups[i].remove(this); 68 } 69 } 70 71 74 public Accreditable[] getAccreditables() { 75 Set accreditables = new HashSet (); 76 accreditables.add(this); 77 78 Group[] groups = getGroups(); 79 80 for (int i = 0; i < groups.length; i++) { 81 Accreditable[] groupAccreditables = groups[i].getAccreditables(); 82 accreditables.addAll(Arrays.asList(groupAccreditables)); 83 } 84 85 return (Accreditable[]) accreditables.toArray(new Accreditable[accreditables.size()]); 86 } 87 88 } | Popular Tags |