Example usage for java.util HashMap values

List of usage examples for java.util HashMap values

Introduction

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

Prototype

public Collection<V> values() 

Source Link

Document

Returns a Collection view of the values contained in this map.

Usage

From source file:com.jaxio.celerio.output.FileTrackerTest.java

@Test
public void leaveGeneratedFilesUntouched() throws IOException {
    File projectDir = new File("target");

    HashMap<String, FileMetaData> generatedFiles = newHashMap();

    // simulate a generation round
    File f1 = createFileWithContent(projectDir, "leaveGeneratedFilesUntouched-f1.txt", "my content");
    File f2 = createFileWithContent(projectDir, "leaveGeneratedFilesUntouched-f2.txt", "my content2");
    generatedFiles.put("leaveGeneratedFilesUntouched-f1.txt",
            new FileMetaData(null, null, "leaveGeneratedFilesUntouched-f1.txt", f1));
    generatedFiles.put("leaveGeneratedFilesUntouched-f2.txt",
            new FileMetaData(null, null, "leaveGeneratedFilesUntouched-f2.txt", f2));
    assertThat(generatedFiles).hasSize(2);
    fileTracker.saveToProjectDir(generatedFiles, projectDir);

    // simulate user changing 1 file content
    f2 = createFileWithContent(projectDir, "leaveGeneratedFilesUntouched-f2.txt", "my content2 has changed");

    // make sure we can detect the file change
    HashMap<String, FileMetaData> loadedGeneratedFiles = fileTracker.loadFromProjectDir(projectDir);
    assertThat(loadedGeneratedFiles.values())
            .contains(new FileMetaData(null, null, "leaveGeneratedFilesUntouched-f1.txt", f1));
    assertThat(loadedGeneratedFiles.values())
            .excludes(new FileMetaData(null, null, "leaveGeneratedFilesUntouched-f2.txt", f2));

    FileMetaData willBeDeleted = new FileMetaData(null, null, "leaveGeneratedFilesUntouched-f1.txt", f1);
    HashSet<FileMetaData> deletedFiles = fileTracker.deleteGeneratedFileIfIdentical(projectDir,
            new ArrayList<String>());
    assertThat(deletedFiles).hasSize(1);
    assertThat(deletedFiles).contains(willBeDeleted);
    assertThat(deletedFiles).excludes(new FileMetaData(null, null, "leaveGeneratedFilesUntouched-f2.txt", f2));
}

From source file:eu.europa.cedefop.europass.jtool.util.ExtractAttachments.java

/**
  * Extract the attachment file/*from  w  ww.j  a  v  a2s.c o  m*/
  * @throws Exception
  */
public void execute() throws Exception {
    boolean hasAttachment = false;
    try {
        PdfReader reader = new PdfReader(in);
        PdfDictionary catalog = reader.getCatalog();
        PdfDictionary names = (PdfDictionary) PdfReader.getPdfObject(catalog.get(PdfName.NAMES));
        if (names != null) {
            PdfDictionary embFiles = (PdfDictionary) PdfReader
                    .getPdfObject(names.get(new PdfName("EmbeddedFiles")));
            if (embFiles != null) {
                HashMap embMap = PdfNameTree.readTree(embFiles);
                for (Iterator i = embMap.values().iterator(); i.hasNext();) {
                    PdfDictionary filespec = (PdfDictionary) PdfReader.getPdfObject((PdfObject) i.next());
                    unpackFile(filespec);
                }
            }
        }
        for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
            PdfArray annots = (PdfArray) PdfReader.getPdfObject(reader.getPageN(k).get(PdfName.ANNOTS));
            if (annots == null)
                continue;
            for (Iterator i = annots.listIterator(); i.hasNext();) {
                PdfDictionary annot = (PdfDictionary) PdfReader.getPdfObject((PdfObject) i.next());
                PdfName subType = (PdfName) PdfReader.getPdfObject(annot.get(PdfName.SUBTYPE));
                if (!PdfName.FILEATTACHMENT.equals(subType))
                    continue;
                PdfDictionary filespec = (PdfDictionary) PdfReader.getPdfObject(annot.get(PdfName.FS));
                hasAttachment = true;
                unpackFile(filespec);
            }
        }
    } catch (Exception e) {
        log.error("Error while extracting PDF attachements: " + e);
    }
    if (!hasAttachment)
        throw new Exception("PDF file does not have attachment.");
}

From source file:com.imag.nespros.runtime.algoritms.Solution.java

private void setComputer2Op(HashMap<EPUnit, Device> op2Comp) {
    computer2Op.clear();/*from   w  ww . j a  v a  2 s . c  om*/
    for (Device c : op2Comp.values()) {
        ArrayList<EPUnit> operators = new ArrayList<>();
        for (EPUnit op : op2Comp.keySet()) {
            if (op2Comp.get(op) == c) {
                operators.add(op);
            }
        }
        computer2Op.put(c, operators);
    }
}

From source file:com.antelink.sourcesquare.client.scan.ProcessWorker.java

