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:uniko.west.topology.bolts.InteractionGraphBolt.java

private void countReplies(Map<Object, Object> message, HashMap<String, ArrayList<Interaction>> authorActions) {
    String replyId = (String) message.get("in_reply_to_user_id_str");

    if (replyId != null) {
        if (!authorActions.containsKey("replied_to")) {
            authorActions.put("replied_to", new ArrayList<Interaction>());
        }//from   www. j  ava  2 s.c  o m
        authorActions.get("replied_to").add(new Interaction(replyId, (String) message.get("created_at")));
    }
}

From source file:epsi.i5.datamining.Treatment.java

/**
 * Main treatment//from  ww  w .  j a va2 s.co m
 *
 * @param file
 * @throws IOException
 * @throws MalformedURLException
 * @throws RepustateException
 * @throws ParseException
 */
public void treatment(File file) throws IOException, MalformedURLException, RepustateException, ParseException {
    boolean bStopWord;
    for (DataEntity entity : builder.getFullCommentaires(file)) {

        fillCatMap(entity);

        entity.setCommentaireTrie(sortComment(entity));

        dataEnter.add(entity);
    }

    //Recherche de la valeur max de chaque mots
    for (String word : words) {
        Integer max = 0;
        for (Entry entry : mapCategorie.entrySet()) {
            HashMap mapDonnee = (HashMap) entry.getValue();
            if (mapDonnee.containsKey(word)) {
                if (max < (Integer) mapDonnee.get(word)) {
                    max = (Integer) mapDonnee.get(word);
                }
            }
        }

        //Suppression des mots si ce n'est pas la valeur max
        for (Entry entry : mapCategorie.entrySet()) {
            HashMap mapDonnee = (HashMap) entry.getValue();
            if (mapDonnee.get(word) != max) {
                mapDonnee.remove(word);
            }
            entry.setValue(mapDonnee);
        }
    }

    List<DataEntity> commentairesFinaux = builder.getSimpleCommentaires(file);
    for (DataEntity commentaire : commentairesFinaux) {
        List<String> categorie;
        for (String word : commentaire.getCommentaires().split(" ")) {
            //System.out.println(stopword.getRegEx());

            word = useStopWords(word);

            bStopWord = checkStopWords(word);

            if (bStopWord == false) {
                for (Entry entry : mapCategorie.entrySet()) {
                    HashMap mapDonnee = (HashMap) entry.getValue();
                    if (mapDonnee.containsKey(word) && !"".equals(word)) {
                        categorie = commentaire.getListeCategorie();
                        if (!categorie.contains((String) entry.getKey())) {
                            categorie.add((String) entry.getKey());
                        }
                        commentaire.setListeCategorie(categorie);
                    }
                }
            }

        }
        dataExit.add(commentaire);
    }

    calculAllpolarite();

    for (int i = 0; i < dataExit.size(); i++) {

        System.out.println("Expected     : " + dataEnter.get(i).getListeCategorie());
        System.out.println("Found        : " + dataExit.get(i).getListeCategorie());

        if (dataEnter.get(i).getListeCategorie().containsAll(dataExit.get(i).getListeCategorie())) {
            System.out.println("Consistency  : " + true);
            fiabilite++;
        } else {
            System.out.println("Consistency  : " + false);
        }

        System.out.println("Raiting      : " + polarites.get(i));

        System.out.println("****************************");
    }
    System.out.println("****************************");
    fiabilite = (fiabilite * 100) / dataExit.size();
    if (fiabilite != 100) {
        System.err.println("Success rate : " + fiabilite + "%");
    } else {
        System.out.println("Success rate : " + fiabilite + "%");
    }
}

From source file:org.ala.spatial.services.web.DashboardController.java

