集册 Java实例教程 将映射转换为IKeyValuePair对象的列表。

将映射转换为IKeyValuePair对象的列表。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

541
将映射转换为IKeyValuePair对象的列表。

/*******************************************************************************

 * Copyright (c) 2008, 2010 Xuggle Inc.  All rights reserved.

 *  

 * This file is part of Xuggle-Utils.

 *

 * Xuggle-Utils 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 3 of the License, or

 * (at your option) any later version.

 *

 * Xuggle-Utils 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 Xuggle-Utils.  If not, see <http://www.gnu.org/licenses/>.

 *******************************************************************************/

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;/* from N o  w  J a v a . c o m - 时  代  Java*/

import java.util.Map;

import java.util.Set;

import java.util.Map.Entry;


public class Main{

    /**

     * Converts a map into a {@link List} of {@link IKeyValuePair} objects.

     * @param map Map to convert.

     * @param listToFill List to fill.  The list has {@link List#clear()} called

     *   before any items are added.

     */

    public static void mapToList(final Map<String, String> map,

            final List<IKeyValuePair> listToFill) {

        if (map == null || listToFill == null)

            throw new IllegalArgumentException();

        final Set<Entry<String, String>> entries = map.entrySet();

        for (Entry<String, String> entry : entries) {

            final String name = entry.getKey();

            final String value = entry.getValue();

            if (name == null)

                continue;/** NowJava.com - 时代Java 提 供 **/

            IKeyValuePair pair = new KeyValuePair(name, value);

            listToFill.add(pair);

        }

    }

    
展开阅读全文