|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -17,6 +17,7 @@ |
|
|
|
|
package org.springframework.beans.factory.support; |
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.LinkedHashSet; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
@ -34,7 +35,10 @@ import java.util.Set; |
|
|
|
|
*/ |
|
|
|
|
public class MethodOverrides { |
|
|
|
|
|
|
|
|
|
private final Set<MethodOverride> overrides = new LinkedHashSet<MethodOverride>(0); |
|
|
|
|
private final Set<MethodOverride> overrides = |
|
|
|
|
Collections.synchronizedSet(new LinkedHashSet<MethodOverride>(0)); |
|
|
|
|
|
|
|
|
|
private volatile boolean modified = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -56,7 +60,8 @@ public class MethodOverrides { |
|
|
|
|
*/ |
|
|
|
|
public void addOverrides(MethodOverrides other) { |
|
|
|
|
if (other != null) { |
|
|
|
|
this.overrides.addAll(other.getOverrides()); |
|
|
|
|
this.modified = true; |
|
|
|
|
this.overrides.addAll(other.overrides); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -64,6 +69,7 @@ public class MethodOverrides { |
|
|
|
|
* Add the given method override. |
|
|
|
|
*/ |
|
|
|
|
public void addOverride(MethodOverride override) { |
|
|
|
|
this.modified = true; |
|
|
|
|
this.overrides.add(override); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -73,6 +79,7 @@ public class MethodOverrides { |
|
|
|
|
* @see MethodOverride |
|
|
|
|
*/ |
|
|
|
|
public Set<MethodOverride> getOverrides() { |
|
|
|
|
this.modified = true; |
|
|
|
|
return this.overrides; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -80,7 +87,7 @@ public class MethodOverrides { |
|
|
|
|
* Return whether the set of method overrides is empty. |
|
|
|
|
*/ |
|
|
|
|
public boolean isEmpty() { |
|
|
|
|
return this.overrides.isEmpty(); |
|
|
|
|
return (!this.modified || this.overrides.isEmpty()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -89,13 +96,18 @@ public class MethodOverrides { |
|
|
|
|
* @return the method override, or {@code null} if none |
|
|
|
|
*/ |
|
|
|
|
public MethodOverride getOverride(Method method) { |
|
|
|
|
MethodOverride match = null; |
|
|
|
|
for (MethodOverride candidate : this.overrides) { |
|
|
|
|
if (candidate.matches(method)) { |
|
|
|
|
match = candidate; |
|
|
|
|
if (!this.modified) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
synchronized (this.overrides) { |
|
|
|
|
MethodOverride match = null; |
|
|
|
|
for (MethodOverride candidate : this.overrides) { |
|
|
|
|
if (candidate.matches(method)) { |
|
|
|
|
match = candidate; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return match; |
|
|
|
|
} |
|
|
|
|
return match; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|