Example usage for java.util LinkedHashMap get

List of usage examples for java.util LinkedHashMap get

Introduction

In this page you can find the example usage for java.util LinkedHashMap get.

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.tacitknowledge.util.migration.DistributedMigrationProcess.java

/**
 * Applies the necessary rollbacks to the system.
 *
 * @param currentPatchInfoStore// ww  w  . j  a  v  a2s .  co  m
 * @param rollbackLevels        the level that the system should rollback to
 * @param context               information and resources that are available to the migration tasks
 * @return the number of <code>RollbackableMigrationTasks</code> which have been rolled back
 * @throws MigrationException if a rollback fails
 * @Override
 */
public final int doRollbacks(final PatchInfoStore currentPatchInfoStore, final int[] rollbackLevels,
        final MigrationContext context, boolean forceRollback) throws MigrationException {
    log.debug("Starting doRollbacks");
    // get all of the allTasks, with launchers, then get the list of just
    // allTasks
    LinkedHashMap rollbacksWithLaunchers = getMigrationTasksWithLaunchers();
    List allTasks = new ArrayList();
    allTasks.addAll(rollbacksWithLaunchers.keySet());

    List<MigrationTask> rollbackCandidates = getMigrationRunnerStrategy().getRollbackCandidates(allTasks,
            rollbackLevels, currentPatchInfoStore);

    validateControlledSystems(currentPatchInfoStore);
    rollbackDryRun(rollbackCandidates, rollbacksWithLaunchers);

    if (rollbackCandidates.size() > 0) {
        log.info("A total of " + rollbackCandidates.size() + " rollback patch tasks will execute.");
    } else {
        log.info("System up-to-date.  No patch tasks will rollback.");
    }

    if (isPatchSetRollbackable(rollbackCandidates) || forceRollback) {
        if (isReadOnly()) {
            throw new MigrationException("Unapplied rollbacks exist, but read-only flag is set");
        }

        for (Iterator rollbackIterator = rollbackCandidates.iterator(); rollbackIterator.hasNext();) {
            RollbackableMigrationTask task = (RollbackableMigrationTask) rollbackIterator.next();
            // Execute the task in the context it was loaded from
            JdbcMigrationLauncher launcher = (JdbcMigrationLauncher) rollbacksWithLaunchers.get(task);

            // iterate through all the contexts
            for (Iterator j = launcher.getContexts().keySet().iterator(); j.hasNext();) {
                MigrationContext launcherContext = (MigrationContext) j.next();
                applyRollback(launcherContext, task, true);
            }
        }

    } else {
        log.info("Could not complete rollback because one or more of the tasks is not rollbackable.");
    }

    List<MigrationTask> rollbacksNotApplied = getMigrationRunnerStrategy()
            .getRollbackCandidates(rollbackCandidates, rollbackLevels, currentPatchInfoStore);

    if (rollbacksNotApplied.isEmpty()) {
        log.info("Rollback complete (" + rollbackCandidates.size() + " patch tasks rolledback)");
    } else {
        log.info("The system could not rollback the tasks");
    }
    return rollbackCandidates.size() - rollbacksNotApplied.size();
}

From source file:service.EventService.java

public LinkedHashMap<Campaign, HashMap<String, String>> getCampaignsWithCountInfos(Long pkId, User us) {
    LinkedHashMap<Campaign, HashMap<String, String>> res = new LinkedHashMap();
    LinkedHashMap<Long, HashMap<String, String>> countMap = eventDao
            .getFinishedAndUnassignedEventCountsInCampaignsAsMap(pkId);
    for (Campaign c : campaignDao.getAllCampaigns(pkId)) {
        HashMap<String, String> InfoMap = countMap.get(c.getId());
        if (InfoMap == null) {
            InfoMap = new HashMap();
            InfoMap.put("finishedCount", "0");
            InfoMap.put("unassignedCount", "0");
        }/*from  w  w w  .j a v a2 s  .  com*/
        if (us != null) {
            if (!campaignObserverDao.getByUsrAngCampaign(c.getCampaignId(), pkId, us.getId()).isEmpty()) {
                res.put(c, InfoMap);
            }
        } else {
            res.put(c, InfoMap);
        }

    }
    return res;
}

