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:mysoft.sonar.plugins.web.check.StyleAttributeRegExpCheck.java

private void CheckStyleRules(TagNode node, HashMap<String, String> styles) {
    for (StyleRule styleRule : styleRules) {
        String attributeName = styleRule.name;
        if (!styles.containsKey(attributeName))
            continue;

        String value = styles.get(attributeName);
        String rule = styleRule.rule;
        Pattern pattern = Pattern.compile(rule);
        Matcher matcher = pattern.matcher(value);
        if (!matcher.find()) {
            createViolation(node.getStartLinePosition(),
                    "?" + attributeName + "???" + rule);
        }// www  .  ja  va2  s  .c  om
    }
}

From source file:controllers.MessagesController.java

@RequestMapping(value = "message", method = RequestMethod.GET)
public ModelAndView message(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
    ModelAndView model = new ModelAndView("page");
    model.addObject("content", "message");
    UserEntity ue = (UserEntity) session.getAttribute("user");
    ue = userService.findByID(ue.getId());
    List<MessageUserEntity> fta = ue.getMessageR();
    HashMap<String, List<MessageUserEntity>> hmmue = new HashMap<>();
    HashMap<String, Boolean> newMessages = new HashMap<>();
    for (MessageUserEntity mue : fta) {
        if (!newMessages.containsKey(mue.getMessage().getGroupName())) {
            newMessages.put(mue.getMessage().getGroupName(), mue.isNewMessage());
        } else if (mue.isNewMessage() == true) {
            newMessages.put(mue.getMessage().getGroupName(), mue.isNewMessage());
        }//w ww .  j ava2  s  .c  o m
        if (!hmmue.containsKey(mue.getMessage().getGroupName())) {
            hmmue.put(mue.getMessage().getGroupName(), mue.getMessage().getTarget());
        }

    }

    //List<FriendEntity> friends = ue.getFriends();
    /*friends.addAll(ue.getFriendedBy());*/
    model.addObject("groupList", hmmue);
    model.addObject("newMessageGroupList", newMessages);
    return model;
}

From source file:IOtweets.ReadingData.java

/**
 *
 * @param map/*  w  w w  . ja v a  2 s.  c  o m*/
 * @param count
 * @param id
 * @param text
 */
public void fillMap(HashMap<String, TweetData> map, int count, String id, String text, String time) {
    TweetData data = new TweetData();
    if (map.containsKey(id)) {
        data = map.get(id);
    }
    data.Time = data.Time == null ? time : data.Time;
    count = Math.max(count, data.ReTweetCount);
    data.ReTweetCount = count;
    data.Tweet = data.Tweet == null ? text : data.Tweet;
    map.put(id, data);
}

From source file:com.view.TimeSeriesChartView.java

private int updateItemMap(HashMap<Month, Integer> itemMap, Month theMonth, int quantity) {
    int quan = 0;
    if (itemMap.containsKey(theMonth)) {
        int temp = itemMap.get(theMonth);
        temp += quantity;/*from  w w  w. j  a v  a  2s  . co  m*/
        quan = temp;
    }
    return quan;
}

From source file:org.pentaho.platform.platform.osgi.requirejs.bindings.RequireJsConfigTest.java

@Test
public void testModuleMapping() throws Exception {

    RequireJsConfig requireJsConfig = mapper.readValue(new File("src/test/resources/testConfig.js"),
            RequireJsConfig.class);

    assertEquals("/Public/js", requireJsConfig.getBaseUrl());
    assertEquals(3, requireJsConfig.getWaitSeconds());
    HashMap<String, String> paths = requireJsConfig.getPaths();
    assertNotNull(paths);/*from  w  w w . j  a v a2  s  . c  o  m*/
    assertTrue(paths.size() > 0);
    assertTrue(paths.containsKey("jqueryui"));
    assertTrue(paths.containsKey("jquery"));
    assertEquals("../../Scripts/jquery-ui-1.10.2.min", paths.get("jqueryui"));
    assertEquals("../../Scripts/jquery-1.10.2.min", paths.get("jquery"));

    HashMap<String, Shim> shim = requireJsConfig.getShim();
    assertNotNull(shim);
    assertEquals(1, shim.size());

    Shim jqueryui = shim.get("jqueryui");
    assertNotNull(jqueryui);
    assertEquals(1, jqueryui.getDeps().length);
    assertEquals("jquery", jqueryui.getDeps()[0]);

    // Serialize it back out and then in again to compare.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    mapper.writeValue(outputStream, requireJsConfig);

    String serialized = new String(outputStream.toByteArray(), "UTF-8");

    RequireJsConfig configRoundTripped = mapper.readValue(serialized, RequireJsConfig.class);

    assertEquals(requireJsConfig, configRoundTripped);

}

From source file:controllers.MessagesController.java

@RequestMapping(value = "/message/{groupMessage}", method = RequestMethod.GET)
public ModelAndView message(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        @PathVariable String groupMessage) {
    ModelAndView model = new ModelAndView("page");
    model.addObject("content", "message");
    model.addObject("currentGroupMessage", groupMessage);
    UserEntity ue = (UserEntity) session.getAttribute("user");
    ue = userService.findByID(ue.getId());
    messageService.messageRead(ue, groupMessage);
    List<MessageUserEntity> fta = ue.getMessageR();
    HashMap<String, List<MessageUserEntity>> hmmue = new HashMap<>();
    List<MessageEntity> me = new ArrayList<>();
    HashMap<String, Boolean> newMessages = new HashMap<>();
    for (MessageUserEntity mue : fta) {
        if (!newMessages.containsKey(mue.getMessage().getGroupName())) {
            newMessages.put(mue.getMessage().getGroupName(), mue.isNewMessage());
        } else if (mue.isNewMessage() == true) {
            newMessages.put(mue.getMessage().getGroupName(), mue.isNewMessage());
        }/*from   ww  w . j  a  va  2 s  .  c  o m*/
        if (mue.getMessage().getGroupName().equals(groupMessage)) {
            me.add(mue.getMessage());
        }
        if (!hmmue.containsKey(mue.getMessage().getGroupName())) {
            hmmue.put(mue.getMessage().getGroupName(), mue.getMessage().getTarget());
        }

    }

    //List<FriendEntity> friends = ue.getFriends();
    /*friends.addAll(ue.getFriendedBy());*/
    model.addObject("groupList", hmmue);
    model.addObject("messages", me);
    model.addObject("newMessageGroupList", newMessages);

    return model;
}

From source file:org.eda.fpsrv.FPParams.java

public void setFromList(HashMap<String, String> params_) {
    FPProperty property;/*from ww  w  .j  ava2  s  .  c o m*/
    for (String key : properties.keySet()) {
        if (params_.containsKey(key)) {
            property = properties.get(key);
            property.setValue(params_.get(key));
        }
    }
}

From source file:com.michellemay.mappings.ISO639Alpha2Mapping.java

/**
 * Instantiates a new ISO 639 alpha 2 mapping.
 *//*from   w ww  .  j  a  v  a 2 s  .  c om*/
public ISO639Alpha2Mapping() {
    super(NAME);

    // Build reverse map
    HashMap<String, Locale> map = new HashMap<String, Locale>();
    for (String isoCode : Locale.getISOLanguages()) {
        if (isoCode.length() > 0) {
            String displayValue = isoCode.toLowerCase();
            if (!map.containsKey(displayValue)) {
                map.put(displayValue, LocaleUtils.toLocale(isoCode));
            }
        }
    }
    this.withMapping(map).withCaseSensitive(false);
}

From source file:ece356.UserDBAO.java

public static ArrayList<DoctorData> queryDoctor(HashMap<String, String> doctorParam, String user)
        throws ClassNotFoundException, SQLException {
    Connection con = null;/* ww w  .j  av a2s.c om*/
    PreparedStatement pstmt = null;
    ArrayList<DoctorData> ret;
    try {
        con = getConnection();
        String query;
        boolean reviewByFriends = false;
        if (doctorParam.containsKey("reviewByFriends")) {

            if (doctorParam.get("reviewByFriends").equals("yes")) {

                query = "select * from doctorSearchView where username in (select username from doctorSearchView left join review on doctorSearchView.doc_spec_username = review.doc_username where doctorSearchView.patient_username in "
                        + "(select friend.sent_username as friend "
                        + "from friend where friend.isAccepted = 1 AND friend.recieved_username like '%" + user
                        + "%'" + "union " + "select friend.recieved_username as friend "
                        + "from friend where friend.isAccepted = 1 AND friend.sent_username like '%" + user
                        + "%'))";
                reviewByFriends = true;
            } else {
                query = "SELECT * FROM doctorSearchView ";
            }
            doctorParam.remove("reviewByFriends");
        } else {
            query = "SELECT * FROM doctorSearchView ";
            //pstmt = con.prepareStatement(query);

        }
        // Query for general doctor information
        ArrayList<String> keys = new ArrayList<String>(doctorParam.keySet());
        ArrayList<String> values = new ArrayList<String>(doctorParam.values());

        HashMap<Integer, Integer> h1 = new HashMap<>();
        int counter = 0;
        if (!keys.isEmpty()) {
            counter++;
            if (!reviewByFriends)
                query = query + " where";
            else
                query = query + " AND";

            for (String key : keys) {
                if (key.equals("averageRating") || key.equals("yearsLicensed")) {
                    query = query + " " + key + " >= ?";
                    query += " AND";
                    h1.put(counter, counter);
                } else if (key.equals("gender")) {
                    query = query + " " + key + " = ?";
                    query += " AND";
                    h1.put(counter, counter);
                } else if (keys.equals("reviewByFriends")) {

                } else {
                    query = query + " " + key + " LIKE ?";
                    query += " AND";
                }
                counter++;
            }
            query = query.substring(0, query.length() - 4);
            System.out.println(query);
        }

        query += " group by first_name, last_name, gender, averageRating, numberOfReviews";

        pstmt = con.prepareStatement(query);

        if (!values.isEmpty()) {
            counter = 1;
            for (String value : values) {
                if (h1.containsKey(counter)) {
                    pstmt.setString(counter, value);
                } else {
                    pstmt.setString(counter, "%" + value + "%");
                }
                counter++;
            }
        }
        System.out.println(pstmt);
        ResultSet resultSet;
        resultSet = pstmt.executeQuery();

        ret = new ArrayList();

        while (resultSet.next()) {
            DoctorData doctor = new DoctorData();
            doctor.userName = resultSet.getString("username");
            doctor.firstName = resultSet.getString("first_name");
            doctor.middleInitial = resultSet.getString("middle_initial");
            doctor.lastName = resultSet.getString("last_name");
            doctor.gender = resultSet.getString("gender");
            doctor.averageRating = resultSet.getDouble("averageRating");
            doctor.numberOfReviews = resultSet.getInt("numberOfReviews");
            ret.add(doctor);
        }
        return ret;
    } catch (Exception e) {
        System.out.println("EXCEPTION:%% " + e);
    } finally {
        if (pstmt != null) {
            pstmt.close();
        }
        if (con != null) {
            con.close();
        }
    }
    return null;
}

From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java

/**
 * Gets counts for productions by (conceptually) summing over all the possible alignments
 * and weighing each alignment (and its constituent productions) by the given probability table.
 * probSum is important (and memoized for input word pairs)--it keeps track and returns the sum of the
 * probabilities of all possible alignments for the word pair
 *
 * This is Algorithm 3 in the paper.//from   w ww.j  a  v a  2  s  .c  o m
 *
 * @param word1
 * @param word2
 * @param maxSubstringLength1
 * @param maxSubstringLength2
 * @param probs
 * @param memoizationTable
 * @return a hashmap and double as a pair. The double is y, a normalization constant. The hashmap is a table of substring pairs
 * and their unnormalized counts
 */
public static Pair<HashMap<Production, Double>, Double> CountWeightedAlignmentsHelper(String word1,
        String word2, int maxSubstringLength1, int maxSubstringLength2, HashMap<Production, Double> probs,
        HashMap<Production, Pair<HashMap<Production, Double>, Double>> memoizationTable) {
    double probSum;

    Pair<HashMap<Production, Double>, Double> memoization;
    for (int orig = 0; orig < SPModel.numOrigins; orig++) {
        if (memoizationTable.containsKey(new Production(word1, word2, orig))) {
            memoization = memoizationTable.get(new Production(word1, word2, orig));
            probSum = memoization.getSecond(); //stored probSum
            return new Pair<>(memoization.getFirst(), probSum); //table of probs
        }
    }

    HashMap<Production, Double> result = new HashMap<>(); // this is C in Algorithm 3 in the paper
    probSum = 0; // this is R in Algorithm 3 in the paper

    if (word1.length() == 0 && word2.length() == 0) //record probabilities
    {
        probSum = 1; //null -> null is always a perfect alignment
        return new Pair<>(result, probSum); //end of the line
    }

    int maxSubstringLength1f = Math.min(word1.length(), maxSubstringLength1);
    int maxSubstringLength2f = Math.min(word2.length(), maxSubstringLength2);

    for (int orig = 0; orig < SPModel.numOrigins; orig++) {
        for (int i = 1; i <= maxSubstringLength1f; i++) //for each possible substring in the first word...
        {
            String substring1 = word1.substring(0, i);

            for (int j = 1; j <= maxSubstringLength2f; j++) //for possible substring in the second
            {
                if ((word1.length() - i) * maxSubstringLength2 >= word2.length() - j
                        && (word2.length() - j) * maxSubstringLength1 >= word1.length() - i) //if we get rid of these characters, can we still cover the remainder of word2?
                {
                    String substring2 = word2.substring(0, j);

                    Production production = new Production(substring1, substring2, orig);
                    double prob = probs.get(production);

                    // recurse here. Result is Q in Algorithm 3
                    Pair<HashMap<Production, Double>, Double> Q = CountWeightedAlignmentsHelper(
                            word1.substring(i), word2.substring(j), maxSubstringLength1, maxSubstringLength2,
                            probs, memoizationTable);

                    HashMap<Production, Double> remainderCounts = Q.getFirst();
                    Double remainderProbSum = Q.getSecond();

                    Dictionaries.IncrementOrSet(result, production, prob * remainderProbSum,
                            prob * remainderProbSum);

                    //update our probSum
                    probSum += remainderProbSum * prob;

                    //update all the productions that come later to take into account their preceding production's probability
                    for (Production key : remainderCounts.keySet()) {
                        Double value = remainderCounts.get(key);
                        Dictionaries.IncrementOrSet(result, key, prob * value, prob * value);
                    }
                }
            }
        }
    }

    for (int orig = 0; orig < SPModel.numOrigins; orig++) {
        memoizationTable.put(new Production(word1, word2, orig), new Pair<>(result, probSum));
    }
    return new Pair<>(result, probSum);
}