Here you can find the source of putAllNonNullValues(Map source, Map target)
Parameter | Description |
---|---|
source | Map providing the entries |
target | Map getting all entries |
@SuppressWarnings({ "rawtypes", "unchecked" }) public static Set putAllNonNullValues(Map source, Map target)
//package com.java2s; /******************************************************************************* * Copyright 2009, 2010 Innovation Gate GmbH * /* ww w . ja v a 2 s . co m*/ * 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. ******************************************************************************/ import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; public class Main { /** * Puts all entries from map source to map target whose values are non-null. * This can be used to fill ConcurrentHashMaps that do not take null values. * @param source Map providing the entries * @param target Map getting all entries * @return A set of keys that contained null values and therefor were not put to target */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Set putAllNonNullValues(Map source, Map target) { Iterator entries = source.entrySet().iterator(); Set nullKeys = new HashSet(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); if (entry.getValue() != null) { target.put(entry.getKey(), entry.getValue()); } else { nullKeys.add(entry.getKey()); } } return nullKeys; } }