From source file:com.grarak.kerneladiutor.fragments.tools.ProfileFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (data == null)
        return;/*from   ww w . j  av a2  s .c om*/
    if (requestCode == 0 || requestCode == 2) {
        LinkedHashMap<String, String> commandsList = new LinkedHashMap<>();
        ArrayList<String> ids = data.getStringArrayListExtra(ProfileActivity.RESULT_ID_INTENT);
        ArrayList<String> commands = data.getStringArrayListExtra(ProfileActivity.RESULT_COMMAND_INTENT);
        for (int i = 0; i < ids.size(); i++) {
            commandsList.put(ids.get(i), commands.get(i));
        }

        if (requestCode == 0) {
            create(commandsList);
        } else {
            Profiles.ProfileItem profileItem = mProfiles.getAllProfiles()
                    .get(data.getIntExtra(ProfileActivity.POSITION_INTENT, 0));

            for (Profiles.ProfileItem.CommandItem commandItem : profileItem.getCommands()) {
                if (ids.contains(commandItem.getPath())) {
                    profileItem.delete(commandItem);
                }
            }

            for (String path : commandsList.keySet()) {
                profileItem.putCommand(new Profiles.ProfileItem.CommandItem(path, commandsList.get(path)));
            }
            mProfiles.commit();
        }
    } else if (requestCode == 1) {
        ImportProfile importProfile = new ImportProfile(data.getStringExtra(FilePickerActivity.RESULT_INTENT));

        if (!importProfile.readable()) {
            Utils.toast(R.string.import_malformed, getActivity());
            return;
        }

        if (!importProfile.matchesVersion()) {
            Utils.toast(R.string.import_wrong_version, getActivity());
            return;
        }

        showImportDialog(importProfile);
    } else if (requestCode == 3) {
        reload();
    }
}

From source file:com.taobao.datax.plugins.writer.oraclejdbcwriter.OracleJdbcWriter.java

public String buildInsertString() {
    StringBuilder sb = new StringBuilder();
    sb.append("INSERT INTO ").append(this.schema + "." + this.table).append(" ");
    if (!StringUtils.isEmpty(this.colorder)) {
        sb.append("(").append(this.colorder).append(")");
    }/*from   w  ww .  ja v a2  s .  co m*/
    sb.append(" VALUES(");
    try {
        ResultSet rs = this.connection.createStatement()
                .executeQuery("SELECT COLUMN_NAME,DATA_TYPE FROM USER_TAB_COLUMNS WHERE TABLE_NAME='"
                        + this.table.toUpperCase() + "'");
        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        while (rs.next()) {
            String colName = rs.getString(1);
            String colType = rs.getString(2);
            map.put(colName, colType);
        }
        logger.debug("Column map:size=" + map.size() + ";cols=" + map.toString());
        if (StringUtils.isEmpty(this.colorder)) {
            Iterator<Entry<String, String>> it = map.entrySet().iterator();
            while (it.hasNext()) {
                Entry<String, String> entry = it.next();
                String colType = entry.getValue();
                if (colType.toUpperCase().equals("DATE")) {
                    sb.append("to_date(?,'" + this.dtfmt + "'),");
                } else {
                    sb.append("?,");
                }
            }
            sb.deleteCharAt(sb.length() - 1);// remove last comma
            sb.append(")");
        } else {
            String[] arr = colorder.split(",");
            for (String colName : arr) {
                if (!map.containsKey(colName)) {
                    throw new DataExchangeException("col " + colName + " not in database");
                }
                String colType = map.get(colName);
                if (colType.toUpperCase().equals("DATE")) {
                    sb.append("to_date(?,'" + this.dtfmt + "'),");
                } else {
                    sb.append("?,");
                }
            }
            sb.deleteCharAt(sb.length() - 1);// remove last comma
            sb.append(")");
        }
    } catch (SQLException e) {
        e.printStackTrace();
        throw new DataExchangeException(e.getMessage());
    }

    return sb.toString();
}

From source file:com.logsniffer.event.es.EsEventPersistence.java

