Example usage for java.util HashMap containsKey

List of usage examples for java.util HashMap containsKey

Introduction

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

Prototype

public boolean containsKey(Object key) 

Source Link

Document

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

Usage

From source file:com.mindcognition.mindraider.export.Atomizer.java

private static String getNoteOriginUri(final String globalOutlineUri, ConceptResource conceptResource,
        HashMap<String, String> noteUriToGlobalId) {
    if (noteUriToGlobalId.containsKey(conceptResource.getUri())) {
        return noteUriToGlobalId.get(conceptResource.getUri());
    } else {/*  w w  w .j  a  va  2 s  . com*/
        String globalConceptUri = conceptResource.getOriginUri();
        if (globalConceptUri == null) {
            globalConceptUri = GlobalIdGenerator.generateNoteId(globalOutlineUri);
            conceptResource.resource.addProperty(new OriginProperty(globalConceptUri));
        }
        noteUriToGlobalId.put(conceptResource.getUri(), conceptResource.getOriginUri());
        return globalConceptUri;
    }
}

From source file:org.samjoey.graphing.GraphUtility.java

public static void createGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (Game game : games) {
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }/*from  www.  j a v a 2 s.  com*/
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }

    for (String key : datasets.keySet()) {
        JFrame f = new JFrame();
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        f.setContentPane(chartPanel);
        f.pack();
        RefineryUtilities.centerFrameOnScreen(f);
        f.setVisible(true);
    }
}

From source file:Main.java