private void analyzeMapWithCount(int times, HashMap<String, String> tempMap) throws Exception {
    try {//from   w ww  .j av a2  s  . c  om
        logger.debug("pass " + times + ": analyzing files " + tempMap.values());
        this.engine.discover(tempMap);
    } catch (Exception e) {
        logger.debug("Error while analyzing", e);
        if (times > RETRIES) {
            logger.error(RETRIES + " time retry done... giving up!");
            // do as if the result where found
            this.engine.DummyPass(e, tempMap.size());
            throw e;
        } else {
            logger.debug("retrying...");
            analyzeMapWithCount(times + 1, tempMap);
        }
    }
}

From source file:kmi.taa.core.SmallSetAnalyser.java

public double mean(HashMap<Integer, Double> map) {
    double sum = 0;
    for (Double v : map.values()) {
        sum += v.doubleValue();/*from  w w  w .jav a  2 s . c o m*/
    }
    return sum / map.size();
}

From source file:com.likya.myra.jef.core.MonitoringOperationsImpl.java

private ControllerInterface getControllerInterface() {
    HashMap<String, ControllerInterface> controllerContainer = coreFactory.getControllerContainer();

    ArrayList<ControllerInterface> controllerArray = new ArrayList<ControllerInterface>(
            controllerContainer.values());

    ControllerInterface controllerInterface = ((ControllerInterface) controllerArray.get(0));

    return controllerInterface;

}

From source file:com.likya.myra.jef.core.MonitoringOperationsImpl.java

public Collection<AbstractJobType> getJobList(Predicate predicate) {

    HashMap<String, ControllerInterface> controllerContainer = coreFactory.getControllerContainer();

    ArrayList<ControllerInterface> controllerArray = new ArrayList<ControllerInterface>(
            controllerContainer.values());

    ControllerInterface controllerInterface = ((ControllerInterface) controllerArray.get(0));

    return JobQueueOperations.getJobListForImpl(controllerInterface.getJobQueue(), predicate);

}

From source file:edu.illinois.cs.cogcomp.utils.Utils.java

/**
 * This measures the WAVE score of a set of productions. WAVE score comes from (Kumaran et al 2010)
 * It is a measure of transliterability.
 * @param fname the file name of a set of learned productions.
 * @return WAVE score/* w ww . j a va2 s.co  m*/
 */
public static double WAVE(String fname) throws FileNotFoundException {
    List<String> lines = LineIO.read(fname);

    HashMap<String, Integer> srcFreq = new HashMap<>();
    HashMap<String, Integer> tgtFreq = new HashMap<>();

    HashMap<String, Double> entropy = new HashMap<>();

    for (String line : lines) {

        if (line.trim().length() == 0 || line.startsWith("#")) {
            continue;
        }

        String[] sline = line.split("\t");

        String src = sline[0];
        String tgt = sline[1];
        double prob = Double.parseDouble(sline[2]);

        Dictionaries.IncrementOrSet(srcFreq, src, 1, 1);

        Dictionaries.IncrementOrSet(tgtFreq, tgt, 1, 1);

        double v = prob * Math.log(prob);
        Dictionaries.IncrementOrSet(entropy, src, v, v);

    }

    double total = 0;
    for (int v : srcFreq.values()) {
        total += v;
    }

    double WAVE = 0;

    for (String i : srcFreq.keySet()) {
        // -= because entropy should be negative, but I never do it.
        WAVE -= srcFreq.get(i) / total * entropy.get(i);
    }

    return WAVE;
}

From source file:JarUtil.java

/**
 * Reads the package-names from the given jar-file.
 * /*from  www . j  ava2  s.  c  om*/
 * @param jarFile
 *            the jar file
 * @return an array with all found package-names
 * @throws IOException
 *             when the jar-file could not be read
 */
public static String[] getPackageNames(File jarFile) throws IOException {
    HashMap<String, String> packageNames = new HashMap<String, String>();
    JarFile input = new JarFile(jarFile, false, ZipFile.OPEN_READ);
    Enumeration<JarEntry> enumeration = input.entries();
    for (; enumeration.hasMoreElements();) {
        JarEntry entry = enumeration.nextElement();
        String name = entry.getName();
        if (name.endsWith(".class")) {
            int endPos = name.lastIndexOf('/');
            boolean isWindows = false;
            if (endPos == -1) {
                endPos = name.lastIndexOf('\\');
                isWindows = true;
            }
            name = name.substring(0, endPos);
            name = name.replace('/', '.');
            if (isWindows) {
                name = name.replace('\\', '.');
            }
            packageNames.put(name, name);
        }
    }
    return (String[]) packageNames.values().toArray(new String[packageNames.size()]);
}

From source file:com.predic8.membrane.core.interceptor.javascript.JavascriptInterceptor.java

private HashMap<String, Object> getJavascriptTypesForClasses(HashMap<String, Object> classes) {
    HashMap<String, Object> result = new HashMap<>();
    for (Object clazz : classes.values()) {
        Class<?> clazzz = (Class<?>) clazz;
        String scriptSrc = clazzz.getSimpleName() + ".static;";
        //TODO this is hacky, do this differently ( maybe do this one time at startup )
        Object jsType = jls.compileScript(router, scriptSrc).apply(classes);

        result.put(clazzz.getSimpleName(), jsType);
    }/*from   www.j a v  a  2 s. co m*/
    return result;
}