private void prepareMapping(final long snifferId) {
    logger.info("Rebuilding mapping for sniffer {}", snifferId);
    final Sniffer sniffer = snifferPersistence.getSniffer(snifferId);
    if (sniffer == null) {
        logger.info("Skip rebuilding mapping due to no more existing sniffer: {}", snifferId);
        return;//w  w  w  . j  a  v  a  2 s  .c om
    }
    final LinkedHashMap<String, FieldBaseTypes> snifferTypes = new LinkedHashMap<>();

    final LogSource<?> source = logSourceProvider.getSourceById(sniffer.getLogSourceId());
    final LinkedHashMap<String, FieldBaseTypes> entriesTypes = new LinkedHashMap<>();
    try {
        entriesTypes.putAll(source.getReader().getFieldTypes());
    } catch (final FormatException e) {
        logger.warn("Failed to access entries fields, these won't be considered", e);
    }

    try {
        clientTpl.executeWithClient(new ClientCallback<Object>() {
            @Override
            public Object execute(final Client client) {
                final StringWriter jsonMapping = new StringWriter();
                final JSONBuilder mappingBuilder = new JSONBuilder(jsonMapping).object();
                final JSONBuilder props = mappingBuilder.key(getType(snifferId)).object().key("properties")
                        .object();

                // TODO: Map sniffer fields dynamically
                props.key(Event.FIELD_TIMESTAMP).object().key("type").value("date").endObject();
                props.key(Event.FIELD_PUBLISHED).object().key("type").value("date").endObject();

                for (final String key : entriesTypes.keySet()) {
                    mapField(props, Event.FIELD_ENTRIES + "." + key, entriesTypes.get(key));
                }

                mappingBuilder.endObject().endObject().endObject();
                logger.info("Creating mapping for sniffer {}: {}", snifferId, jsonMapping);
                client.admin().indices().preparePutMapping(indexNamingStrategy.buildActiveName(snifferId))
                        .setType(getType(snifferId)).setSource(jsonMapping.toString()).get();
                return null;
            }
        });
    } catch (final Exception e) {
        logger.warn("Failed to update mapping for sniffer " + snifferId + ", try to delete all events", e);
    }
}

From source file:gate.util.reporting.PRTimeReporter.java

/**
 * Sorts LinkedHashMap by its values(natural descending order). keeps the
 * duplicates as it is.//from w w w.j av  a  2  s . co  m
 *
 * @param passedMap
 *          An Object of type LinkedHashMap to be sorted by its values.
 *
 * @return An Object containing the sorted LinkedHashMap.
 */
private LinkedHashMap<String, String> sortHashMapByValues(LinkedHashMap<String, String> passedMap) {
    List<String> mapKeys = new ArrayList<String>(passedMap.keySet());
    List<String> mapValues = new ArrayList<String>(passedMap.values());

    Collections.sort(mapValues, new ValueComparator());
    Collections.sort(mapKeys);
    Collections.reverse(mapValues);
    LinkedHashMap<String, String> sortedMap = new LinkedHashMap<String, String>();

    Iterator<String> valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        String val = valueIt.next();
        Iterator<String> keyIt = mapKeys.iterator();
        while (keyIt.hasNext()) {
            String key = keyIt.next();
            String comp1 = passedMap.get(key).toString();
            String comp2 = val.toString();

            if (comp1.equals(comp2)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put(key, val);
                break;
            }
        }
    }
    return sortedMap;
}

From source file:de.ingrid.importer.udk.strategy.v1.IDCStrategy1_0_9.java

/** Add gui ids of all NEW OPTIONAL fields to sys_gui table ! (mandatory fields not added, behavior not changeable) */
protected void updateSysGui() throws Exception {
    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui...");
    }/*  w  ww . ja  v  a2  s. c  om*/

    if (log.isInfoEnabled()) {
        log.info("Add ids of new OPTIONAL fields !...");
    }

    LinkedHashMap<String, Integer> newSysGuis = new LinkedHashMap<String, Integer>();
    Integer initialBehaviour = -1; // default behaviour, optional field only shown if section expanded ! 
    //      Integer remove = 0; // do NOT show if section reduced (use case for optional fields ? never used) !
    //      Integer mandatory = 1; // do also show if section reduced (even if field optional) !

    newSysGuis.put("3260", initialBehaviour);
    newSysGuis.put("3630", initialBehaviour);
    newSysGuis.put("3600", initialBehaviour);
    newSysGuis.put("3640", initialBehaviour);
    newSysGuis.put("3645", initialBehaviour);
    newSysGuis.put("3650", initialBehaviour);
    newSysGuis.put("3670", initialBehaviour);

    Iterator<String> itr = newSysGuis.keySet().iterator();
    while (itr.hasNext()) {
        String key = itr.next();
        jdbc.executeUpdate("INSERT INTO sys_gui (id, gui_id, behaviour) VALUES (" + getNextId() + ", '" + key
                + "', " + newSysGuis.get(key) + ")");
    }

    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui... done");
    }
}

From source file:es.eucm.eadventure.tracking.prv.gleaner.GleanerLogConsumer.java

