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:forge.game.phase.Upkeep.java

private static void upkeepUpkeepCost(final Game game) {
    final CardCollectionView list = game.getPhaseHandler().getPlayerTurn().getCardsIn(ZoneType.Battlefield);

    for (int i = 0; i < list.size(); i++) {
        final Card c = list.get(i);
        final Player controller = c.getController();
        for (String ability : c.getKeywords()) {
            // sacrifice
            if (ability.startsWith("At the beginning of your upkeep, sacrifice")) {

                final StringBuilder sb = new StringBuilder("Sacrifice upkeep for " + c);
                final String[] k = ability.split(" pay ");
                final String cost = k[1].replaceAll("[{]", "").replaceAll("[}]", " ");

                String effect = "AB$ Sacrifice | Cost$ 0 | SacValid$ Self" + "| UnlessPayer$ You | UnlessCost$ "
                        + cost;/*from  w w  w .j  a  v a2s  . c om*/

                SpellAbility upkeepAbility = AbilityFactory.getAbility(effect, c);
                upkeepAbility.setActivatingPlayer(controller);
                upkeepAbility.setStackDescription(sb.toString());
                upkeepAbility.setDescription(sb.toString());
                upkeepAbility.setTrigger(true);

                game.getStack().addSimultaneousStackEntry(upkeepAbility);
            }

            // Cumulative upkeep
            if (ability.startsWith("Cumulative upkeep")) {
                final StringBuilder sb = new StringBuilder();
                final String[] k = ability.split(":");
                sb.append("Cumulative upkeep for " + c);

                final Ability upkeepAbility = new Ability(c, ManaCost.ZERO) {
                    @Override
                    public void resolve() {
                        c.addCounter(CounterType.AGE, 1, true);
                        String cost = CardFactoryUtil.multiplyCost(k[1], c.getCounters(CounterType.AGE));
                        final Cost upkeepCost = new Cost(cost, true);
                        this.setCumulativeupkeep(true);
                        boolean isPaid = controller.getController().payManaOptional(c, upkeepCost, this,
                                sb.toString(), ManaPaymentPurpose.CumulativeUpkeep);
                        final HashMap<String, Object> runParams = new HashMap<String, Object>();
                        runParams.put("CumulativeUpkeepPaid", Boolean.valueOf(isPaid));
                        runParams.put("Card", this.getHostCard());
                        runParams.put("PayingMana", StringUtils.join(this.getPayingMana(), ""));
                        game.getTriggerHandler().runTrigger(TriggerType.PayCumulativeUpkeep, runParams, false);
                        if (!isPaid) {
                            game.getAction().sacrifice(c, this);
                        }
                    }
                };
                sb.append("\n");
                upkeepAbility.setActivatingPlayer(controller);
                upkeepAbility.setStackDescription(sb.toString());
                upkeepAbility.setDescription(sb.toString());

                game.getStack().addSimultaneousStackEntry(upkeepAbility);
            }
        }
    }
}

From source file:com.opengamma.analytics.financial.provider.sensitivity.multicurve.MulticurveSensitivity.java

public static MulticurveSensitivity ofForward(final String curveName,
        final ForwardSensitivity pointSensitivity) {
    final List<ForwardSensitivity> listForward = new ArrayList<>();
    listForward.add(pointSensitivity);//www . j a  va 2  s  .com
    final HashMap<String, List<ForwardSensitivity>> mapFwd = new HashMap<>();
    mapFwd.put(curveName, listForward);
    return MulticurveSensitivity.ofForward(mapFwd);
}

From source file:Main.java

/**
 * Gets the changes made to the a list of items
 * /*  ww  w . ja v a 2 s  . com*/
 * @return HashMap the a list of items removed from the original list and a
 *         list of items added to the original list
 * */
public static <T> HashMap<String, HashSet<T>> getChangesToList(List<T> original, List<T> edited) {
    HashMap<String, HashSet<T>> changeSet = new HashMap<String, HashSet<T>>();
    HashSet<T> removed = new HashSet<T>(original);
    HashSet<T> added = new HashSet<T>(edited);
    removed.removeAll(edited);
    added.removeAll(original);

    changeSet.put(REMOVED_TAG, removed);
    changeSet.put(ADDED_TAG, added);

    return changeSet;
}

