Example usage for java.util HashMap put

List of usage examples for java.util HashMap put

Introduction

In this page you can find the example usage for java.util HashMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:com.parse.ParseRESTQueryCommand.java

static <T extends ParseObject> Map<String, String> encode(ParseQuery.State<T> state,
        boolean count) {
    ParseEncoder encoder = PointerEncoder.get();
    HashMap<String, String> parameters = new HashMap<>();
    List<String> order = state.order();
    if (!order.isEmpty()) {
        parameters.put("order", ParseTextUtils.join(",", order));
    }/*from w w  w  . ja v a  2s  .c o m*/

    ParseQuery.QueryConstraints conditions = state.constraints();
    if (!conditions.isEmpty()) {
        JSONObject encodedConditions = (JSONObject) encoder.encode(conditions);
        parameters.put("where", encodedConditions.toString());
    }

    // This is nullable since we allow unset selectedKeys as well as no selectedKeys
    Set<String> selectedKeys = state.selectedKeys();
    if (selectedKeys != null) {
        parameters.put("keys", ParseTextUtils.join(",", selectedKeys));
    }

    Set<String> includeds = state.includes();
    if (!includeds.isEmpty()) {
        parameters.put("include", ParseTextUtils.join(",", includeds));
    }

    if (count) {
        parameters.put("count", Integer.toString(1));
    } else {
        int limit = state.limit();
        if (limit >= 0) {
            parameters.put("limit", Integer.toString(limit));
        }

        int skip = state.skip();
        if (skip > 0) {
            parameters.put("skip", Integer.toString(skip));
        }
    }

    Map<String, Object> extraOptions = state.extraOptions();
    for (Map.Entry<String, Object> entry : extraOptions.entrySet()) {
        Object encodedExtraOptions = encoder.encode(entry.getValue());
        parameters.put(entry.getKey(), encodedExtraOptions.toString());
    }

    if (state.isTracingEnabled()) {
        parameters.put("trace", Integer.toString(1));
    }
    return parameters;
}

From source file:com.austin.base.commons.util.StringUtil.java

/**
 * @param map ?Map// w  ww .  j a  va2 s.  c om
 * @param key key
 * @param value 17
 */
public static void addParamterToMap(HashMap map, String key, Object value) {
    log.info("?17" + key + "" + value + "HashMap17");
    map.put(key, value);
    /*if(map.containsKey(key))
    {
       map.remove(key);
    }*/

}

From source file:com.linkedin.pinot.util.TestUtils.java

private static HashMap<String, Double> genMapFromJSONArray(JSONArray array) throws JSONException {
    HashMap<String, Double> map = new HashMap<String, Double>();
    for (int i = 0; i < array.length(); ++i) {
        map.put(array.getJSONObject(i).getJSONArray("group").getString(0),
                array.getJSONObject(i).getDouble("value"));
    }/*  w w w.j a va 2s  .c  o  m*/
    return map;
}

From source file:gov.nasa.jpl.analytics.util.CommonUtil.java

public static HashMap<String, Integer> termFrequency(Iterable<String> terms) {
    HashMap<String, Integer> map = new HashMap();
    for (String term : terms) {
        if (!map.containsKey(term)) {
            map.put(term, 1);
        } else {//from w  w w .  ja v  a 2s  . co m
            map.put(term, map.get(term) + 1);
        }
    }
    return map;
}

From source file:com.github.koraktor.steamcondenser.community.GameAchievement.java

/**
 * Loads the global unlock percentages of all achievements for the given
 * game/* w  w w .  j  av  a  2s  . c  o  m*/
 *
 * @param appId The unique Steam Application ID of the game (e.g.
 *        <code>440</code> for Team Fortress 2). See
 *        http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
 *        all application IDs
 * @return The symbolic achievement names with the corresponding global
 *         unlock percentages
 * @throws WebApiException if a request to Steam's Web API fails
 */
public static Map<String, Double> getGlobalPercentages(int appId) throws WebApiException {
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("gameid", appId);

    try {
        JSONObject data = new JSONObject(
                WebApi.getJSON("ISteamUserStats", "GetGlobalAchievementPercentagesForApp", 2, params));

        HashMap<String, Double> percentages = new HashMap<String, Double>();
        JSONArray achievementsData = data.getJSONObject("achievementpercentages").getJSONArray("achievements");
        for (int i = 0; i < achievementsData.length(); i++) {
            JSONObject achievementData = achievementsData.getJSONObject(i);
            percentages.put(achievementData.getString("name"), achievementData.getDouble("percent"));
        }

        return percentages;
    } catch (JSONException e) {
        throw new WebApiException("Could not parse JSON data.", e);
    }
}

From source file:ca.ualberta.cs.c301f12t01.serverStorage.TaskServerRetrieval.java

/**
 * @return HashMap of all local tasks/*  w  w w . j  a  v  a  2 s . co m*/
 */
public static HashMap<UUID, Task> getLocalTasks() {
    ArrayList<Task> al = getAllTasks();
    HashMap<UUID, Task> own = new HashMap<UUID, Task>();
    for (Task t : al) {
        if (t.isLocal()) {
            own.put(t.getId(), t);
        }
    }
    return own;
}

From source file:com.mengge.MobileCommand.java

