Java Map Copy copyUntilFull(final Map source, final Map dest1, Map overflow, final int dest1Capacity)

Here you can find the source of copyUntilFull(final Map source, final Map dest1, Map overflow, final int dest1Capacity)

Description

Copies the entries from source to dest1 until dest1 has reached size dest1Capacity.

License

Open Source License

Parameter

Parameter Description
T the key type.
U the entry/value type.
source the mappings to be copied.
dest1 the first destination for the entries, to be filled until its size reaches dest1Capacity.
overflow destination for the remaining entries.
dest1Capacity maximum allowed size for dest1.

Declaration

public static <T, U> void copyUntilFull(final Map<? extends T, ? extends U> source,
        final Map<? super T, ? super U> dest1, Map<T, U> overflow, final int dest1Capacity) 

Method Source Code

//package com.java2s;
/*// www  .j  a  v a  2s  .c  o  m
 * Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * PeerfactSim.KOM 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.util.Map;

public class Main {
    /**
     * Copies the entries from <code>source</code> to <code>dest1</code> until
     * <code>dest1</code> has reached size <code>dest1Capacity</code>. The
     * remaining entries are saved in <code>overflow</code>. The order of
     * insertion depends on the iterator of the underlying map. Note that as
     * <code>dest1</code> is a map, inserting an entry with a key that already
     * exists in the map does not increase its size (if the insertion is
     * permitted).
     * 
     * @param <T>
     *            the key type.
     * @param <U>
     *            the entry/value type.
     * @param source
     *            the mappings to be copied.
     * @param dest1
     *            the first destination for the entries, to be filled until its
     *            size reaches dest1Capacity.
     * @param overflow
     *            destination for the remaining entries.
     * @param dest1Capacity
     *            maximum allowed size for dest1.
     */
    public static <T, U> void copyUntilFull(final Map<? extends T, ? extends U> source,
            final Map<? super T, ? super U> dest1, Map<T, U> overflow, final int dest1Capacity) {
        for (final Map.Entry<? extends T, ? extends U> srcEntry : source.entrySet()) {
            if (dest1.size() < dest1Capacity) {
                dest1.put(srcEntry.getKey(), srcEntry.getValue());
            } else {
                overflow.put(srcEntry.getKey(), srcEntry.getValue());
            }
        }
    }
}

Related

  1. copyOptions(Map options)
  2. copyParameters(Map parameters)
  3. copyPropertiesToMap(Properties source, Map target)
  4. copySafelyToObjectToObjectMap(java.util.Map map)
  5. copyStringMap(Map initParams)
  6. copyValue(Map source, Map target, K key)
  7. copyValueIfExist(Map source, K sourceKey, Map target, K targetKey)
  8. copyValueIfExist(Map source, Map target, K key)
  9. deepCopy(Map map)