From source file:com.espertech.esperio.regression.adapter.SupportJMSReceiver.java

public static void print(Message msg) throws JMSException {
    log.info(".print received message: " + msg.getJMSMessageID());
    if (msg instanceof ObjectMessage) {
        ObjectMessage objMsg = (ObjectMessage) msg;
        log.info(".print object: " + objMsg.getObject().toString());
    } else {//from ww w .ja va 2 s.c o  m
        MapMessage mapMsg = (MapMessage) msg;
        HashMap map = new HashMap();
        Enumeration en = mapMsg.getMapNames();
        while (en.hasMoreElements()) {
            String property = (String) en.nextElement();
            Object mapObject = mapMsg.getObject(property);
            map.put(property, mapObject);
        }
        log.info(".print map: " + map);
    }
}

From source file:com.bigtobster.pgnextractalt.commands.TestCommandContext.java

/**
 * Builds an import command/* w  ww . j av  a2  s.  c  om*/
 *
 * @param file The file being imported
 * @return The full, complete import command including the reference to the file to be imported
 */
static String buildImportCommand(final File file) {
    //Execute command
    final HashMap<String, String> optionArgs = new HashMap<String, String>(1);
    optionArgs.put(IOCommands.FILE_PATH_OPTION, file.getPath());
    return TestCommandContext.buildCommand(IOCommands.getImportCommand(), optionArgs);
}

From source file:Main.java

public static HashMap<String, Element> buildIndex(Element element, String tagName, String idName) {
    NodeList nl = element.getElementsByTagName(tagName);
    HashMap<String, Element> index = new HashMap<>(nl.getLength());
    for (int i = 0; i < nl.getLength(); i++) {
        Element el = (Element) nl.item(i);
        String id = el.getAttribute(idName);
        if (!id.isEmpty())
            index.put(id, el);
    }//w w  w. ja v  a 2s.c om
    return index;
}

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

/**
 * /*from w w w  .  j a  va  2  s  . c o  m*/
 * @param userid
 *            User id that tasks need to match
 * @return HashMap of tasks matching userid
 */
public static HashMap<UUID, Task> getUserTasks(UUID userid) {
    ArrayList<Task> al = getAllTasks();
    HashMap<UUID, Task> own = new HashMap<UUID, Task>();
    for (Task t : al) {
        if (t.getUser().equals(userid)) {
            own.put(t.getId(), t);
        }
    }
    return own;
}

From source file:com.cloud.utils.PropertiesUtil.java

public static Map<String, Object> toMap(Properties props) {
    Set<String> names = props.stringPropertyNames();
    HashMap<String, Object> map = new HashMap<String, Object>(names.size());
    for (String name : names) {
        map.put(name, props.getProperty(name));
    }// www .  j  av  a 2  s.c om

    return map;
}

From source file:Main.java

static String generateURLForm(String... data) throws UnsupportedEncodingException {
    HashMap<String, String> keyValue = new HashMap<String, String>();
    String key = "";
    for (int i = 0; i < data.length; i++) {
        if (i % 2 == 0) { // Is key
            key = data[i];//from w  w w  .j av a  2s  .  co  m
        } else { // Is value
            keyValue.put(key, data[i]);
        }
    }
    return generateURLForm(keyValue);
}

From source file:heylee.android.network.JSONParserCustom.java

public static HashMap<String, Object> getJsonData(String data) throws JSONException {
    JSONObject jObj = new JSONObject(data);
    Iterator<String> iKeys = jObj.keys();
    HashMap<String, Object> map = new HashMap<String, Object>();
    while (iKeys.hasNext()) {
        String key = (String) iKeys.next();
        if (jObj.get(key) instanceof JSONObject) {
            map.put(key, parse(jObj.getJSONObject(key)));
        } else if (jObj.get(key) instanceof JSONArray) {
            map.put(key, parse(jObj.getJSONArray(key)));
        } else {//from w  w  w .  j a v  a2  s  .co m
            map.put(key, jObj.getString(key));
        }
    }
    return map;
}