Example usage for java.util LinkedHashMap containsValue

List of usage examples for java.util LinkedHashMap containsValue

Introduction

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

Prototype

public boolean containsValue(Object value) 

Source Link

Document

Returns true if this map maps one or more keys to the specified value.

Usage

From source file:Main.java

public static void main(String[] args) {
    LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>();

    lHashMap.put("1", "One");
    lHashMap.put("2", "Two");
    lHashMap.put("3", "Three");

    boolean blnExists = lHashMap.containsValue("Two");
    System.out.println(blnExists);
}

From source file:gov.nih.nci.cabig.caaers.web.ae.AdverseEventCaptureTab.java

@Override
protected void validate(CaptureAdverseEventInputCommand command, BeanWrapper commandBean,
        Map<String, InputFieldGroup> fieldGroups, Errors errors) {
    Term aeTerminologyTerm = command.getStudy().getAeTerminology().getTerm();

    boolean ctcTerminology = aeTerminologyTerm == null ? false : aeTerminologyTerm == Term.CTC;
    boolean meddraTerminology = aeTerminologyTerm == null ? false : aeTerminologyTerm == Term.MEDDRA;

    short i = 0;/*  www  .  java  2  s.com*/
    for (AdverseEvent ae : command.getAdverseEventReportingPeriod().getAdverseEvents()) {
        if (ae.isRetired()) {
            i++;
            continue;
        }
        if (isFieldRequired(ae, "adverseEvents[].adverseEventCtcTerm.term")) {
            if (ae.getAdverseEventTerm() == null || ae.getAdverseEventTerm().getTerm() == null) {
                if (ctcTerminology) {
                    errors.rejectValue("adverseEvents[" + i + "].ctcTerm", "SAE_045",
                            new Object[] { ae.getDetailsForOther() }, "");
                }
                if (meddraTerminology) {
                    errors.rejectValue("adverseEvents[" + i + "].meddraTerm", "SAE_045",
                            new Object[] { ae.getDetailsForOther() }, "");
                }

            }
        }

        if (isFieldRequired(ae, "adverseEvents[].detailsForOther")) {
            if (StringUtils.isEmpty(ae.getDetailsForOther())) {
                errors.rejectValue("adverseEvents[" + i + "].detailsForOther", "CAE_018", "Missing Verbatim");
            }
        }

        i++;
    }

    if (command.getStudy().getAeTermUnique()) {

        // START -> AE VALIDATION //
        AdverseEvent adverseEvent = checkAEsUniqueness(command);
        if (adverseEvent != null) {
            String name = adverseEvent.getDisplayName();
            errors.reject("DUPLICATE_EXPECTED_AE", new Object[] { name }, "ERR.");
        }
        // STOP -> AE VALIDATION //

    }

    boolean foundGrade5 = false;

    i = 0;
    for (AdverseEvent ae : command.getAdverseEventReportingPeriod().getAdverseEvents()) {
        if (ae.isRetired()) {
            i++;
            continue;
        }

        if (ae.getGrade() != null && ae.getGrade().equals(Grade.DEATH)) {
            if (foundGrade5) {
                errors.rejectValue("adverseEvents[" + i + "].grade", "SAE_033",
                        "Only one adverse event with grade DEATH is allowed in a course.");
            }
            foundGrade5 = true;
        }

        // CHECKING VERBATIM LENGTH
        if (ae.getDetailsForOther() != null && ae.getDetailsForOther().length() > VERBATIM_MAX_SIZE) {
            errors.rejectValue("adverseEvents[" + i + "].detailsForOther", "SAE_021",
                    new Object[] { VERBATIM_MAX_SIZE },
                    "The size of the verbatim value should not exceed " + VERBATIM_MAX_SIZE + " characters.");
        }

        if (caaersFieldConfigurationManager.isFieldMandatory(TAB_NAME, "adverseEvents[].gradedDate")
                && ae.getGradedDate() == null) {
            errors.rejectValue("adverseEvents[" + i + "].gradedDate", "CAE_023",
                    "The \"Awareness date\" can not be blank. It should be either be the same day as \"Start date\" or today when \"Start date\" is unknown.");
        }

        //Check if Graded Date is lesser than Start Date
        if (caaersFieldConfigurationManager.isFieldApplicable(TAB_NAME, "adverseEvents[].startDate")
                && caaersFieldConfigurationManager.isFieldApplicable(TAB_NAME, "adverseEvents[].gradedDate")) {
            if (ae.getStartDate() != null && ae.getGradedDate() != null
                    && (DateUtils.compareDate(ae.getStartDate(), ae.getGradedDate()) > 0)) {
                errors.rejectValue("adverseEvents[" + i + "].gradedDate", "CAE_021",
                        "The \"Awareness date\" can not be before the \"Start date\". It should be either be the same day or later.");
            }
        }

        // Check if end date is greater than the start date
        if (caaersFieldConfigurationManager.isFieldApplicable(TAB_NAME, "adverseEvents[].startDate")
                && caaersFieldConfigurationManager.isFieldApplicable(TAB_NAME, "adverseEvents[].endDate"))
            if (ae.getEndDate() != null && ae.getStartDate() != null
                    && DateUtils.compareDate(ae.getStartDate(), ae.getEndDate()) > 0)
                errors.rejectValue("adverseEvents[" + i + "].endDate", "CAE_014",
                        "The \"End date\" can not be before the \"Start date\". It should be either be the same day or later.");

        // Check if start date of course is greater than the start date of the ae.
        //if(command.getAdverseEventReportingPeriod().getStartDate() != null && ae.getStartDate() != null &&
        //      DateUtils.compareDate(command.getAdverseEventReportingPeriod().getStartDate(), ae.getStartDate()) > 0)
        //   errors.rejectValue("adverseEvents[" + i + "].startDate", "CAE_015");

        // Special validation for outcomes as it cannot be validated through the fieldgroup framework.

        if (caaersFieldConfigurationManager.isFieldMandatory(TAB_NAME, "adverseEvents[].outcomes")
                && !ae.getSolicited()) {
            LinkedHashMap<Integer, Boolean> oneOutcomeMap = (LinkedHashMap<Integer, Boolean>) command
                    .getOutcomes().get(i);
            if (oneOutcomeMap == null || !oneOutcomeMap.containsValue(Boolean.TRUE)) {
                errors.rejectValue("adverseEvents[" + i + "].outcomes", "CAE_016", "Missing outcomes.");
            }
        }

        if (caaersFieldConfigurationManager.isFieldMandatory(TAB_NAME,
                "adverseEvents[].eventApproximateTime.hourString") && !ae.getSolicited()) {
            if (ae.getEventApproximateTime() == null || ae.getEventApproximateTime().getHourString() == null)
                errors.rejectValue("adverseEvents[" + i + "].eventApproximateTime.hourString", "CAE_019",
                        "Missing event hour.");
        }

        if (caaersFieldConfigurationManager.isFieldMandatory(TAB_NAME,
                "adverseEvents[].eventApproximateTime.minuteString") && !ae.getSolicited()) {
            if (ae.getEventApproximateTime() == null || ae.getEventApproximateTime().getMinuteString() == null)
                errors.rejectValue("adverseEvents[" + i + "].eventApproximateTime.minuteString", "CAE_020",
                        "Missing event minute.");
        }
        i++;
    }

    command.setErrorsForFields(new HashMap<String, Boolean>());
    WebUtils.populateErrorFieldNames(command.getErrorsForFields(), errors);
}

