[java-identity-provider COMMIT] /trunk/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/Att...
noreply at shibboleth.net
noreply at shibboleth.net
Mon Jun 3 16:44:26 EDT 2013
Author: tzeller
Date: Mon Jun 3 16:44:25 2013
New Revision: 4514
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4514&view=rev
Log:
Another way to optimize the size of the underlying guarded maps set via setFilteredAttributes() and setPrefilteredAttributes().
Modified:
trunk/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/AttributeFilterContext.java
Modified: trunk/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/AttributeFilterContext.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/AttributeFilterContext.java?rev=4514&r1=4513&r2=4514&view=diff
==============================================================================
--- trunk/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/AttributeFilterContext.java (original)
+++ trunk/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/AttributeFilterContext.java Mon Jun 3 16:44:25 2013
@@ -17,6 +17,7 @@
package net.shibboleth.idp.attribute.filter;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -34,11 +35,13 @@
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+import net.shibboleth.utilities.java.support.collection.CollectionSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
import org.opensaml.messaging.context.BaseContext;
+import com.google.common.base.Predicates;
import com.google.common.collect.Constraints;
import com.google.common.collect.MapConstraints;
@@ -84,18 +87,16 @@
* @param attributes attributes which are to be filtered
*/
public void setPrefilteredAttributes(@Nullable @NullableElements final Collection<Attribute> attributes) {
- Map<String, Attribute> checkedAttributes =
- MapConstraints.constrainedMap(new HashMap<String, Attribute>(), MapConstraints.notNull());
-
- if (attributes != null) {
- for (Attribute attribute : attributes) {
- if (attribute != null) {
- checkedAttributes.put(attribute.getId(), attribute);
- }
- }
- }
-
- prefilteredAttributes = checkedAttributes;
+ Collection<Attribute> checkedAttributes = new ArrayList<Attribute>();
+ CollectionSupport.addIf(checkedAttributes, attributes, Predicates.notNull());
+
+ prefilteredAttributes =
+ MapConstraints.constrainedMap(new HashMap<String, Attribute>(checkedAttributes.size()),
+ MapConstraints.notNull());
+
+ for (Attribute attribute : checkedAttributes) {
+ prefilteredAttributes.put(attribute.getId(), attribute);
+ }
}
/**
@@ -211,23 +212,15 @@
* @param attributes attributes that have been filtered
*/
public void setFilteredAttributes(@Nullable @NullableElements final Collection<Attribute> attributes) {
-
- if (null == attributes) {
- filteredAttributes = Collections.EMPTY_MAP;
- } else {
- final Map<String, Attribute> checkedAttributes =
- MapConstraints.constrainedMap(new HashMap<String, Attribute>(attributes.size()),
- MapConstraints.notNull());
-
- if (attributes != null) {
- for (Attribute attribute : attributes) {
- if (attribute != null) {
- checkedAttributes.put(attribute.getId(), attribute);
- }
- }
- }
-
- filteredAttributes = checkedAttributes;
+ Collection<Attribute> checkedAttributes = new ArrayList<Attribute>();
+ CollectionSupport.addIf(checkedAttributes, attributes, Predicates.notNull());
+
+ filteredAttributes =
+ MapConstraints.constrainedMap(new HashMap<String, Attribute>(checkedAttributes.size()),
+ MapConstraints.notNull());
+
+ for (Attribute attribute : checkedAttributes) {
+ filteredAttributes.put(attribute.getId(), attribute);
}
}
}
More information about the commits
mailing list