Implement containsProperty on MapPropertySource

Improve the performance of MapPropertySource by directly implementing
the containsProperty property.

Issue: SPR-12224
This commit is contained in:
Phillip Webb 2014-09-18 23:17:13 -07:00
parent 2077388f38
commit e71fbb9f46
1 changed files with 12 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package org.springframework.core.env;
import java.util.Map;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@ -43,4 +44,15 @@ public class MapPropertySource extends EnumerablePropertySource<Map<String, Obje
return StringUtils.toStringArray(this.source.keySet());
}
@Override
public boolean containsProperty(String name) {
Assert.notNull(name, "Property name must not be null");
boolean containsProperty = this.source.containsKey(name);
if (logger.isDebugEnabled()) {
logger.debug(String.format("PropertySource [%s] %s '%s'", getName(),
(containsProperty ? "contains" : "does not contain"), name));
}
return containsProperty;
}
}