private static Map<String, CommandInfo> createCommandRepository() {
    HashMap<String, CommandInfo> result = new HashMap<String, CommandInfo>();
    result.put(RESET, postC("/session/:sessionId/appium/app/reset"));
    result.put(GET_STRINGS, postC("/session/:sessionId/appium/app/strings"));
    result.put(SET_VALUE, postC("/session/:sessionId/appium/element/:id/value"));
    result.put(PULL_FILE, postC("/session/:sessionId/appium/device/pull_file"));
    result.put(PULL_FOLDER, postC("/session/:sessionId/appium/device/pull_folder"));
    result.put(HIDE_KEYBOARD, postC("/session/:sessionId/appium/device/hide_keyboard"));
    result.put(RUN_APP_IN_BACKGROUND, postC("/session/:sessionId/appium/app/background"));
    result.put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform"));
    result.put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform"));
    result.put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed"));
    result.put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app"));
    result.put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app"));
    result.put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch"));
    result.put(CLOSE_APP, postC("/session/:sessionId/appium/app/close"));
    result.put(LOCK, postC("/session/:sessionId/appium/device/lock"));
    result.put(COMPLEX_FIND, postC("/session/:sessionId/appium/app/complex_find"));
    result.put(GET_SETTINGS, getC("/session/:sessionId/appium/settings"));
    result.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings"));
    result.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time"));
    result.put(GET_SESSION, getC("/session/:sessionId/"));
    //iOS//from ww  w .j  a  va  2s  . c o m
    result.put(SHAKE, postC("/session/:sessionId/appium/device/shake"));
    //Android
    result.put(CURRENT_ACTIVITY, getC("/session/:sessionId/appium/device/current_activity"));
    result.put(END_TEST_COVERAGE, postC("/session/:sessionId/appium/app/end_test_coverage"));
    result.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection"));
    result.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked"));
    result.put(LONG_PRESS_KEY_CODE, postC("/session/:sessionId/appium/device/long_press_keycode"));
    result.put(OPEN_NOTIFICATIONS, postC("/session/:sessionId/appium/device/open_notifications"));
    result.put(PRESS_KEY_CODE, postC("/session/:sessionId/appium/device/press_keycode"));
    result.put(PUSH_FILE, postC("/session/:sessionId/appium/device/push_file"));
    result.put(SET_NETWORK_CONNECTION, postC("/session/:sessionId/network_connection"));
    result.put(START_ACTIVITY, postC("/session/:sessionId/appium/device/start_activity"));
    result.put(TOGGLE_LOCATION_SERVICES, postC("/session/:sessionId/appium/device/toggle_location_services"));
    result.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"));
    result.put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value"));
    return result;
}

From source file:com.sonicle.webtop.core.util.NotificationHelper.java

/**
 * Creates strings map (No-Reply version) for notification (simple body) template
 * @param locale//from   w w w .  ja  v  a  2s.  c  o  m
 * @param source
 * @param bodyHeader
 * @param bodyMessage
 * @return 
 */
public static Map<String, String> createNoReplayDefaultBodyTplStrings(Locale locale, String source,
        String bodyHeader, String bodyMessage) {
    HashMap<String, String> map = new HashMap<>();
    map.put("bodyHeader", StringUtils.defaultString(bodyHeader));
    map.put("bodyMessage", StringUtils.defaultString(bodyMessage));
    map.put("footerHeader", MessageFormat.format(
            WT.lookupResource(CoreManifest.ID, locale, CoreLocaleKey.TPL_NOTIFICATION_NOREPLY_FOOTER_HEADER),
            source));
    map.put("footerMessage",
            WT.lookupResource(CoreManifest.ID, locale, CoreLocaleKey.TPL_NOTIFICATION_NOREPLY_FOOTER_MESSAGE));
    return map;
}

From source file:com.sonicle.webtop.core.util.NotificationHelper.java

/**
 * Creates strings map (No-Reply version) for notification (custom body) template
 * @param locale//w w  w.  j ava2s  .  co  m
 * @param source
 * @param bodyHeader
 * @param customBody
 * @return 
 */
public static Map<String, String> createNoReplayCustomBodyTplStrings(Locale locale, String source,
        String bodyHeader, String customBody) {
    HashMap<String, String> map = new HashMap<>();
    map.put("bodyHeader", StringUtils.defaultString(bodyHeader));
    map.put("customBody", StringUtils.defaultString(customBody));
    map.put("footerHeader", MessageFormat.format(
            WT.lookupResource(CoreManifest.ID, locale, CoreLocaleKey.TPL_NOTIFICATION_NOREPLY_FOOTER_HEADER),
            source));
    map.put("footerMessage",
            WT.lookupResource(CoreManifest.ID, locale, CoreLocaleKey.TPL_NOTIFICATION_NOREPLY_FOOTER_MESSAGE));
    return map;
}

From source file:Main.java

public static HashMap<String, Object> testReflect(Object obj)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    HashMap<String, Object> hashMap = new HashMap<String, Object>();
    Class c = obj.getClass();//from  w w w.jav  a2 s.  c  o m
    Method m[] = c.getDeclaredMethods();
    for (int i = 0; i < m.length; i++) {
        if (m[i].getName().indexOf("get") == 0) {
            hashMap.put(m[i].getName(), m[i].invoke(obj, new Object[0]));
        }
    }
    return hashMap;
}