From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java

public void testContainsValue() {
    LinkedHashMap<String, Integer> hashMap = new LinkedHashMap<String, Integer>();
    checkEmptyLinkedHashMapAssumptions(hashMap);

    assertFalse("check contains of empty map", hashMap.containsValue(VALUE_TEST_CONTAINS_KEY));
    hashMap.put(KEY_TEST_CONTAINS_VALUE, VALUE_TEST_CONTAINS_KEY);
    assertTrue("check contains of map with element", hashMap.containsValue(VALUE_TEST_CONTAINS_KEY));
    assertFalse("check contains of map other element",
            hashMap.containsValue(VALUE_TEST_CONTAINS_DOES_NOT_EXIST));

    assertFalse(hashMap.containsValue(null));
    hashMap.put(KEY_TEST_CONTAINS_VALUE, null);
    assertTrue(hashMap.containsValue(null));
}

From source file:com.concursive.connect.web.modules.members.portlets.InviteMembersPortlet.java

private LinkedHashMap<String, String> updateMemberList(ActionRequest request, String member, String id,
        LinkedHashMap<String, String> memberMap, LinkedHashMap<String, String> memberPresentMap) {
    //return if the id passed is not valid or empty
    if (NO_MATCH_FOUND.equals(id) || !StringUtils.hasText(id)) {
        return memberMap;
    }//from  ww  w .  j a  v a2 s  . c om

    LinkedHashMap<String, String> members = new LinkedHashMap<String, String>(memberMap);
    //remove the entry if the userid(s) was already added
    if (members.containsValue(id)) {
        members.remove(member);
        return members;
    }

    User currentUser = PortalUtils.getUser(request);
    Project currentProject = PortalUtils.getProject(request);

    String arrUserId[] = id.split(",");
    String userIds = "";
    for (String userId : arrUserId) {
        //discard the userid if added before
        if (members.containsValue(userId)) {
            continue;
        }
        //discard the userid if its the current user
        if (Integer.parseInt(userId) == currentUser.getId()) {
            continue;
        }
        //discard the userid if the user is already a member
        if (currentProject.getTeam().getTeamMember(Integer.parseInt(userId)) != null) {
            continue;
        }

        userIds += userId + ",";
    }
    userIds = DimDimUtils.trimComma(userIds);

    //check if there are ids not discarded
    if (StringUtils.hasText(userIds)) {
        //if its not a multi match then check if the user was previous added to any multi match list.
        if (arrUserId.length == 1) {
            checkDuplicates(members, member, userIds);
        }
        members.put(member, userIds);
    } else {
        //remove from the member list if its not a multi match
        if (arrUserId.length == 1) {
            memberPresentMap.put(member, id);
            members.remove(member);
        } else {
            members.put(member, NO_MATCH_FOUND);
        }
    }
    return members;
}

