All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.disy.commons.collections15.util.MultiMapUtils Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/**
 * Legato is a configurable, lightweight web mapping client that can be
 * easily embedded into web pages and portals, CMS and individual web
 * applications. Legato is implemented in JavaScript and based on the
 * popular open source library OpenLayers.
 *
 * Copyright (C) 2010  disy Informationssysteme GmbH, http://www.disy.net
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package net.disy.commons.collections15.util;

import java.util.Collection;

import org.apache.commons.collections15.MultiMap;
import org.apache.commons.lang.Validate;

/**
 * Utilities for {@link MultiMap}
 */
public class MultiMapUtils {

  /**
   * Returns the first value for the given key from the given map.
   *
   * @param 
   *            Type of the key.
   * @param 
   *            Type of the value.
   * @param map
   *            map, must not be null.
   * @param key
   *            key.
   * @return If given map contains values for the given key, returns the first
   *         one from these values, otherwise returns null
   *
   */
  public static  V get(MultiMap map, K key) {
    Validate.notNull(map, "Map parameter must not be null."); //$NON-NLS-1$

    final Collection collection = map.get(key);

    if (collection == null || collection.isEmpty()) {
      return null;
    }
    return collection.iterator().next();

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy