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:org.kitodo.data.index.elasticsearch.RestClientImplementationTest.java

private static HashMap<Integer, HttpEntity> createEntities() {
    HashMap<Integer, HttpEntity> documents = new HashMap<>();

    String jsonString = "{\"title\":\"Batch1\",\"type\":\"LOGISTIC\",\"processes\":[{\"id\":\"1\"},{\"id\":\"2\"}]}";
    HttpEntity entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
    documents.put(1, entity);

    jsonString = "{\"title\":\"Batch2\",\"type\":\"null\",\"processes\":[]}";
    entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON);
    documents.put(2, entity);/*from  w  ww. j  a v  a 2 s. c  o  m*/

    return documents;
}

From source file:com.example.orangeweather.JSONWeatherParser.java

public static HashMap<String, ContentValues> getWeather3(JSONObject jObj) throws JSONException {
    ContentValues cvWeather = new ContentValues();
    ContentValues cvCity = new ContentValues();

    JSONObject coordObj = getObject("coord", jObj);
    cvCity.put(CityTags.CITY_NAME, getString("name", jObj));
    cvCity.put("_id", getInt("id", jObj));
    cvWeather.put("_id", getInt("id", jObj));
    cvWeather.put(WeatherTags.WEATHER_DT, getInt("dt", jObj));
    cvCity.put(CityTags.CITY_COORD, getDMSCoordinates(getFloat("lat", coordObj), getFloat("lon", coordObj)));

    JSONObject sysObj = getObject("sys", jObj);
    cvCity.put(CityTags.CITY_SYS_COUNTRY, getString("country", sysObj));

    if (sysObj.has("sunrise")) {
        cvWeather.put(WeatherTags.WEATHER_SYS_SUNRISE, getInt("sunrise", sysObj));
    }//from www  . j  a va 2s.com
    if (sysObj.has("sunset")) {
        cvWeather.put(WeatherTags.WEATHER_SYS_SUNSET, getInt("sunset", sysObj));
    }

    JSONArray jArr = jObj.getJSONArray("weather");

    JSONObject JSONWeather = jArr.getJSONObject(0);

    cvWeather.put(WeatherTags.WEATHER_CONDITION_DESC, getString("description", JSONWeather));
    cvWeather.put(WeatherTags.WEATHER_CONDITION_MAIN, getString("main", JSONWeather));

    JSONObject mainObj = getObject("main", jObj);
    cvWeather.put(WeatherTags.WEATHER_MAIN_HUMIDITY, getInt("humidity", mainObj));
    cvWeather.put(WeatherTags.WEATHER_MAIN_PRESSURE, getInt("pressure", mainObj));
    cvWeather.put(WeatherTags.WEATHER_MAIN_TEMP_MAX, getTemperatureString(getFloat("temp_max", mainObj)));
    cvWeather.put(WeatherTags.WEATHER_MAIN_TEMP_MIN, getTemperatureString(getFloat("temp_min", mainObj)));
    cvWeather.put(WeatherTags.WEATHER_MAIN_TEMP, getTemperatureString(getFloat("temp", mainObj)));

    JSONObject wObj = getObject("wind", jObj);
    cvWeather.put(WeatherTags.WEATHER_WIND_SPEED, getFloat("speed", wObj));
    cvWeather.put(WeatherTags.WEATHER_WIND_DEG, getInt("deg", wObj));

    if (wObj.has("var_beg")) {
        cvWeather.put(WeatherTags.WEATHER_WIND_VAR_BEG, getInt("var_beg", wObj));
    }
    if (wObj.has("var_end")) {
        cvWeather.put(WeatherTags.WEATHER_WIND_VAR_END, getInt("var_end", wObj));
    }

    JSONObject cObj = getObject("clouds", jObj);
    cvWeather.put(WeatherTags.WEATHER_CLOUDS_ALL, getInt("all", cObj));
    HashMap<String, ContentValues> hm = new HashMap<String, ContentValues>();
    hm.put(CityTags.OBJECT_TAG, cvCity);
    hm.put(WeatherTags.OBJECT_TAG, cvWeather);
    return hm;
}

From source file:com.opengamma.analytics.util.amount.CubeValue.java

/**
 * Create a new object containing the point of the initial object with the all values multiplied by a given factor.
 * @param surfaceValue The surface value.
 * @param factor The multiplicative factor.
 * @return The multiplied surface./*  w w w .  j a  va 2 s.co m*/
 */
public static CubeValue multiplyBy(final CubeValue surfaceValue, final double factor) {
    ArgumentChecker.notNull(surfaceValue, "Surface value");
    final HashMap<Triple<Double, Double, Double>, Double> multiplied = new HashMap<>();
    for (final Triple<Double, Double, Double> p : surfaceValue._data.keySet()) {
        multiplied.put(p, surfaceValue._data.get(p) * factor);
    }
    return new CubeValue(multiplied);
}

From source file:com.opengamma.analytics.util.amount.SurfaceValue.java

/**
 * Create a new object containing the point of the initial object with the all values multiplied by a given factor.
 * @param surfaceValue The surface value.
 * @param factor The multiplicative factor.
 * @return The multiplied surface./*from  ww  w . jav  a 2s .  com*/
 */
public static SurfaceValue multiplyBy(final SurfaceValue surfaceValue, final double factor) {
    ArgumentChecker.notNull(surfaceValue, "Surface value");
    final HashMap<DoublesPair, Double> multiplied = new HashMap<>();
    for (final DoublesPair p : surfaceValue._data.keySet()) {
        multiplied.put(p, surfaceValue._data.get(p) * factor);
    }
    return new SurfaceValue(multiplied);
}

From source file:edu.harvard.mcz.nametools.AuthorNameComparator.java

public static Map<String, Boolean> detectApplicableCode(String authorship, String kingdom, String phylum) {
    HashMap<String, Boolean> result = new HashMap<String, Boolean>();
    result.put("ICZN", false);
    result.put("ICNafp", false);
    boolean done = false;
    if (kingdom == null) {
        kingdom = "";
    }/*from   w w w.  j  a v a 2 s  .  c  om*/
    if (phylum == null) {
        phylum = "";
    }

    if (!done && kingdom.trim().equalsIgnoreCase("Animalia")) {
        result.put("ICZN", true);
        done = true;
    }
    if (!done && kingdom.trim().equalsIgnoreCase("Fungi")) {
        result.put("ICNafp", true);
        done = true;
    }
    if (!done && kingdom.trim().equalsIgnoreCase("Plantae")) {
        result.put("ICNafp", true);
        done = true;
    }

    if (!done && authorship != null) {
        if (authorship.startsWith("(") && authorship.endsWith(")")) {
            // when plant authors contain parenthesies, at least one follows the parenthesies.
            result.put("ICZN", true);
            done = true;
        }
        if (authorship.contains(" ex ") || authorship.contains(":")) {
            // only plant names should contain ex authors or sanctioning authors, designated by these characters.
            result.put("ICNafp", true);
            done = true;
        }
        if (authorship.startsWith("(") && authorship.contains(")") && authorship.matches("[a-zA-Z.]$")
                && authorship.matches(") [A-Z]")) {
            // when plant authors contain parenthesies at least one follows the parenthesis.
            result.put("ICNafp", true);
            done = true;
        }
    }

    return result;
}

From source file:com.example.android.tvleanback2.data.VideoDatabase.java

/**
 * Builds a map for all columns that may be requested, which will be given to the
 * SQLiteQueryBuilder. This is a good way to define aliases for column names, but must include
 * all columns, even if the value is the key. This allows the ContentProvider to request
 * columns w/o the need to know real column names and create the alias itself.
 *//*from w w w . ja  v  a  2  s. co  m*/