private Map<String, Object> convert(GameLogEntry entry) {

    LinkedHashMap<String, Object> trace = new LinkedHashMap<String, Object>();
    LinkedHashMap<String, Object> data = new LinkedHashMap<String, Object>();

    try {//from  w w w.  j a v a2 s.c  om
        // High level
        if (entry.getElementName().equals("h")) {
            trace.put("timeStamp", Long.parseLong(entry.getAttributeValue("ms")) + initTimeStamp);
            trace.put("type", "logic");

            if (entry.getAttributeValue("o") != null) {
                trace.put("target", entry.getAttributeValue("o"));
            }

            if (entry.getAttributeValue("t") != null) {
                if (trace.containsKey("target")) {
                    data.put("target", entry.getAttributeValue("t"));
                } else {
                    trace.put("target", entry.getAttributeValue("t"));
                }
            }

            if ("scn".equals(entry.getAttributeValue("a"))) {
                if (currentPhase != null) {
                    // Send phase_end trace
                    LinkedHashMap<String, Object> endPhaseTrace = new LinkedHashMap<String, Object>();
                    endPhaseTrace.put("type", "logic");
                    endPhaseTrace.put("timeStamp", (Long) trace.get("timeStamp") - 1);
                    endPhaseTrace.put("event", "phase_end");
                    endPhaseTrace.put("target", currentPhase);
                    traces.add(endPhaseTrace);
                }
                // Set phase_start trace
                trace.put("event", "phase_start");
                this.currentPhase = trace.get("target").toString();
            } else if (entry.getAttributeValue("a") != null) {
                trace.put("event", entry.getAttributeValue("a"));
            } else if (entry.getAttributeValue("e") != null) {
                // Activate / Deactive flag
                String attValue = entry.getAttributeValue("e");
                trace.put("event", attValue);
                String varName = entry.getAttributeValue("t");
                trace.put("target", varName);
                boolean varUpdate = false;
                boolean value = false;
                if (attValue.equals("act")) {
                    trace.put("event", "var_update");
                    varUpdate = true;
                    value = true;
                } else if (attValue.equals("dct")) {
                    trace.put("event", "var_update");
                    varUpdate = true;
                    value = false;
                }

                if (varUpdate) {
                    data.put("value", value);
                    data.put("operator", attValue);
                }
            }

            // Change var value
            if (entry.getAttributeValue("v") != null) {

                String valueString = entry.getAttributeValue("v");
                data.put("operand", valueString);
                String operator = entry.getAttributeValue("e");
                data.put("operator", operator);
                trace.put("event", "var_update");
                String varName = entry.getAttributeValue("t");
                trace.put("target", varName);

                if (entry.getAttributeValue("e") != null
                        && (entry.getAttributeValue("e").equals(_HighLevelEvents.INCREMENT_VAR)
                                || entry.getAttributeValue("e").equals(_HighLevelEvents.DECREMENT_VAR)
                                || entry.getAttributeValue("e").equals(_HighLevelEvents.SET_VALUE)
                                || entry.getAttributeValue("e").equals(_HighLevelEvents.WAIT_TIME))) {
                    Integer value = Integer.parseInt(entry.getAttributeValue("v"));
                    if (!vars.containsKey(trace.get("target"))) {
                        vars.put(varName, 0);
                    }

                    if (operator.equals("set")) {
                        vars.put(varName, value);
                    } else if (operator.equals("inc")) {
                        vars.put(varName, value + vars.get(varName));
                    } else if (operator.equals("dec")) {
                        vars.put(varName, value - vars.get(varName));
                    }
                    data.put("value", vars.get(varName));
                }
            }

            // Other data
            if (entry.getAttributeValue("ix") != null) {
                data.put("ix", Float.parseFloat(entry.getAttributeValue("ix")));
            }
            if (entry.getAttributeValue("iy") != null) {
                data.put("iy", Float.parseFloat(entry.getAttributeValue("iy")));
            }
            if (entry.getAttributeValue("x") != null) {
                data.put("x", Integer.parseInt(entry.getAttributeValue("x")));
            }
            if (entry.getAttributeValue("y") != null) {
                data.put("y", Integer.parseInt(entry.getAttributeValue("y")));
            }
            if (entry.getAttributeValue("dx") != null) {
                data.put("dx", Integer.parseInt(entry.getAttributeValue("dx")));
            }
            if (entry.getAttributeValue("dy") != null) {
                data.put("dy", Integer.parseInt(entry.getAttributeValue("dy")));
            }
            if (entry.getAttributeValue("l") != null) {
                data.put("l", entry.getAttributeValue("l"));
            }
        }
        // Low level
        else if (entry.getElementName().equals("l")) {
            trace.put("timeStamp", Long.parseLong(entry.getAttributeValue("ms")) + initTimeStamp);
            trace.put("type", "input");
            String type = entry.getAttributeValue("t");
            String action = entry.getAttributeValue("i");
            if ("m".equals(type)) {
                trace.put("device", "mouse");
                data.put("count", Integer.parseInt(entry.getAttributeValue("c")));
                data.put("button", Integer.parseInt(entry.getAttributeValue("b")));
                String offset = entry.getAttributeValue("off");
                if (offset != null) {
                    data.put("offset", Integer.parseInt(offset));
                }
            } else if ("k".equals(type)) {
                trace.put("device", "keyboard");
                if ("t".equals(action)) {
                    data.put("ch", entry.getAttributeValue("k"));
                } else {
                    data.put("keyCode", Integer.parseInt(entry.getAttributeValue("c")));
                }
            }

            // Action
            if ("m".equals(action)) {
                trace.put("action", "move");
            } else if ("p".equals(action)) {
                trace.put("action", "press");
            } else if ("r".equals(action)) {
                trace.put("action", "release");
            } else if ("c".equals(action)) {
                trace.put("action", "click");
            } else if ("en".equals(action)) {
                trace.put("action", "enter");
            } else if ("d".equals(action)) {
                trace.put("action", "drag");
            } else if ("ex".equals(action)) {
                trace.put("action", "exit");
            } else if ("t".equals(action)) {
                trace.put("action", "type");
            }

            if (entry.getAttributeValue("m") != null) {
                data.put("modifiers", entry.getAttributeValue("m"));
            }

            if (entry.getAttributeValue("x") != null) {
                data.put("x", Integer.parseInt(entry.getAttributeValue("x")));
            }

            if (entry.getAttributeValue("y") != null) {
                data.put("y", Integer.parseInt(entry.getAttributeValue("y")));
            }
        }

        if (trace.isEmpty()) {
            return null;
        }

        if (!data.isEmpty()) {
            trace.put("data", data);
        }

    } catch (Exception e) {
        System.out.println("Exception while converting traces: " + e);
        System.out.println(entry + "");
    }
    return trace;

}

