Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Pablo Pavon-Marino.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * Contributors:
 *     Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1
 *     Pablo Pavon-Marino - from version 0.4.0 onwards
 ******************************************************************************/

import java.util.*;

public class Main {
    /**
     * Returns a list of the values of the selected elements from an input map. 
     * It is not backed in the input map, thus changes in this list are not 
     * reflected in the input map.
     *
     * @param <A> Key type
     * @param <B> Value type
     * @param map Input map
     * @param keys Keys of the elements to be selected
     * @return List of the values associated to the input indexes (in iteration order)
     */
    public static <A, B> List<B> select(Map<A, B> map, Collection<A> keys) {
        List<B> out = new LinkedList<B>();
        for (A key : keys)
            if (map.containsKey(key))
                out.add(map.get(key));

        return out;
    }
}