1 /* 2 MapUtils.java 3 Creation date : 29/06/2011 4 Copyright © Benjamin Croizet (graffity2199@yahoo.fr) 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 or GNU Lesser General Public License as published by the 9 Free Software Foundation; either version 3 of the License, 10 or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received copies of the GNU General Public License 18 and GNU Lesser General Public License along with this program; 19 if not, write to the Free Software Foundation, Inc., 20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 http://www.fsf.org/licensing/licenses/gpl.html 22 http://www.gnu.org/licenses/lgpl.html 23 */ 24 25 package net.sourceforge.plantumldependency.common.utils.map; 26 27 import static java.util.logging.Level.FINE; 28 import static java.util.logging.Logger.getLogger; 29 import static net.sourceforge.plantumldependency.common.constants.log.FineConstants.IGNORING_MAP_KEY_FINE; 30 import static net.sourceforge.plantumldependency.common.constants.log.FineConstants.IGNORING_MAP_VALUE_FINE; 31 import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.isNotEmpty; 32 33 import java.util.Map; 34 import java.util.logging.Logger; 35 36 /** 37 * The class utilities simplifying some {@link Map} tasks. 38 * 39 * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>) 40 * @since 1.3.0 41 * @version 1.3.0 42 */ 43 public abstract class MapUtils { 44 45 /** The class logger. */ 46 private static final transient Logger LOGGER = getLogger(MapUtils.class.getName()); 47 48 /** 49 * Put the key and the value in the {@link Map} only if both of them are not <code>null</code> 50 * and not empty. 51 * 52 * @param map 53 * the {@link Map} to put the {@link String} into, mustn't be <code>null</code>. 54 * @param key 55 * the {@link String} key, can be <code>null</code>. 56 * @param value 57 * the associated {@link String} value, can be <code>null</code>. 58 * @since 1.3.0 59 */ 60 public static void putNonEmptyStringToMap(final Map < String, String > map, final String key, final String value) { 61 if (isNotEmpty(key)) { 62 if (isNotEmpty(value)) { 63 map.put(key, value); 64 } else { 65 LOGGER.log(FINE, IGNORING_MAP_VALUE_FINE); 66 } 67 } else { 68 LOGGER.log(FINE, IGNORING_MAP_KEY_FINE); 69 } 70 } 71 72 /** 73 * Private constructor to prevent from instantiation. 74 * 75 * @since 1.3.0 76 */ 77 private MapUtils() { 78 super(); 79 } 80 }