@RequestMapping(value = { DASHBOARD_HOME, DASHBOARD_INDEX })
public ModelAndView index(HttpServletRequest req) {

    if (!Utilities.isLoggedIn(req)) {
        //ModelAndView mv = new ModelAndView("dashboard/types");
        //mv.addAttribute("error", "authentication");
        //mv.addAttribute("message", "Please authenticate yourself with the ALA system");
        //return mv;

        return new ModelAndView("message", "msg", "Please authenticate yourself with the ALA system");
    }/*from  w  w w .ja v a2 s .c o  m*/

    String useremail = Utilities.getUserEmail(req);
    List<Action> abe = actionDao.getActionsByEmail(useremail);

    FastDateFormat df = FastDateFormat.getInstance("yyyy-MM-dd hh:mm");
    HashMap<String, String> types = new HashMap<String, String>();
    for (Action a : abe) {
        if (a.getService() == null) {
            continue;
        }

        String val = "";
        if (types.containsKey(a.getCategory1())) {
            val = types.get(a.getCategory1()) + "|";
        }

        val += a.getService().getName() + "-" + a.getId() + "-" + df.format(a.getTime()).replaceAll("-", "_");
        types.put(a.getCategory1(), val);
    }

    List<Session> sessions = actionDao.getActionsBySessionsByUser(useremail);

    for (int i = 0; i < sessions.size(); i++) {
        Session session = sessions.get(i);
        String[] mal = session.getTasks().split(",");

        for (String s : mal) {
            session.incrementCount(s);
        }
    }

    ModelAndView mv = new ModelAndView("dashboard/index");
    mv.addObject("abe", abe);
    mv.addObject("types", types);
    mv.addObject("sessions", sessions);
    mv.addObject("useremail", useremail);
    mv.addObject("isAdmin", Utilities.isUserAdmin(req));

    return mv;
}

From source file:com.krawler.br.spring.RConverterImpl.java

private void putItem(HashMap itemMap, String key, Object value) {
    List l;//w w  w . j  a  va2 s. co  m
    if (itemMap.containsKey(key)) {
        l = (List) itemMap.get(key);
    } else {
        l = new ArrayList();
        itemMap.put(key, l);
    }
    l.add(value);
}

From source file:blusunrize.immersiveengineering.api.ApiUtils.java