public static boolean getFrequentElementBinary(int[] sample) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;/*w w  w .java2 s  .com*/

    for (int col = 0; col < sample.length; col++) {
        // System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(sample[col])) {
            map.put(sample[col], id++);
            count.add(1);
            uniId.add(sample[col]);
        } else {
            no = map.get(sample[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        // System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    // System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    if (maxId == 1)
        return true;
    else
        return false;
}

From source file:com.cloudera.kitten.appmaster.util.HDFSFileFinder.java

public static Map<String, Long> getNumBytesOfGlobHeldByDatanodes(Path p, Configuration conf)
        throws IOException {
    FileSystem fs = p.getFileSystem(conf);

    HashMap<String, Long> bytesHeld = Maps.newHashMap();
    for (FileStatus f : fs.globStatus(p)) {
        BlockLocation[] bls = fs.getFileBlockLocations(p, 0, f.getLen());
        if (bls.length > 0) {
            for (BlockLocation bl : bls) {
                long l = bl.getLength();
                for (String name : bl.getNames()) {
                    if (bytesHeld.containsKey(name))
                        bytesHeld.put(name, bytesHeld.get(name) + l);
                    else
                        bytesHeld.put(name, l);
                }/*from w w w. j a v a 2  s  .  com*/
            }
        }
    }

    return bytesHeld;
}

From source file:Main.java

public static int getFrequentElement(int[] bcp) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;/* ww  w  .j  a va  2s . c o m*/

    for (int col = 0; col < bcp.length; col++) {
        //System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(bcp[col])) {
            map.put(bcp[col], id++);
            count.add(1);
            uniId.add(bcp[col]);
        } else {
            no = map.get(bcp[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        //System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    //System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    return maxId;
}

From source file:com.ciphertool.sentencebuilder.dao.BasicWordMapDao.java

/**
 * @param allWords/*from  ww  w  .j  a v a  2s .c om*/
 *            the List of all Words pulled in from the constructor
 * @return a Map of all Words keyed by their length
 */
protected static HashMap<Integer, ArrayList<Word>> mapByWordLength(List<Word> allWords) {
    if (allWords == null || allWords.isEmpty()) {
        throw new IllegalArgumentException(
                "Error mapping Words by length.  The supplied List of Words cannot be null or empty.");
    }

    HashMap<Integer, ArrayList<Word>> byWordLength = new HashMap<Integer, ArrayList<Word>>();

    for (Word w : allWords) {
        Integer length = w.getId().getWord().length();

        // Add the part of speech to the map if it doesn't exist
        if (!byWordLength.containsKey(length)) {
            byWordLength.put(length, new ArrayList<Word>());
        }

        /*
         * Add the word to the map by reference a number of times equal to
         * the frequency value
         */
        for (int i = 0; i < w.getFrequencyWeight(); i++) {
            byWordLength.get(length).add(w);
        }
    }

    return byWordLength;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.utils.LocalNamespaceClassUtils.java

public static HashMap<String, String> getLocalNamespacesClasses(VitroRequest vreq,
        HashMap<String, String> namespaces) {
    HashMap<String, String> localClasses = new HashMap<String, String>();
    List<VClass> allClasses = vreq.getWebappDaoFactory().getVClassDao().getAllVclasses();
    for (VClass v : allClasses) {
        String classNamespace = v.getNamespace();
        String classUri = v.getURI();

        if (namespaces.containsKey(classNamespace)) {
            String namespaceLabel = namespaces.get(classNamespace);
            String prefix = namespaceLabel.substring(namespaceLabel.indexOf("(") + 1,
                    namespaceLabel.indexOf(")"));
            localClasses.put(classUri, v.getName() + " ( " + prefix + ")");
        }/*from w  w  w .  j a v a 2s .c  o  m*/
    }
    return localClasses;
}

From source file:com.ciphertool.sentencebuilder.dao.BasicWordMapDao.java

/**
 * @param allWords//from   w w  w  .ja va 2  s. c om
 *            the List of all Words pulled in from the constructor
 * @return a Map of all Words keyed by their PartOfSpeech
 */
protected static HashMap<PartOfSpeechType, ArrayList<Word>> mapByPartOfSpeech(List<Word> allWords) {
    if (allWords == null || allWords.isEmpty()) {
        throw new IllegalArgumentException(
                "Error mapping Words by PartOfSpeech.  The supplied List of Words cannot be null or empty.");
    }

    HashMap<PartOfSpeechType, ArrayList<Word>> byPartOfSpeech = new HashMap<PartOfSpeechType, ArrayList<Word>>();
    for (Word w : allWords) {
        PartOfSpeechType pos = w.getId().getPartOfSpeech();

        // Add the part of speech to the map if it doesn't exist
        if (!byPartOfSpeech.containsKey(pos)) {
            byPartOfSpeech.put(pos, new ArrayList<Word>());
        }

        /*
         * Add the word to the map by reference a number of times equal to
         * the frequency value
         */
        for (int i = 0; i < w.getFrequencyWeight(); i++) {
            byPartOfSpeech.get(pos).add(w);
        }
    }
    return byPartOfSpeech;
}

From source file:com.collabnet.ccf.teamforge.TFAppHandler.java

public static HashMap<String, List<TrackerFieldDO>> loadTrackerFieldsInHashMap(TrackerFieldDO[] flexFields) {
    HashMap<String, List<TrackerFieldDO>> fieldsMap = new HashMap<String, List<TrackerFieldDO>>();
    for (TrackerFieldDO field : flexFields) {
        String fieldName = field.getName();
        // FIXME Will we ever get two field with same name in method?
        if (fieldsMap.containsKey(fieldName)) {
            List<TrackerFieldDO> fieldsList = fieldsMap.get(fieldName);
            fieldsList.add(field);//from   w  w w.  j  a  va 2  s .  c  o m
        } else {
            List<TrackerFieldDO> fieldsList = new ArrayList<TrackerFieldDO>();
            fieldsList.add(field);
            fieldsMap.put(fieldName, fieldsList);
        }
    }
    return fieldsMap;
}

From source file:it.acubelab.smaph.SmaphUtils.java

/**
 * Turns a list of pairs <b,r>, where b is a bold and r is the position in
 * which the bold occurred, to a mapping from a bold to the positions in
 * which the bolds occurred.//w  w w  .j  a  v  a 2s .  c o m
 * 
 * @param boldAndRanks
 *            a list of pairs <b,r>, where b is a bold and r is the position
 *            in which the bold occurred.
 * @return a mapping from a bold to the positions in which the bold
 *         occurred.
 */
public static HashMap<String, HashSet<Integer>> findPositionsLC(List<Pair<String, Integer>> boldAndRanks) {
    HashMap<String, HashSet<Integer>> positions = new HashMap<>();
    for (Pair<String, Integer> boldAndRank : boldAndRanks) {
        String bold = boldAndRank.first.toLowerCase();
        int rank = boldAndRank.second;
        if (!positions.containsKey(bold))
            positions.put(bold, new HashSet<Integer>());
        positions.get(bold).add(rank);
    }
    return positions;
}