Example usage for com.google.common.collect MapConstraint MapConstraint

List of usage examples for com.google.common.collect MapConstraint MapConstraint

Introduction

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

Prototype

MapConstraint

Source Link

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/* w w w . jav a 2s. co  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:org.jasig.portal.url.AbstractUrlBuilder.java

public AbstractUrlBuilder() {
    this.parameters = MapConstraints.constrainedMap(new ParameterMap(), new MapConstraint<String, String[]>() {
        @Override/*w  w  w  .  j  a  v  a2  s  .co 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 w  ww .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");
                }
            });
}