1 16 17 package org.springframework.aop.support; 18 19 import java.io.Serializable ; 20 21 import org.springframework.aop.ClassFilter; 22 import org.springframework.util.Assert; 23 import org.springframework.util.ObjectUtils; 24 25 36 public abstract class ClassFilters { 37 38 45 public static ClassFilter union(ClassFilter cf1, ClassFilter cf2) { 46 Assert.notNull(cf1, "First ClassFilter must not be null"); 47 Assert.notNull(cf2, "Second ClassFilter must not be null"); 48 return new UnionClassFilter(new ClassFilter[] {cf1, cf2}); 49 } 50 51 57 public static ClassFilter union(ClassFilter[] classFilters) { 58 Assert.notEmpty(classFilters, "ClassFilter array must not be empty"); 59 return new UnionClassFilter(classFilters); 60 } 61 62 69 public static ClassFilter intersection(ClassFilter cf1, ClassFilter cf2) { 70 Assert.notNull(cf1, "First ClassFilter must not be null"); 71 Assert.notNull(cf2, "Second ClassFilter must not be null"); 72 return new IntersectionClassFilter(new ClassFilter[] {cf1, cf2}); 73 } 74 75 81 public static ClassFilter intersection(ClassFilter[] classFilters) { 82 Assert.notEmpty(classFilters, "ClassFilter array must not be empty"); 83 return new IntersectionClassFilter(classFilters); 84 } 85 86 87 90 private static class UnionClassFilter implements ClassFilter, Serializable { 91 92 private ClassFilter[] filters; 93 94 public UnionClassFilter(ClassFilter[] filters) { 95 this.filters = filters; 96 } 97 98 public boolean matches(Class clazz) { 99 for (int i = 0; i < this.filters.length; i++) { 100 if (this.filters[i].matches(clazz)) { 101 return true; 102 } 103 } 104 return false; 105 } 106 107 public boolean equals(Object other) { 108 return (this == other || (other instanceof UnionClassFilter && 109 ObjectUtils.nullSafeEquals(this.filters, ((UnionClassFilter) other).filters))); 110 } 111 112 public int hashCode() { 113 return ObjectUtils.nullSafeHashCode(this.filters); 114 } 115 } 116 117 118 121 private static class IntersectionClassFilter implements ClassFilter, Serializable { 122 123 private ClassFilter[] filters; 124 125 public IntersectionClassFilter(ClassFilter[] filters) { 126 this.filters = filters; 127 } 128 129 public boolean matches(Class clazz) { 130 for (int i = 0; i < this.filters.length; i++) { 131 if (!this.filters[i].matches(clazz)) { 132 return false; 133 } 134 } 135 return true; 136 } 137 138 public boolean equals(Object other) { 139 return (this == other || (other instanceof IntersectionClassFilter && 140 ObjectUtils.nullSafeEquals(this.filters, ((IntersectionClassFilter) other).filters))); 141 } 142 143 public int hashCode() { 144 return ObjectUtils.nullSafeHashCode(this.filters); 145 } 146 } 147 148 } 149 | Popular Tags |