Here you can find the source of addToMapIfNotNull(Map
Parameter | Description |
---|---|
map | the map to add the entry under |
key | the key to add to the map |
value | the value to add to the map |
public static final <K, V> void addToMapIfNotNull(Map<K, V> map, K key, V value)
//package com.java2s; /*/* www .ja v a 2 s.c o m*/ * EmailService - RESTful service that sends emails * Copyright (C) 2014 Terry Yiu * * This program 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 * (at your option) any later version. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Map; public class Main { /** * Adds a value V into a map under key K only if the value is not null. * * @param map * the map to add the entry under * @param key * the key to add to the map * @param value * the value to add to the map */ public static final <K, V> void addToMapIfNotNull(Map<K, V> map, K key, V value) { if (value == null) { return; } map.put(key, value); } }