private static boolean handlePos(Vec3d pos, BlockPos posB, HashMap<BlockPos, Vec3d> halfScanned,
        HashSet<BlockPos> done, Predicate<Triple<BlockPos, Vec3d, Vec3d>> shouldStop,
        HashSet<Triple<BlockPos, Vec3d, Vec3d>> near) {
    final double DELTA_NEAR = .3;
    if (!done.contains(posB)) {
        if (halfScanned.containsKey(posB) && !pos.equals(halfScanned.get(posB))) {
            Triple<BlockPos, Vec3d, Vec3d> added = new ImmutableTriple<>(posB, halfScanned.get(posB), pos);
            boolean stop = shouldStop.test(added);
            done.add(posB);//from  www.ja v  a 2 s.  co  m
            halfScanned.remove(posB);
            near.removeIf((t) -> t.getLeft().equals(posB));
            if (stop)
                return true;
            for (int i = 0; i < 3; i++) {
                double coord = getDim(pos, i);
                double diff = coord - Math.floor(coord);
                if (diff < DELTA_NEAR)
                    near.add(
                            new ImmutableTriple<>(offsetDim(posB, i, -1), added.getMiddle(), added.getRight()));
                diff = Math.ceil(coord) - coord;
                if (diff < DELTA_NEAR)
                    near.add(new ImmutableTriple<>(offsetDim(posB, i, 1), added.getMiddle(), added.getRight()));
            }
        } else {
            halfScanned.put(posB, pos);
        }
    }
    return false;
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

private static <A, B> HashMap<B, A> swapMap(HashMap<A, B> originalMap) {
    HashMap<B, A> newMap = new HashMap<B, A>();
    for (Map.Entry<A, B> entry : originalMap.entrySet()) {
        final B originalValue = entry.getValue();
        if (newMap.containsKey(originalValue)) {
            throw new IllegalArgumentException("value " + originalValue + " was already encountered");
        }/*from   w w  w. j  av  a2 s .  co  m*/
        newMap.put(originalValue, entry.getKey());
    }
    return newMap;
}

From source file:com.coinprism.model.APIClient.java

private void addQuantity(HashMap<String, BigInteger> map, String assetId, BigInteger quantity) {
    if (!map.containsKey(assetId))
        map.put(assetId, quantity);/*from   w  ww. j  av a 2s .  c  o  m*/
    else
        map.put(assetId, quantity.add(map.get(assetId)));
}

From source file:com.uber.hoodie.cli.commands.StatsCommand.java

@CliCommand(value = "stats filesizes", help = "File Sizes. Display summary stats on sizes of files")
public String fileSizeStats(@CliOption(key = {
        "partitionPath" }, help = "regex to select files, eg: 2016/08/02", unspecifiedDefaultValue = "*/*/*") final String globRegex)
        throws IOException {

    FileSystem fs = HoodieCLI.fs;
    String globPath = String.format("%s/%s/*", HoodieCLI.tableMetadata.getBasePath(), globRegex);
    FileStatus[] statuses = fs.globStatus(new Path(globPath));

    // max, min, #small files < 10MB, 50th, avg, 95th
    final int MAX_FILES = 1000000;
    Histogram globalHistogram = new Histogram(new UniformReservoir(MAX_FILES));
    HashMap<String, Histogram> commitHistoMap = new HashMap<String, Histogram>();
    for (FileStatus fileStatus : statuses) {
        String commitTime = FSUtils.getCommitTime(fileStatus.getPath().getName());
        long sz = fileStatus.getLen();
        if (!commitHistoMap.containsKey(commitTime)) {
            commitHistoMap.put(commitTime, new Histogram(new UniformReservoir(MAX_FILES)));
        }//ww w. ja  va  2s . co  m
        commitHistoMap.get(commitTime).update(sz);
        globalHistogram.update(sz);
    }

    String[][] rows = new String[commitHistoMap.size() + 1][];
    int ind = 0;
    for (String commitTime : commitHistoMap.keySet()) {
        Snapshot s = commitHistoMap.get(commitTime).getSnapshot();
        rows[ind++] = printFileSizeHistogram(commitTime, s);
    }
    Snapshot s = globalHistogram.getSnapshot();
    rows[ind++] = printFileSizeHistogram("ALL", s);

    return HoodiePrintHelper.print(
            new String[] { "CommitTime", "Min", "10th", "50th", "avg", "95th", "Max", "NumFiles", "StdDev" },
            rows);
}

From source file:com.thoughtworks.studios.journey.models.PropertyCollections.java

public Map<String, Set> properties(Node node) {
    HashMap<String, Set> result = new HashMap<>();
    Iterable<Relationship> relationships = node.getRelationships(propertyRelType(), Direction.OUTGOING);
    for (Relationship relationship : relationships) {
        String name = getName(relationship.getEndNode());
        if (!result.containsKey(name)) {
            result.put(name, new HashSet(1));
        }/*from  w  w  w  . j  a  v  a  2 s.  c  o  m*/
        Set values = result.get(name);
        //noinspection unchecked
        values.add(relationship.getProperty(REL_PROP_VALUE));
    }
    return result;
}

From source file:in.sc.main.CategoryController.java

@RequestMapping(value = { "{category:[a-zA-Z0-9-]+}/", "{category:[a-zA-Z0-9-]+}" })
public String getParseCat(Model model, @PathVariable String category, HttpServletRequest request,
        @RequestParam(required = false) String filterQ) {
    String unique_id = null;//w  w  w.j a  v  a  2  s.c  om
    String page = "error-404";
    int found = 0;
    HashMap inputMap = new HashMap();
    HashMap catPatternMap = daoutils.getCatPatternMap();
    try {
        if (catPatternMap.containsKey(category)) {
            LinkedList pList = (LinkedList) catPatternMap.get(category);
            inputMap.put(ProductHelper.category, pList.get(0));
            inputMap.put("filterQ", filterQ);
            page = productList(unique_id, model, inputMap);
        }
        if (request.getParameter("isAdmin") == null && page.equals("category_1")) {
            page = "category_2";
        }
        return page;
    } catch (Exception e) {
        e.printStackTrace();
        throw new CategoryController.ResourceNotFoundException();
    }
}