Example usage for java.util LinkedHashMap containsKey

List of usage examples for java.util LinkedHashMap containsKey

Introduction

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

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

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  ava 2  s  .  c  o  m*/
        // 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:AndroidUninstallStock.java

public static LinkedHashMap<String, String> getLibFromPackage(String adb, LinkedList<String> liblist,
        LinkedHashMap<String, String> apklist) throws IOException {
    LinkedHashMap<String, String> libinclude = new LinkedHashMap<String, String>();
    File libget = File.createTempFile("AndroidUninstallStockLibs", null);
    for (Map.Entry<String, String> info : sortByValues(apklist).entrySet()) {
        System.out.print("* Libs in " + info.getKey() + " (" + info.getValue() + ")");
        LinkedList<String> pull = run(adb, "-s", lastdevice, "pull", "\"" + info.getKey() + "\"",
                "\"" + libget.getCanonicalPath() + "\"");
        if (pull.size() > 0 && pull.get(0).indexOf("does not exist") > 0) {
            System.out.println(" - file not exist");
            continue;
        }/*  w  w w  .  j a  v  a 2  s.c o m*/
        LinkedList<String> libinapk = getLibsInApk(libget.toPath());
        if (libinapk.size() == 0) {
            System.out.println(" - empty");
        } else {
            System.out.println(":");
            for (String libpath : libinapk) {
                String libname = libpath.substring(libpath.lastIndexOf('/') + 1);
                boolean libfound = false;
                for (String lb : liblist) {
                    if (lb.indexOf(libname) > -1) {
                        System.out.println(libpath + " = " + lb);
                        libinclude.put(lb,
                                (libinclude.containsKey(libname) ? libinclude.get(libname) + ", " : "")
                                        + info.getKey());
                        libfound = true;
                    }
                }
                if (!libfound) {
                    System.out.println(libpath + " = not found");
                }
            }
        }
    }
    try {
        libget.delete();
    } catch (Exception e) {
    }
    return libinclude;
}

From source file:com.dbmojo.QueryExecutor.java

/** Add a batch update to either a single statement, the correct
  * passed prepared statement./*w ww . jav  a2  s.c om*/
  */
private void addBatchUpdate(Connection conn, boolean prepared, String query, String[] values, Statement bstmt,
        LinkedHashMap<String, PreparedStatement> bpstmts) throws Exception {

    //If this is NOT a prepared statement then add the query to a raw SQL batch
    if (!prepared) {
        if (DebugLog.enabled) {
            DebugLog.add(this, "Adding update '" + query + "' to statement batch");
        }
        bstmt.addBatch(query);
    } else {
        //If this IS a prepared statement then check for its existence
        //in the pstmts hash. If it doesn't exist then create a new
        //pstmt for the query and add it to the hash.
        PreparedStatement pstmt = null;
        if (bpstmts.containsKey(query)) {
            if (DebugLog.enabled) {
                DebugLog.add(this, "Retrieving pstmt batch for query '" + query + "'");
            }
            pstmt = bpstmts.get(query);
        } else {
            if (DebugLog.enabled) {
                DebugLog.add(this, "Starting pstmt batch for query '" + query + "'");
            }

            pstmt = conn.prepareStatement(query);
        }

        if (DebugLog.enabled) {
            DebugLog.add(this, "Setting vals on pstmt batch for query '" + query + "'");
        }

        setPreparedStatementValues(pstmt, values);

        //Add THIS set of values to the batch for this specific 
        //prepared statement. Later on all prepared statment batches
        //will be executed sequentially
        if (DebugLog.enabled) {
            DebugLog.add(this, "Adding to pstmt batch for query '" + query + "'");
        }
        pstmt.addBatch();
        bpstmts.put(query, pstmt);
    }
}

From source file:org.primeframework.mvc.control.form.LocaleSelect.java

/**
 * Adds the countries Map and then calls super.
 *//*from   ww w  .  j  a  v  a  2  s .c om*/
@Override
protected Map<String, Object> makeParameters() {
    LinkedHashMap<String, String> locales = new LinkedHashMap<>();
    String preferred = (String) attributes.get("preferredLocales");
    if (preferred != null) {
        String[] parts = preferred.split(",");
        for (String part : parts) {
            Locale locale = LocaleUtils.toLocale(part);
            locales.put(locale.toString(), locale.getDisplayName(locale));
        }
    }

    boolean includeCountries = attributes.containsKey("includeCountries")
            ? (Boolean) attributes.get("includeCountries")
            : true;
    List<Locale> allLocales = new ArrayList<>();
    Collections.addAll(allLocales, Locale.getAvailableLocales());
    allLocales.removeIf((locale) -> locale.getLanguage().isEmpty() || locale.hasExtensions()
            || !locale.getScript().isEmpty() || !locale.getVariant().isEmpty()
            || (!includeCountries && !locale.getCountry().isEmpty()));
    allLocales.sort((one, two) -> one.getDisplayName(locale).compareTo(two.getDisplayName(locale)));

    for (Locale locale : allLocales) {
        if (!locales.containsKey(locale.getCountry())) {
            locales.put(locale.toString(), locale.getDisplayName(this.locale));
        }
    }

    attributes.put("items", locales);

    return super.makeParameters();
}

From source file:org.sonatype.nexus.plugin.AbstractStagingMojo.java

protected StageRepository select(final List<StageRepository> stageRepos, final String basicPrompt,
        final boolean allowAutoSelect) throws MojoExecutionException {
    List<StageRepository> stageRepositories = stageRepos;

    if (stageRepositories == null || stageRepositories.isEmpty()) {
        throw new MojoExecutionException("No repositories available.");
    }/*from ww  w.  j  ava  2s. c  om*/

    if (getRepositoryId() != null) {
        for (StageRepository repo : stageRepositories) {
            if (getRepositoryId().equals(repo.getRepositoryId())) {
                return repo;
            }
        }
    }

    if (allowAutoSelect && isAutomatic() && stageRepositories.size() == 1) {
        StageRepository repo = stageRepositories.get(0);
        getLog().info("Using the only staged repository available: " + repo.getRepositoryId());

        return repo;
    }

    LinkedHashMap<String, StageRepository> repoMap = new LinkedHashMap<String, StageRepository>();
    StringBuilder menu = new StringBuilder();
    List<String> choices = new ArrayList<String>();

    menu.append("\n\n\nAvailable Staging Repositories:\n\n");

    int i = 0;
    for (StageRepository repo : stageRepositories) {
        ++i;
        repoMap.put(Integer.toString(i), repo);
        choices.add(Integer.toString(i));

        menu.append("\n").append(i).append(": ").append(listRepo(repo)).append("\n");
    }

    menu.append("\n\n");

    if (isAutomatic()) {
        getLog().info(menu.toString());
        throw new MojoExecutionException(
                "Cannot auto-select; multiple staging repositories are available, and none are specified for use.");
    } else {
        String choice = null;
        while (choice == null || !repoMap.containsKey(choice)) {
            getLog().info(menu.toString());
            try {
                choice = getPrompter().prompt(basicPrompt, choices, "1");
            } catch (PrompterException e) {
                throw new MojoExecutionException("Failed to read from CLI prompt: " + e.getMessage(), e);
            }
        }

        return repoMap.get(choice);
    }
}

From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java

/**
 * Organized the results by the factor values (for one factor)
 * /*from w w w .  j  a v  a2  s.c  om*/
 * @param fv2bms master map
 * @param bioMaterialChunk biomaterials to organize
 * @param factorValues factor value to consider - biomaterials will be organized in the order given
 * @param chunks map of factor values to chunks goes here
 * @param organized the results go here
 */
private static void organizeByFactorValues(Map<FactorValue, List<BioMaterial>> fv2bms,
        List<BioMaterial> bioMaterialChunk, List<FactorValue> factorValues,
        LinkedHashMap<FactorValue, List<BioMaterial>> chunks, List<BioMaterial> organized) {
    Collection<BioMaterial> seenBioMaterials = new HashSet<BioMaterial>();
    for (FactorValue fv : factorValues) {

        if (!fv2bms.containsKey(fv)) {
            /*
             * This can happen if a factorvalue has been created but not yet associated with any biomaterials. This
             * can also be cruft.
             */
            continue;
        }

        // all in entire experiment, so we might not want them all as we may just be processing a small chunk.
        List<BioMaterial> biomsforfv = fv2bms.get(fv);

        for (BioMaterial bioMaterial : biomsforfv) {
            if (bioMaterialChunk.contains(bioMaterial)) {
                if (!chunks.containsKey(fv)) {
                    chunks.put(fv, new ArrayList<BioMaterial>());
                }
                if (!chunks.get(fv).contains(bioMaterial)) {
                    /*
                     * shouldn't be twice, but ya never know.
                     */
                    chunks.get(fv).add(bioMaterial);
                }
            }
            seenBioMaterials.add(bioMaterial);
        }

        // If we used that fv ...
        if (chunks.containsKey(fv)) {
            organized.addAll(chunks.get(fv)); // now at least this is in order of this factor
        }
    }

    // Leftovers contains biomaterials which have no factorvalue assigned for this factor.
    Collection<BioMaterial> leftovers = new HashSet<BioMaterial>();
    for (BioMaterial bm : bioMaterialChunk) {
        if (!seenBioMaterials.contains(bm)) {
            leftovers.add(bm);
        }
    }

    if (leftovers.size() > 0) {
        organized.addAll(leftovers);
        chunks.put((FactorValue) null, new ArrayList<BioMaterial>(leftovers));
    }

}

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

