1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.strategy.impl.propertysuppression;
18
19 import org.apache.commons.betwixt.strategy.PropertySuppressionStrategy;
20
21
22
23
24
25
26
27
28 public class PackageSuppressor extends PropertySuppressionStrategy {
29
30
31 private final String suppressedPackage;
32 private final boolean exact;
33
34
35
36
37
38
39 public PackageSuppressor(String suppressedPackage) {
40 if (suppressedPackage.endsWith(".*")) {
41 exact = false;
42 suppressedPackage = suppressedPackage.substring(0, suppressedPackage.length()-2);
43 }
44 else
45 {
46 exact =true;
47 }
48 this.suppressedPackage = suppressedPackage;
49 }
50
51 public boolean suppressProperty(Class classContainingTheProperty, Class propertyType, String propertyName) {
52 boolean result = false;
53 if (propertyType != null) {
54 Package propertyTypePackage = propertyType.getPackage();
55 if (propertyTypePackage != null) {
56 String packageName = propertyTypePackage.getName();
57 if (exact) {
58 result = suppressedPackage.equals(packageName);
59 }
60 else if (packageName != null)
61 {
62 result = packageName.startsWith(suppressedPackage);
63 }
64 }
65 }
66 return result;
67 }
68
69 public String toString() {
70 StringBuffer buffer = new StringBuffer("Suppressing package " );
71 buffer.append(suppressedPackage);
72 if (exact) {
73 buffer.append("(exact)");
74 }
75 return buffer.toString();
76 }
77 }