1 11 package org.eclipse.ltk.core.refactoring; 12 13 import java.util.ArrayList ; 14 import java.util.Collections ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Set ; 19 20 import org.eclipse.core.runtime.Assert; 21 22 32 public class GroupCategorySet { 33 34 38 public static final GroupCategorySet NONE= new GroupCategorySet() { 39 public boolean contains(GroupCategory category) { 40 return false; 41 } 42 public List asList() { 43 return Collections.EMPTY_LIST; 44 } 45 }; 46 47 56 public static GroupCategorySet union(GroupCategorySet one, GroupCategorySet two) { 57 Assert.isNotNull(one); 58 Assert.isNotNull(two); 59 if (one == two) 63 return one; 64 if (one == NONE) 65 return two; 66 if (two == NONE) 67 return one; 68 69 Set combined= new HashSet (); 70 combined.addAll(one.asList()); 71 combined.addAll(two.asList()); 72 return new GroupCategorySet(combined); 73 } 74 75 private List fContent; 76 77 private GroupCategorySet() { 78 fContent= Collections.EMPTY_LIST; 79 } 80 81 private GroupCategorySet(Set categories) { 82 fContent= new ArrayList (categories); 83 } 84 85 91 public GroupCategorySet(GroupCategory category) { 92 Assert.isNotNull(category); 93 fContent= new ArrayList (1); 94 fContent.add(category); 95 } 96 97 103 public GroupCategorySet(GroupCategory[] categories) { 104 Assert.isNotNull(categories); 105 fContent= new ArrayList (categories.length); 106 for (int i= 0; i < categories.length; i++) { 107 if (!fContent.contains(categories[i])) 108 fContent.add(categories[i]); 109 } 110 } 111 112 121 public boolean contains(GroupCategory category) { 122 return fContent.contains(category); 123 } 124 125 134 public boolean containsOneCategory(List categories) { 135 for (Iterator iter= categories.iterator(); iter.hasNext();) { 136 GroupCategory category= (GroupCategory)iter.next(); 137 if(contains(category)) 138 return true; 139 } 140 return false; 141 } 142 143 150 public List asList() { 151 return Collections.unmodifiableList(fContent); 152 } 153 } 154 | Popular Tags |