Here you can find the source of putAllNewInMap(Map
Parameter | Description |
---|---|
T | a parameter |
S | a parameter |
original | a parameter |
newStuff | a parameter |
public static <T, S> void putAllNewInMap(Map<T, S> original, Map<T, S> newStuff)
//package com.java2s; /**// ww w. j a v a2 s . c om * $Id$ * $URL$ * EntityDataUtils.java - entity-broker - Aug 11, 2008 2:58:03 PM - azeckoski ************************************************************************** * Copyright (c) 2008, 2009 The Sakai Foundation * * Licensed under the Educational Community 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.opensource.org/licenses/ECL-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. */ import java.util.*; import java.util.Map.Entry; public class Main { /** * Puts the values of 2 maps together such that the values from the newStuff map are added to the * original map only if they are not already in the the original * @param <T> * @param <S> * @param original * @param newStuff */ public static <T, S> void putAllNewInMap(Map<T, S> original, Map<T, S> newStuff) { if (original == null) { throw new IllegalArgumentException("original map cannot be null"); } if (newStuff != null) { if (original.isEmpty()) { original.putAll(newStuff); } else { for (Entry<T, S> entry : newStuff.entrySet()) { if (original.containsKey(entry.getKey())) { continue; } original.put(entry.getKey(), entry.getValue()); } } } } }