From source file:de.ingrid.importer.udk.strategy.v2.IDCStrategy2_3_0.java

/** Add gui ids of all NEW OPTIONAL fields to sys_gui table ! (mandatory fields not added, behavior not changeable) */
protected void updateSysGui() throws Exception {
    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui...");
    }//  ww w.j a v a  2 s.  c om

    if (log.isInfoEnabled()) {
        log.info("Add ids of new DataQuality Tables (OPTIONAL by default) !...");
    }

    LinkedHashMap<String, Integer> newSysGuis = new LinkedHashMap<String, Integer>();
    Integer initialBehaviour = -1; // default behaviour, optional field only shown if section expanded ! 
    //      Integer remove = 0; // do NOT show if section reduced (use case for optional fields ? never used) !
    //      Integer mandatory = 1; // do also show if section reduced (even if field optional) !

    // add  new sysgui Ids (dq tables)
    newSysGuis.put("7509", initialBehaviour);
    newSysGuis.put("7510", initialBehaviour);
    newSysGuis.put("7512", initialBehaviour);
    newSysGuis.put("7513", initialBehaviour);
    newSysGuis.put("7514", initialBehaviour);
    newSysGuis.put("7515", initialBehaviour);
    newSysGuis.put("7517", initialBehaviour);
    newSysGuis.put("7520", initialBehaviour);
    newSysGuis.put("7525", initialBehaviour);
    newSysGuis.put("7526", initialBehaviour);
    newSysGuis.put("7527", initialBehaviour);

    Iterator<String> itr = newSysGuis.keySet().iterator();
    while (itr.hasNext()) {
        String key = itr.next();
        jdbc.executeUpdate("INSERT INTO sys_gui (id, gui_id, behaviour) VALUES (" + getNextId() + ", '" + key
                + "', " + newSysGuis.get(key) + ")");
    }

    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui... done");
    }
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractBillingController.java

private void pushInvoiceToMap(LinkedHashMap<ServiceResourceType, ArrayList<Invoice>> chargesMap,
        ServiceResourceType serviceResourceType, Invoice invoice, List<Invoice> newServiceInvoices,
        List<Invoice> renewServiceInvoices) {
    if (serviceResourceType == null) {
        if (invoice.getType().equals(com.vmops.model.Invoice.Type.Subscription)) {
            newServiceInvoices.add(invoice);
        } else {/*from w ww .  j  av a 2 s . c  om*/
            renewServiceInvoices.add(invoice);
        }
        return;
    }
    if (chargesMap.containsKey(serviceResourceType)) {
        chargesMap.get(serviceResourceType).add(invoice);
    } else {
        ArrayList<Invoice> newInvoiceList = new ArrayList<Invoice>();
        newInvoiceList.add(invoice);
        chargesMap.put(serviceResourceType, newInvoiceList);
    }
}