Example usage for java.util HashMap get

List of usage examples for java.util HashMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.adobe.sign.utils.validator.ApiValidatorHelper.java

/**
 * Function to validate a list of mandatory parameters.
 *./*from  w  w w  . j  a va  2s .c  o  m*/
 * @param hashMap The parameter List from which every parameter needs to be validated.
 * @throws ApiException
 */
public static void validateRequiredParameters(HashMap hashMap) throws ApiException {
    Set<String> keys = hashMap.keySet();
    for (String key : keys) {
        validateParameter(hashMap.get(key), key);
    }
}

From source file:com.symphony.jirabot.clients.QuandlClient.java

private static String mapToQueryString(HashMap<String, Object> parameters) {
    if (parameters == null || parameters.size() == 0) {
        return "";
    }/*from w  ww.  j a  v  a  2  s.c  o m*/

    StringBuilder queryString = new StringBuilder("&");
    for (String key : parameters.keySet()) {
        queryString.append(urlEncodeUTF8(key));
        queryString.append("=");
        queryString.append(urlEncodeUTF8(parameters.get(key).toString()));
        queryString.append("&");
    }

    if (queryString.charAt(queryString.length() - 1) == '&') {
        queryString = queryString.deleteCharAt(queryString.length() - 1);
    }

    return queryString.toString();
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateMultiRadioSelect.java

/**
 * Verifies if the hashmap, that contains the unique multi-radio button
 * select, is not empty and has no empty fields Which means that by default
 * all key entries must exist and be empty
 * /*from   w  w w .j a  v  a  2s . c om*/
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @param request
 * @return
 */
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {

    DynaActionForm form = (DynaActionForm) bean;
    HashMap hashMap = (HashMap) form.get(field.getProperty());
    if (hashMap.keySet().size() == 0) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return false;
    }
    Iterator iterator = hashMap.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        if (hashMap.get(key).equals("")) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
            return false;
        }
    }
    return true;
}

From source file:com.clustercontrol.repository.factory.AgentLibDownloader.java

/**
 * ????<BR>/*from  w  w  w. ja  va 2  s .com*/
 * 
 */
