17
17
package org .springframework .beans .factory .support ;
18
18
19
19
import java .lang .reflect .Method ;
20
- import java .util .Collections ;
21
- import java .util .LinkedHashSet ;
22
20
import java .util .Set ;
21
+ import java .util .concurrent .CopyOnWriteArraySet ;
23
22
24
23
/**
25
24
* Set of method overrides, determining which, if any, methods on a
35
34
*/
36
35
public class MethodOverrides {
37
36
38
- private final Set <MethodOverride > overrides =
39
- Collections .synchronizedSet (new LinkedHashSet <MethodOverride >(0 ));
40
-
41
- private volatile boolean modified = false ;
37
+ private final Set <MethodOverride > overrides = new CopyOnWriteArraySet <MethodOverride >();
42
38
43
39
44
40
/**
@@ -60,7 +56,6 @@ public MethodOverrides(MethodOverrides other) {
60
56
*/
61
57
public void addOverrides (MethodOverrides other ) {
62
58
if (other != null ) {
63
- this .modified = true ;
64
59
this .overrides .addAll (other .overrides );
65
60
}
66
61
}
@@ -69,25 +64,23 @@ public void addOverrides(MethodOverrides other) {
69
64
* Add the given method override.
70
65
*/
71
66
public void addOverride (MethodOverride override ) {
72
- this .modified = true ;
73
67
this .overrides .add (override );
74
68
}
75
69
76
70
/**
77
71
* Return all method overrides contained by this object.
78
- * @return Set of MethodOverride objects
72
+ * @return a Set of MethodOverride objects
79
73
* @see MethodOverride
80
74
*/
81
75
public Set <MethodOverride > getOverrides () {
82
- this .modified = true ;
83
76
return this .overrides ;
84
77
}
85
78
86
79
/**
87
80
* Return whether the set of method overrides is empty.
88
81
*/
89
82
public boolean isEmpty () {
90
- return (! this .modified || this . overrides .isEmpty () );
83
+ return this .overrides .isEmpty ();
91
84
}
92
85
93
86
/**
@@ -96,18 +89,13 @@ public boolean isEmpty() {
96
89
* @return the method override, or {@code null} if none
97
90
*/
98
91
public MethodOverride getOverride (Method method ) {
99
- if (!this .modified ) {
100
- return null ;
101
- }
102
- synchronized (this .overrides ) {
103
- MethodOverride match = null ;
104
- for (MethodOverride candidate : this .overrides ) {
105
- if (candidate .matches (method )) {
106
- match = candidate ;
107
- }
92
+ MethodOverride match = null ;
93
+ for (MethodOverride candidate : this .overrides ) {
94
+ if (candidate .matches (method )) {
95
+ match = candidate ;
108
96
}
109
- return match ;
110
97
}
98
+ return match ;
111
99
}
112
100
113
101
0 commit comments