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

org.opentripplanner.util.MapUtils Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.util;

import gnu.trove.map.TLongObjectMap;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class MapUtils {

  public static  void addToMapSet(TLongObjectMap> mapSet, long key, U value) {
    Set set = mapSet.get(key);
    if (set == null) {
      set = new HashSet<>();
      mapSet.put(key, set);
    }
    set.add(value);
  }

  /**
   * Map a collection of objects of type S to a list of type T using the provided
   * mapping function.
   * 

* Nullsafe: if entities is null, then null is returned. */ public static List mapToList(Collection entities, Function mapper) { return entities == null ? null : entities.stream().map(mapper).collect(Collectors.toList()); } }