private static HashMap<String, String> buildColumnMap() {
    HashMap<String, String> map = new HashMap<>();
    map.put(KEY_NAME, KEY_NAME);
    map.put(KEY_DESCRIPTION, KEY_DESCRIPTION);
    map.put(KEY_ICON, KEY_ICON);
    map.put(KEY_DATA_TYPE, KEY_DATA_TYPE);
    map.put(KEY_IS_LIVE, KEY_IS_LIVE);
    map.put(KEY_VIDEO_WIDTH, KEY_VIDEO_WIDTH);
    map.put(KEY_VIDEO_HEIGHT, KEY_VIDEO_HEIGHT);
    map.put(KEY_AUDIO_CHANNEL_CONFIG, KEY_AUDIO_CHANNEL_CONFIG);
    map.put(KEY_PURCHASE_PRICE, KEY_PURCHASE_PRICE);
    map.put(KEY_RENTAL_PRICE, KEY_RENTAL_PRICE);
    map.put(KEY_RATING_STYLE, KEY_RATING_STYLE);
    map.put(KEY_RATING_SCORE, KEY_RATING_SCORE);
    map.put(KEY_PRODUCTION_YEAR, KEY_PRODUCTION_YEAR);
    map.put(KEY_COLUMN_DURATION, KEY_COLUMN_DURATION);
    map.put(KEY_ACTION, KEY_ACTION);
    map.put(BaseColumns._ID, "rowid AS " + BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID,
            "rowid AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

From source file:com.gst.integrationtests.common.GroupHelper.java

public static String activateGroupAsJSON(final String activationDate) {
    final HashMap<String, String> map = new HashMap<>();
    map.put("dateFormat", "dd MMMM yyyy");
    map.put("locale", "en");
    if (StringUtils.isNotEmpty(activationDate)) {
        map.put("activationDate", activationDate);
    } else {/*from   w w w  .  ja v  a2s.c o  m*/
        map.put("activationDate", "04 March 2011");
        System.out.println("defaulting to fixed date: 04 March 2011");
    }
    System.out.println("map : " + map);
    return new Gson().toJson(map);
}

From source file:com.gst.integrationtests.common.GroupHelper.java

public static String getTestGroupWithDatatableAsJson(final String registeredTableName) {
    final HashMap<String, Object> map = new HashMap<>();
    map.put("officeId", "1");
    map.put("name", randomNameGenerator("Group_Name_", 5));
    map.put("externalId", randomIDGenerator("ID_", 7));
    map.put("dateFormat", "dd MMMM yyyy");
    map.put("locale", "en");
    map.put("active", "false");
    map.put("submittedOnDate", "04 March 2011");
    String requestJson = getTestDatatableAsJson(map, registeredTableName);
    System.out.println("map : " + requestJson);
    return requestJson;
}

From source file:com.opengamma.analytics.util.amount.SurfaceValue.java

/**
 * Create a new object containing the point of the initial object and the new point. If the point is not in the existing points of the object, it is put in the map.
 * If a point is already in the existing point of the object, the value is added to the existing value.
 * @param surfaceValue The surface value.
 * @param point The surface point.//from www . jav  a  2s .  c o m
 * @param value The associated value.
 * @return The combined/sum surface value.
 */
public static SurfaceValue plus(final SurfaceValue surfaceValue, final DoublesPair point, final Double value) {
    ArgumentChecker.notNull(surfaceValue, "Surface value");
    ArgumentChecker.notNull(point, "Point");
    final HashMap<DoublesPair, Double> plus = new HashMap<>(surfaceValue._data);
    if (surfaceValue._data.containsKey(point)) {
        plus.put(point, value + surfaceValue._data.get(point));
    } else {
        plus.put(point, value);
    }
    return new SurfaceValue(plus);
}

From source file:org.jdbcluster.dao.Dao.java

/**
 * caches dao configurations//from ww  w.j a v  a2 s .co m
 * @param daoClass class of dao object
 * @return map element
 */
private static HashMap<String, String> putCacheMap(Class<?> daoClass) {
    DaoConfig daoConfig = Dao.getDaoConfig();
    if (daoConfig == null)
        throw new ConfigurationException("No Dao configuration present. Call Dao.setDaoConfig first");
    String daoId = daoConfig.getDaoId(daoClass.getName());
    HashMap<String, String> hm = new HashMap<String, String>();
    classToPropsMap.put(daoClass, hm);

    String[] props = daoConfig.getPropertyName(daoId);
    for (String prop : props) {
        String value = daoConfig.getPropertieValue(daoId, prop);
        hm.put(prop, value);
    }
    return hm;
}