/**
 * Generates a tree like structure made up of LinkedHashMap containing the
 * processing elements and time taken by each element totaled at leaf level
 * over corpus./*  w ww .  j av a 2 s  . com*/
 *
 * @param store
 *          An Object of type LinkedHashMap<String, Object> containing the
 *          processing elements (with time in milliseconds) in hierarchical
 *          structure.
 * @param tokens
 *          An array consisting of remaining benchmarkID tokens except the one
 *          being processed.
 * @param bTime
 *          time(in milliseconds) of the benchmarkID token being processed.
 */
@SuppressWarnings("unchecked")
private void organizeEntries(LinkedHashMap<String, Object> store, String[] tokens, String bTime) {
    if (tokens.length > 0 && store.containsKey(tokens[0])) {
        if (tokens.length > 1) {
            String[] tempArr = new String[tokens.length - 1];
            System.arraycopy(tokens, 1, tempArr, 0, tokens.length - 1);
            if (store.get(tokens[0]) instanceof LinkedHashMap) {
                organizeEntries((LinkedHashMap<String, Object>) (store.get(tokens[0])), tempArr, bTime);
            } else {
                if (store.get(tokens[0]) != null) {
                    store.put(tokens[0], new LinkedHashMap<String, Object>());
                } else {
                    store.put(tokens[0], bTime);
                }
            }
        } else {
            if (store.get(tokens[0]) != null) {
                if (!(store.get(tokens[0]) instanceof LinkedHashMap)) {
                    int total = Integer.parseInt((String) (store.get(tokens[0]))) + Integer.parseInt(bTime);
                    store.put(tokens[0], Integer.toString(total));
                } else {
                    int total = Integer.parseInt(bTime);
                    if (((java.util.LinkedHashMap<String, Object>) (store.get(tokens[0])))
                            .get("systotal") != null) {
                        total = total + Integer.parseInt(
                                (String) ((java.util.LinkedHashMap<String, Object>) (store.get(tokens[0])))
                                        .get("systotal"));
                    }
                    ((java.util.LinkedHashMap<String, Object>) (store.get(tokens[0]))).put("systotal",
                            Integer.toString(total));
                }
            }
        }
    } else {
        if (tokens.length - 1 == 0) {
            store.put(tokens[0], bTime);
        } else {
            store.put(tokens[0], new LinkedHashMap<String, Object>());
            String[] tempArr = new String[tokens.length - 1];
            System.arraycopy(tokens, 1, tempArr, 0, tokens.length - 1);
            organizeEntries((LinkedHashMap<String, Object>) (store.get(tokens[0])), tempArr, bTime);
        }
    }
}

From source file:aldenjava.opticalmapping.data.mappingresult.OptMapResultNode.java

public boolean isSubRefInfoValid(LinkedHashMap<String, DataNode> optrefmap) {
    if (optrefmap.containsKey(mappedRegion.ref))
        return isSubRefInfoValid(optrefmap.get(mappedRegion.ref));
    else/*from ww  w  .jav  a2  s. c  om*/
        return false;
}

From source file:org.apache.flex.compiler.internal.projects.SourcePathManager.java