From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java

/**
 * Test method for 'java.util.LinkedHashMap.putAll(Map)'.
 *///  w w w  . j  a  v a 2 s. c om
public void testPutAll() {
    LinkedHashMap<String, String> srcMap = new LinkedHashMap<String, String>();
    checkEmptyLinkedHashMapAssumptions(srcMap);

    srcMap.put(KEY_1, VALUE_1);
    srcMap.put(KEY_2, VALUE_2);
    srcMap.put(KEY_3, VALUE_3);

    // Make sure that the data is copied correctly
    LinkedHashMap<String, String> dstMap = new LinkedHashMap<String, String>();
    checkEmptyLinkedHashMapAssumptions(dstMap);

    dstMap.putAll(srcMap);
    assertEquals(srcMap.size(), dstMap.size());
    assertTrue(dstMap.containsKey(KEY_1));
    assertTrue(dstMap.containsValue(VALUE_1));
    assertFalse(dstMap.containsKey(KEY_1.toUpperCase(Locale.ROOT)));
    assertFalse(dstMap.containsValue(VALUE_1.toUpperCase(Locale.ROOT)));

    assertTrue(dstMap.containsKey(KEY_2));
    assertTrue(dstMap.containsValue(VALUE_2));
    assertFalse(dstMap.containsKey(KEY_2.toUpperCase(Locale.ROOT)));
    assertFalse(dstMap.containsValue(VALUE_2.toUpperCase(Locale.ROOT)));

    assertTrue(dstMap.containsKey(KEY_3));
    assertTrue(dstMap.containsValue(VALUE_3));
    assertFalse(dstMap.containsKey(KEY_3.toUpperCase(Locale.ROOT)));
    assertFalse(dstMap.containsValue(VALUE_3.toUpperCase(Locale.ROOT)));

    // Check that an empty map does not blow away the contents of the
    // destination map
    LinkedHashMap<String, String> emptyMap = new LinkedHashMap<String, String>();
    checkEmptyLinkedHashMapAssumptions(emptyMap);
    dstMap.putAll(emptyMap);
    assertTrue(dstMap.size() == srcMap.size());

    // Check that put all overwrite any existing mapping in the destination map
    srcMap.put(KEY_1, VALUE_2);
    srcMap.put(KEY_2, VALUE_3);
    srcMap.put(KEY_3, VALUE_1);

    dstMap.putAll(srcMap);
    assertEquals(dstMap.size(), srcMap.size());
    assertEquals(dstMap.get(KEY_1), VALUE_2);
    assertEquals(dstMap.get(KEY_2), VALUE_3);
    assertEquals(dstMap.get(KEY_3), VALUE_1);

    // Check that a putAll does adds data but does not remove it

    srcMap.put(KEY_4, VALUE_4);
    dstMap.putAll(srcMap);
    assertEquals(dstMap.size(), srcMap.size());
    assertTrue(dstMap.containsKey(KEY_4));
    assertTrue(dstMap.containsValue(VALUE_4));
    assertEquals(dstMap.get(KEY_1), VALUE_2);
    assertEquals(dstMap.get(KEY_2), VALUE_3);
    assertEquals(dstMap.get(KEY_3), VALUE_1);
    assertEquals(dstMap.get(KEY_4), VALUE_4);

    dstMap.putAll(dstMap);
}

