/*
 * Copyright (c) 2013-2015 Cinchapi Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cinchapi.concourse.util;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

/**
 * Map based utility methods that are not found in the Guava
 * {@link com.google.collect.Maps} utility class.
 * 
 * @author Jeff Nelson
 */
public final class TMaps {

    /**
     * Return a map that has all the data in {@code map} in naturally sorted
     * order.
     * 
     * @param map
     * @return the sorted map
     */
    public static <K extends Comparable<K>, V> SortedMap<K, V> asSortedMap(
            Map<K, V> map) {
        if(map instanceof SortedMap) {
            return (SortedMap<K, V>) map;
        }
        else {
            return new TreeMap<K, V>(map);
        }
    }

    /**
     * Return a set that contains all of the keys from the {@code entrySet}.
     * 
     * @param entrySet
     * @return the keySet
     */
    public static <K, V> Set<K> extractKeysFromEntrySet(
            Collection<Entry<K, V>> entrySet) {
        Set<K> keys = entrySet instanceof SortedSet ? new TreeSet<K>(
                Comparators.<K> naturalOrArbitrary()) : Sets.<K> newHashSet();
        for (Entry<K, V> entry : entrySet) {
            keys.add(entry.getKey());
        }
        return keys;
    }

    /**
     * Return a collection that contains all of the values from the
     * {@code entrySet}/
     * 
     * @param entrySet
     * @return the values collection
     */
    public static <K, V> Collection<V> extractValuesFromEntrySet(
            Collection<Entry<K, V>> entrySet) {
        List<V> values = Lists.newArrayList();
        for (Entry<K, V> entry : entrySet) {
            values.add(entry.getValue());
        }
        return values;
    }

    /**
     * Return a map that contains all the entries in the {@code entrySet}.
     * 
     * @param entrySet
     * @return the populated map
     */
    public static <K, V> Map<K, V> fromEntrySet(Collection<Entry<K, V>> entrySet) {
        // TODO: Find a better way to do this. Perhaps use reflection to place
        // the entires directly in the map...
        Map<K, V> map = entrySet instanceof SortedSet ? new TreeMap<K, V>(
                Comparators.<K> naturalOrArbitrary()) : Maps
                .<K, V> newHashMap();
        for (Entry<K, V> entry : entrySet) {
            map.put(entry.getKey(), entry.getValue());
        }
        return map;
    }

    private TMaps() {/* noop */}

}

@@ -39,16 +39,17 @@
  Inc.%0A *
+ 
 %0A * Lice
@@ -225,13 +225,12 @@
 t%0A *
+ 
 %0A *
-  
  htt
@@ -271,16 +271,17 @@
 E-2.0%0A *
+ 
 %0A * Unle
@@ -665,16 +665,48 @@
 ection;%0A
+import java.util.LinkedHashMap;%0A
 import j
@@ -3289,24 +3289,652 @@
 map;%0A    %7D%0A%0A
+    /**%0A     * Return %3Cem%3Emutable%3C/em%3E, insertion-ordered %7B@link LinkedHashMap%7D instance%0A     * with enough room to fit %7B@code capacity%7D items.%0A     * %0A     * %3Cp%3E%0A     * Use this method over%0A     * %7B@link com.google.common.collect.Maps#newLinkedHashMap()%7D when the size%0A     * of the map is known in advance and we are being careful to not oversize%0A     * collections.%0A     * %3C/p%3E%0A     * %0A     * @param capacity the initial capacity%0A     * @return a new, empty %7B@link LinkedHashMap%7D%0A     */%0A    public static %3CK, V%3E Map%3CK, V%3E newLinkedHashMapWithCapacity(int capacity) %7B%0A        return new LinkedHashMap%3CK, V%3E(capacity);%0A    %7D%0A%0A
     private 

Add static factory to create LinkedHashMap with specific size