void handleChangedSourcePath(File[] newSourcePath) {
    // used to check for duplicates and buildup a mapping of which source files
    // are contained within each sourcePath
    Collection<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
    LinkedHashMap<DirectoryID, HashSet<QNameFile>> newSourcePaths = new LinkedHashMap<DirectoryID, HashSet<QNameFile>>();
    List<QNameFile> newQNameFilesToCreate = new ArrayList<QNameFile>();
    int order = 0;
    for (File sourcePathEntry : newSourcePath) {
        // Make sure the entry is a directory
        if (!sourcePathEntry.isDirectory()) {
            problems.add(new NonDirectoryInSourcePathProblem(sourcePathEntry));
        } else {/*  w  ww  .j  a va  2  s. c  om*/

            DirectoryID directoryId = new DirectoryID(sourcePathEntry);
            if (!newSourcePaths.containsKey(directoryId)) {
                HashSet<QNameFile> filesInPath = new HashSet<QNameFile>();
                newSourcePaths.put(directoryId, filesInPath);

                // Check for overlapping source path entries.
                for (File descendent : newSourcePath) {
                    if ((sourcePathEntry != descendent) && (isAncestorOf(sourcePathEntry, descendent))) {
                        problems.add(new OverlappingSourcePathProblem(sourcePathEntry, descendent));
                    }
                }

                String locale = null;
                if (compilerProject instanceof IFlexProject)
                    locale = ((IFlexProject) compilerProject)
                            .getResourceLocale(sourcePathEntry.getAbsolutePath());

                accumulateQNameFiles(filesInPath, sourcePathEntry, "", locale, problems, order);

                // if the source path already exists, no need to re-add files which
                // already exist
                Set<QNameFile> existingEntriesForSourcePath = Objects.<Set<QNameFile>>firstNonNull(
                        sourcePaths.get(directoryId), Collections.<QNameFile>emptySet());

                // Any qname file that is in filesInPath, but not in existingEntriesForSourcePath
                // is a new qname file that we need to create a compilation unit for.
                newQNameFilesToCreate.addAll(Sets.difference(filesInPath, existingEntriesForSourcePath));

            }
        }
        ++order;
    }

    // if an existing path is not in the newPaths, it needs to be removed.
    // work out which compilation units need to be removed as a result of changing
    Set<ICompilationUnit> unitsToRemove = new HashSet<ICompilationUnit>();
    for (Map.Entry<DirectoryID, HashSet<QNameFile>> e : sourcePaths.entrySet()) {
        Set<QNameFile> newSourcePathFiles = Objects.<Set<QNameFile>>firstNonNull(newSourcePaths.get(e.getKey()),
                Collections.<QNameFile>emptySet());

        Set<QNameFile> filesToRemove = Sets.difference(e.getValue(), newSourcePathFiles);

        for (QNameFile qNameFile : filesToRemove) {
            File sourceFile = qNameFile.file;

            Collection<ICompilationUnit> sourcePathCompilationUnitsToRemove = Collections2.filter(
                    compilerProject.getCompilationUnits(sourceFile.getAbsolutePath()),
                    new Predicate<ICompilationUnit>() {

                        @Override
                        public boolean apply(ICompilationUnit cu) {
                            DefinitionPriority defPriority = (DefinitionPriority) cu.getDefinitionPriority();
                            return defPriority.getBasePriority() == DefinitionPriority.BasePriority.SOURCE_PATH;
                        }
                    });
            unitsToRemove.addAll(sourcePathCompilationUnitsToRemove);
        }
    }

    // set the new sources
    sourcePaths = newSourcePaths;

    List<ICompilationUnit> unitsToAdd = new ArrayList<ICompilationUnit>();
    if (!newQNameFilesToCreate.isEmpty()) {
        for (QNameFile qNameFile : newQNameFilesToCreate) {
            ICompilationUnit newCU = compilerProject.getSourceCompilationUnitFactory().createCompilationUnit(
                    qNameFile.file, DefinitionPriority.BasePriority.SOURCE_PATH, qNameFile.order,
                    qNameFile.qName, qNameFile.locale);

            //It can be null in some cases, see #ResourceBundleSourceFileHandler
            if (newCU != null)
                unitsToAdd.add(newCU);
        }
    }

    this.problems = problems;
    compilerProject.updateCompilationUnitsForPathChange(unitsToRemove, unitsToAdd);
    checkForDuplicateQNames();
}

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

/**
 * Organizes the valid data extracted from the log entries into LinkedHashMap.
 *
 * @param store/*ww  w . j a  v  a  2  s  . c o m*/
 *          A global LinkedHashMap containing the processing elements (with
 *          time in milliseconds) in hierarchical structure.
 * @param matchedPR
 *          A PR matching the given search string.
 * @param bTime
 *          Time taken by the specific processing element.
 * @param docName
 *          Name of the document being processed.
 */
@SuppressWarnings("unchecked")
private void organizeEntries(LinkedHashMap<String, Object> store, String matchedPR, String bTime,
        String docName) {
    allDocs.add(docName);
    if (store.containsKey(matchedPR)) {
        ((LinkedHashMap<String, Object>) store.get(matchedPR)).put(docName, bTime);
    } else {
        LinkedHashMap<String, Object> tempLHM = new LinkedHashMap<String, Object>();
        tempLHM.put(docName, bTime);
        store.put(matchedPR, tempLHM);
    }
}