/*
 * Copyright (C) 2008 TranceCode Software
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library 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 Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 *
 * $Id$
 */
package org.trancecode.collection;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * Utility methods related to {@link Map}.
 * 
 * @author Herve Quiroz
 */
public final class TcMaps
{
    private TcMaps()
    {
        // No instantiation
    }

    public static <K, V> Map<K, V> newSmallWriteOnceMap()
    {
        // TODO
        return Maps.newLinkedHashMap();
    }

    public static <K, V> Map<K, V> merge(final Map<K, V> map1, final Map<? extends K, ? extends V> map2)
    {
        final Map<K, V> map = Maps.newHashMapWithExpectedSize(map1.size() + map2.size());
        map.putAll(map1);
        map.putAll(map2);

        return ImmutableMap.copyOf(map);
    }

    public static <K, V> Map<K, V> copyAndPut(final Map<K, V> map1, final K key, final V value)
    {
        final Map<K, V> map = Maps.newHashMap(map1);
        map.put(key, value);

        return ImmutableMap.copyOf(map);
    }

    public static <K, V> V get(final Map<K, V> map, final K key, final V defaultValue)
    {
        if (map.containsKey(key))
        {
            return map.get(key);
        }

        return defaultValue;
    }
}

@@ -828,16 +828,56 @@
 ction;%0A%0A
+import com.google.common.base.Function;%0A
 import c
@@ -976,16 +976,44 @@
 til.Map;
+%0Aimport java.util.Map.Entry;
 %0A%0A/**%0A *
@@ -2052,11 +2052,419 @@
 e;%0A    %7D
+%0A%0A    public static %3CK, V%3E Map%3CK, V%3E fromEntries(final Iterable%3CEntry%3CK, V%3E%3E entries)%0A    %7B%0A        final Function%3CEntry%3CK, V%3E, K%3E keyFunction = MapFunctions.getKey();%0A        final Function%3CEntry%3CK, V%3E, V%3E valueFunction = MapFunctions.getValue();%0A        final Map%3CK, Entry%3CK, V%3E%3E intermediate = Maps.uniqueIndex(entries, keyFunction);%0A        return Maps.transformValues(intermediate, valueFunction);%0A    %7D
 %0A%7D%0A

Add TcMaps.fromEntries()