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

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

Introduction

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

Prototype

public static <K, V> BiMap<K, V> constrainedBiMap(BiMap<K, V> map,
        MapConstraint<? super K, ? super V> constraint) 

Source Link

Document

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

Usage

From source file:org.sonatype.plugin.nexus.testenvironment.AbstractEnvironmentMojo.java

@SuppressWarnings("unchecked")
private void validateStaticPorts() throws MojoExecutionException, MojoFailureException {
    if (this.staticPorts != null) {
        try {/*w  w  w.j  a  v a 2s .co  m*/
            @SuppressWarnings("rawtypes")
            BiMap staticPortMap = HashBiMap.create(this.staticPorts.size());
            staticPortMap = MapConstraints.constrainedBiMap(staticPortMap, MapConstraints.notNull());
            staticPortMap.putAll(this.staticPorts);
            this.staticPorts = staticPortMap;
        } catch (NullPointerException npe) {
            throw new MojoExecutionException("Port names and values must not be null.", npe);
        } catch (IllegalArgumentException iae) {
            throw new MojoExecutionException("Port names and values must not be duplicated.", iae);
        }
    }
}