From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerActions.java

/**
 * For the given server with serverKey ID, takes his {@link #getBaseLogListFrom(String)}
 * reply as toProcessLogList and fill the serversLogPresenceList for each base log
 * adding the serverKey to the list of presence for that base log.
 * /*from w w w  .j  a v  a  2s . c  o  m*/
 * If finalLogList is not null, also adds the missing entries to it.
 * 
 * @param serverKey
 * @param toProcessLogList
 * @param finalLogList
 * @param serversLogPresenceList
 */
private void fillServerPresenceList(String serverKey, LinkedHashMap<FTPFile, String> toProcessLogList,
        LinkedHashMap<FTPFile, String> finalLogList, LinkedHashMap<String, String> serversLogPresenceList) {

    if (toProcessLogList != null && !toProcessLogList.isEmpty()) {
        if (finalLogList == null || finalLogList.isEmpty()) {
            for (String partialUri : toProcessLogList.values()) {
                serversLogPresenceList.put(partialUri, serverKey);
            }
            if (finalLogList != null)
                finalLogList.putAll(toProcessLogList);
        } else {
            for (FTPFile ftpFile : toProcessLogList.keySet()) {
                String val = toProcessLogList.get(ftpFile);
                if (finalLogList.containsValue(val)) {
                    serversLogPresenceList.put(val, serversLogPresenceList.get(val) + " " + serverKey);
                    continue;
                } else {
                    finalLogList.put(ftpFile, val);
                    serversLogPresenceList.put(val, serverKey);
                }
            }
        }
    }
}

From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerActions.java

private void setStateLocalIfNotInPresentServer(LinkedHashMap<FTPFile, String> retList) {
    long timeC1 = System.currentTimeMillis();

    Object[] objArray = new Object[gui.logFolderList.myModel.size()];
    gui.logFolderList.myModel.copyInto(objArray);
    for (Object comp : objArray) {
        if (stopLogListProcessing)
            break;

        try {/*w w  w  . j  a  va  2s  .co  m*/
            // NeptusLog.pub().info("<###>... upda
            LogFolderInfo log = (LogFolderInfo) comp;
            if (!retList.containsValue(log.getName())) {
                // retList.remove(log.getName());
                for (LogFileInfo lfx : log.getLogFiles()) {
                    if (stopLogListProcessing)
                        break;
                    lfx.setState(LogFolderInfo.State.LOCAL);
                }
                log.setState(LogFolderInfo.State.LOCAL);
            }
        } catch (Exception e) {
            NeptusLog.pub().debug(e.getMessage());
        }
    }
    NeptusLog.pub().warn(".......Removing from already existing LogFolders to LOCAL state "
            + (System.currentTimeMillis() - timeC1) + "ms");
}