public static ArrayList<AgentStatusInfo> getAgentStatusList() throws HinemosUnknown {
    m_log.debug("getAgentStatusList() ");

    // ????
    List<String> ownerRoleIdList = new AccessControllerBean().getOwnerRoleIdList();

    HashMap<String, String> managerMap = getAgentLibMap();
    ArrayList<AgentStatusInfo> ret = new ArrayList<AgentStatusInfo>();
    for (AgentInfo agentInfo : AgentConnectUtil.getAgentList()) {
        // ID
        String facilityId = agentInfo.getFacilityId();
        if (facilityId == null) {
            continue;
        }
        AgentStatusInfo agent = null;
        agent = new AgentStatusInfo();
        agent.setFacilityId(facilityId);

        // ??
        String facilityName = "";
        try {
            // ID??????????????
            String ownerRoleId = NodeProperty.getProperty(facilityId).getOwnerRoleId();
            if (!ownerRoleIdList.contains(ownerRoleId)) {
                m_log.debug("getAgentStatusList() : not ownerRole facilityId = " + facilityId);
                continue;
            }
            m_log.debug("getAgentStatusList() : ownerRole facilityId = " + facilityId);
            facilityName = NodeProperty.getProperty(facilityId).getFacilityName();
        } catch (FacilityNotFound e) {
            // ???????????????
            m_log.info("getAgentStatusList() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
            continue;
        }
        agent.setFacilityName(facilityName);

        // startup time
        agent.setStartupTime(agentInfo.getStartupTime());

        // last login
        agent.setLastLogin(agentInfo.getLastLogin());

        // multiplicity
        int runningMultiplicity = JobMultiplicityCache.getRunningMultiplicity(facilityId);
        int waitMultiplicity = JobMultiplicityCache.getWaitMultiplicity(facilityId);
        /*
        running,wait,max?3??????????max????
        int maxMultiplicity = 0;
        try {
           maxMultiplicity = new RepositoryControllerBean().getNode(facilityId).getJobMultiplicity();
        } catch (FacilityNotFound e) {
           m_log.debug(e.getMessage(), e);
        } catch (HinemosUnknown e) {
           m_log.debug(e.getMessage(), e);
        }
         */
        agent.setMultiplicity("run=" + runningMultiplicity + ",wait=" + waitMultiplicity);

        // ?
        boolean flag = true;
        HashMap<String, String> agentMap = AgentConnectUtil.getAgentLibMd5(facilityId);
        for (Map.Entry<String, String> filenameEntry : managerMap.entrySet()) {
            String agentMd5 = agentMap.get(filenameEntry.getKey());
            String managerMd5 = filenameEntry.getValue();
            // ?????????????????????
            // ????
            if (agentMd5 == null) {
                m_log.info("getAgentStatusList() agentMd5 is null + [" + facilityId + "] filename="
                        + filenameEntry.getKey());
                flag = false;
                break;
            }
            if (!agentMd5.equals(managerMd5)) {
                m_log.debug("getAgentStatusList() agentMd5 differs from managerMd5 [" + facilityId
                        + "] filename=" + filenameEntry.getKey() + ", managerMd5=" + managerMd5 + ", agentMd5="
                        + agentMd5);
                flag = false;
                break;
            }
        }
        agent.setNewFlag(flag);

        ret.add(agent);
    }
    return ret;
}

From source file:StringUtilities.java

/**
 * A directive is a parameter of the digest authentication process.
 * Returns the value of a directive from the map. If mandatory is true and the 
 * value is null, then it throws an {@link AuthenticationException}.
 *  //from   ww  w .ja  va 2 s . c om
 * @param directivesMap the directive's map 
 * @param directive the name of the directive we want to retrieve
 * @param mandatory is the directive mandatory
 * @return the mandatory value as a String
 * @throws AuthenticationException if mandatory is true and if 
 * directivesMap.get(directive) == null
 */
public static String getDirectiveValue(HashMap<String, String> directivesMap, String directive,
        boolean mandatory) throws AuthenticationException {
    String value = directivesMap.get(directive);
    if (value == null) {
        if (mandatory) {
            throw new AuthenticationException("\"" + directive + "\" mandatory directive is missing");
        }

        return "";
    }

    return value;
}

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 {//from  w  w w. ja  v  a 2  s .c o  m
        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:Main.java

public static String addAttributes(HashMap<String, String> p_attributes) {
    StringBuffer l_buf = null;/* ww w . j  a va 2  s .  c  o  m*/
    Iterator<String> l_iter = null;
    String l_name = null;

    if (p_attributes != null) {
        l_buf = new StringBuffer();
        l_iter = p_attributes.keySet().iterator();
        while (l_iter.hasNext()) {
            l_name = l_iter.next();
            l_buf.append(" ").append(l_name).append("=\"");
            l_buf.append(p_attributes.get(l_name)).append("\"");
        }

        return l_buf.toString();
    }

    return "";
}

From source file:org.jdbcluster.dao.Dao.java

/**
 * creates new instance of a Dao using given Dao class
 * @param daoClass class of Object to create
 * @return created dao instance//from  ww w.j av  a2 s .  c  o m
 */
public static Object newInstance(Class<?> daoClass) {
    Object dao = JDBClusterUtil.createClassObject(daoClass);
    //get property of DAO and initial value from jdbcluster.dao.conf.xml
    HashMap<String, String> hm;
    synchronized (classToPropsMap) {
        hm = classToPropsMap.get(daoClass);
        if (hm == null)
            hm = putCacheMap(daoClass);
    }

    BeanWrapper beanWrapper = new BeanWrapperImpl();
    beanWrapper.setWrappedInstance(dao);

    for (String prop : hm.keySet()) {
        String value = hm.get(prop);
        //get property of DAO
        Class<?> propClass = beanWrapper.getPropertyType(prop);
        //convert to Type if necessary
        Object o = beanWrapper.convertIfNecessary(value, propClass);
        //set the value of the predefined property read from jdbcluster.dao.conf.xml
        beanWrapper.setPropertyValue(new PropertyValue(prop, o));
    }
    return dao;
}

From source file:plugins.marauders.MaraudersInteractor.java

public static Data getData() {
    StringBuilder json = new StringBuilder();
    try {/*from w  w w.j  a  v  a 2 s. co  m*/
        URL server = new URL("http://s40server.csse.rose-hulman.edu:9200/marauders/data/0");
        URLConnection yc = server.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null && inputLine != "") {
            System.out.println(inputLine);
            json.append(inputLine);
        }

        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() {
    };
    try {
        HashMap<String, Object> map = mapper.readValue(json.toString(), typeReference);
        HashMap<String, Object> source = (HashMap) map.get("_source");
        Data d = new Data();
        d.setLastStudentID(Integer.parseInt((String) source.get("lastStudentID")));
        d.setMaxInsultID(Integer.parseInt((String) source.get("maxInsultID")));
        d.setPassphrase((String) source.get("passphrase"));
        return d;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

}

From source file:Main.java

/**
 * Method that merges 2 data structures into 1
 * /*from  www.  java  2 s  .c  om*/
 * @param featureSet:
 *            the structure containing all features
 * @param featureSet2:
 *            the structure containing Pairwise Correlation features
 * @return the concatenated data structure
 */
public static HashMap<Integer, ArrayList<HashMap<String, Double>>> mergeStructures(
        HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet,
        ArrayList<ArrayList<HashMap<String, Double>>> featureSet2) {

    HashMap<Integer, ArrayList<HashMap<String, Double>>> featureSet_final = new HashMap<Integer, ArrayList<HashMap<String, Double>>>();

    for (int i = 0; i < featureSet.size(); i++) {
        ArrayList<HashMap<String, Double>> featuresPerChann = featureSet.get(i);
        ArrayList<HashMap<String, Double>> featuresPerChann2 = featureSet2.get(i);
        if (featuresPerChann2 == null)
            continue;

        ArrayList<HashMap<String, Double>> featuresPerChann_final = new ArrayList<HashMap<String, Double>>();

        for (int ii = 0; ii < featuresPerChann.size(); ii++) {
            HashMap<String, Double> h1 = new HashMap<String, Double>();
            HashMap<String, Double> h2 = new HashMap<String, Double>();
            // System.out.println("s:: "+String.format("%03d", ii));
            h1 = featuresPerChann.get(ii);
            for (int j = 0; j < featuresPerChann2.size(); j++) {
                h2 = featuresPerChann2.get(j);
                // System.out.println("h2:"+h2);
                String s = h2.keySet().toString();

                if (s.contains("s" + String.format("%04d", ii))) {
                    // System.out.println("sss"+s.substring(1,14));
                    String new_s = s.substring(1, 17);
                    if (h2.get(new_s) != null) {
                        double v = h2.get(new_s);
                        HashMap<String, Double> h = new HashMap<String, Double>();
                        h.put(new_s.substring(0, 11), v);
                        h1.putAll(h);
                    }
                }
            }
            featuresPerChann_final.add(h1);

        }
        featureSet_final.put(i, featuresPerChann_final);
    }

    return featureSet_final;
}