OSDN Git Service

Automatic translation import
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / lastfm / MapUtilities.java
1 /*
2  * Copyright (c) 2012, the Last.fm Java Project and Committers All rights
3  * reserved. Redistribution and use of this software in source and binary forms,
4  * with or without modification, are permitted provided that the following
5  * conditions are met: - Redistributions of source code must retain the above
6  * copyright notice, this list of conditions and the following disclaimer. -
7  * Redistributions in binary form must reproduce the above copyright notice,
8  * this list of conditions and the following disclaimer in the documentation
9  * and/or other materials provided with the distribution. THIS SOFTWARE IS
10  * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
11  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
13  * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
14  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
16  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
17  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20  */
21
22 package com.cyngn.eleven.lastfm;
23
24 import java.util.Map;
25
26 /**
27  * Utility class to perform various operations on Maps.
28  * 
29  * @author Adrian Woodhead
30  */
31 public final class MapUtilities {
32
33     private MapUtilities() {
34     }
35
36     /**
37      * Puts the passed key and value into the map only if the value is not null.
38      * 
39      * @param map Map to add key and value to.
40      * @param key Map key.
41      * @param value Map value, if null will not be added to map.
42      */
43     public static void nullSafePut(final Map<String, String> map, final String key,
44             final String value) {
45         if (value != null) {
46             map.put(key, value);
47         }
48     }
49
50     /**
51      * Puts the passed key and value into the map only if the value is not null.
52      * 
53      * @param map Map to add key and value to.
54      * @param key Map key.
55      * @param value Map value, if null will not be added to map.
56      */
57     public static void nullSafePut(final Map<String, String> map, final String key,
58             final Integer value) {
59         if (value != null) {
60             map.put(key, value.toString());
61         }
62     }
63
64     /**
65      * Puts the passed key and value into the map only if the value is not -1.
66      * 
67      * @param map Map to add key and value to.
68      * @param key Map key.
69      * @param value Map value, if -1 will not be added to map.
70      */
71     public static void nullSafePut(final Map<String, String> map, final String key, final int value) {
72         if (value != -1) {
73             map.put(key, Integer.toString(value));
74         }
75     }
76
77     /**
78      * Puts the passed key and value into the map only if the value is not -1.
79      * 
80      * @param map Map to add key and value to.
81      * @param key Map key.
82      * @param value Map value, if -1 will not be added to map.
83      */
84     public static void nullSafePut(final Map<String, String> map, final String key,
85             final double value) {
86         if (value != -1) {
87             map.put(key, Double.toString(value));
88         }
89     }
90 }