1 24 25 package org.aspectj.util; 26 27 28 import java.util.*; 29 30 public class InvertableSet { 31 private boolean inverse; 32 private Set set; 33 34 public InvertableSet(Set set, boolean inverse) { 35 this.set = set; 36 this.inverse = inverse; 37 } 38 39 public InvertableSet(Set set) { 40 this.set = set; 41 this.inverse = false; 42 } 43 44 public InvertableSet() { 45 this.set = new HashSet(); 46 this.inverse = false; 47 } 48 49 public Set getSet() { return set; } 50 public boolean isInverse() { return inverse; } 51 52 53 public void addAll(InvertableSet other) { 54 InvertableSet s = union(other); 55 this.set = s.set; 56 this.inverse = s.inverse; 57 } 58 59 public boolean contains(Object obj) { 60 if (inverse) return !set.contains(obj); 61 else return set.contains(obj); 62 } 63 64 public boolean containsAny(Collection c) { 65 for (Iterator i = c.iterator(); i.hasNext(); ) { 66 if (contains(i.next())) return true; 67 } 68 return false; 69 } 70 71 public InvertableSet intersect(InvertableSet s2) { 72 InvertableSet s1 = this; 73 74 if (!s1.inverse && !s2.inverse) { 77 s1.set.retainAll(s2.set); 78 return s1; 79 } 80 if (s1.inverse && s2.inverse) { 82 s1.set.addAll(s2.set); 83 return s1; 84 } 85 if (s1.inverse) { 86 s1 = s2; 87 s2 = this; 88 } 89 s1.set.removeAll(s2.set); 91 return s1; 92 } 93 94 public InvertableSet invert() { 95 inverse = !inverse; 96 return this; 97 } 98 99 public InvertableSet union(InvertableSet s2) { 100 InvertableSet s0 = this.invert().intersect(s2.invert()); 102 return s0.invert(); 103 } 104 } 105 | Popular Tags |