Example usage for com.google.common.collect MapConstraints constrainedMap

List of usage examples for com.google.common.collect MapConstraints constrainedMap

Introduction

In this page you can find the example usage for com.google.common.collect MapConstraints constrainedMap.

Prototype

public static <K, V> Map<K, V> constrainedMap(Map<K, V> map, MapConstraint<? super K, ? super V> constraint) 

Source Link

Document

Returns a constrained view of the specified map, using the specified constraint.

Usage

From source file:org.brocalc.domain.RangeConstraintMapUtil.java

public static <T extends Comparable<?>> Map<Range<T>, BrokerageScheduleComponent> createRangeConstrainedMap(
        final String rangeName) {
    final Map<Range<T>, BrokerageScheduleComponent> baseMap = Maps.newHashMap();
    Map<Range<T>, BrokerageScheduleComponent> constrainedMap = MapConstraints.constrainedMap(baseMap,
            new MapConstraint<Range<T>, BrokerageScheduleComponent>() {

                @Override/*from  w  ww.ja va 2 s  .c  o m*/
                public void checkKeyValue(Range<T> newKey,
                        BrokerageScheduleComponent brokerageScheduleComponent) {
                    baseMap.keySet();
                    for (Range<T> existingKey : baseMap.keySet()) {
                        if (existingKey.isConnected(newKey) && !existingKey.intersection(newKey).isEmpty()) {
                            throw new RangeOverlapException(
                                    rangeName + " " + newKey + " overlaps with " + existingKey);
                        }
                    }
                }
            });
    return constrainedMap;
}

From source file:com.google.gxp.compiler.schema.FileBackedSchemaFactory.java

private static <K, V> Map<K, V> createMap() {
    Map<K, V> map = Maps.newHashMap();
    return MapConstraints.constrainedMap(map, MapConstraints.notNull());
}

From source file:org.jasig.portal.url.AbstractUrlBuilder.java

public AbstractUrlBuilder() {
    this.parameters = MapConstraints.constrainedMap(new ParameterMap(), new MapConstraint<String, String[]>() {
        @Override// ww w  .  j a  v a 2  s  .  c o m
        public void checkKeyValue(String key, String[] value) {
            Validate.notNull(key, "name can not be null");
            Validate.noNullElements(value, "values can not be null or contain null elements");
        }
    });
}

From source file:org.apereo.portal.url.PortletUrlBuilder.java

public PortletUrlBuilder(IPortletWindowId portletWindowId, IPortalUrlBuilder portalUrlBuilder) {
    Preconditions.checkNotNull(portletWindowId, "IPortletWindowId can not be null");
    Preconditions.checkNotNull(portalUrlBuilder, "IPortalUrlBuilder can not be null");

    this.portletWindowId = portletWindowId;
    this.portalUrlBuilder = portalUrlBuilder;
    this.urlType = this.portalUrlBuilder.getUrlType();

    this.publicRenderParameters = MapConstraints.constrainedMap(new ParameterMap(),
            new MapConstraint<String, String[]>() {
                @Override/*from  ww  w .ja  v a  2  s. c o  m*/
                public void checkKeyValue(String key, String[] value) {
                    Validate.notNull(key, "name can not be null");
                    Validate.noNullElements(value, "values can not be null or contain null elements");
                }
            });
}

From source file:net.shibboleth.idp.attribute.filter.context.AttributeFilterWorkContext.java

/** Constructor. */
public AttributeFilterWorkContext() {
    permittedValues = MapConstraints.constrainedMap(new HashMap<String, Set<IdPAttributeValue>>(),
            MapConstraints.notNull());//from   ww  w . j a v  a  2s  . c o  m
    deniedValues = MapConstraints.constrainedMap(new HashMap<String, Set<IdPAttributeValue>>(),
            MapConstraints.notNull());
}

From source file:net.shibboleth.idp.attribute.resolver.context.AttributeResolverWorkContext.java

/** Constructor. */
public AttributeResolverWorkContext() {
    resolvedAttributeDefinitions = MapConstraints
            .constrainedMap(new HashMap<String, ResolvedAttributeDefinition>(), MapConstraints.notNull());

    resolvedDataConnectors = MapConstraints.constrainedMap(new HashMap<String, ResolvedDataConnector>(),
            MapConstraints.notNull());//w  w  w.  jav a 2s .c  o m
}

From source file:net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext.java

/** Constructor. */
public AttributeResolutionContext() {
    requestedAttributeNames = Collections.emptySet();
    resolvedAttributes = MapConstraints.constrainedMap(new HashMap<String, IdPAttribute>(),
            MapConstraints.notNull());/*  w w w  .java 2 s.  co m*/
}

From source file:net.shibboleth.idp.attribute.filter.context.AttributeFilterContext.java

/** Constructor. */
public AttributeFilterContext() {
    prefilteredAttributes = MapConstraints.constrainedMap(new HashMap<String, IdPAttribute>(),
            MapConstraints.notNull());//from www .  j  a v  a  2 s  . c  o  m
    filteredAttributes = MapConstraints.constrainedMap(new HashMap<String, IdPAttribute>(),
            MapConstraints.notNull());
}

From source file:net.shibboleth.idp.attribute.filter.context.AttributeFilterContext.java

/**
 * Sets the attributes which are to be filtered.
 * /*from ww w .  j  a v  a  2 s .  c o  m*/
 * @param attributes attributes which are to be filtered
 */
public void setPrefilteredIdPAttributes(@Nullable @NullableElements final Collection<IdPAttribute> attributes) {
    Collection<IdPAttribute> checkedAttributes = new ArrayList<>();
    CollectionSupport.addIf(checkedAttributes, attributes, Predicates.notNull());

    prefilteredAttributes = MapConstraints.constrainedMap(
            new HashMap<String, IdPAttribute>(checkedAttributes.size()), MapConstraints.notNull());

    for (final IdPAttribute attribute : checkedAttributes) {
        prefilteredAttributes.put(attribute.getId(), attribute);
    }
}

From source file:net.shibboleth.idp.attribute.filter.context.AttributeFilterContext.java

/**
 * Sets the attributes that have been filtered.
 * //from ww  w  .  jav a2  s .c o  m
 * @param attributes attributes that have been filtered
 */
public void setFilteredIdPAttributes(@Nullable @NullableElements final Collection<IdPAttribute> attributes) {
    Collection<IdPAttribute> checkedAttributes = new ArrayList<>();
    CollectionSupport.addIf(checkedAttributes, attributes, Predicates.notNull());

    filteredAttributes = MapConstraints.constrainedMap(
            new HashMap<String, IdPAttribute>(checkedAttributes.size()), MapConstraints.notNull());

    for (final IdPAttribute attribute : checkedAttributes) {
        filteredAttributes.put(attribute.getId(), attribute);
    }
}