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:net.itransformers.idiscover.discoveryhelpers.xml.SnmpForXslt.java

public static String getDeviceType(String ipAddress, String neighbourIPDryRun) throws Exception {

    HashMap<String, String> deviceMap = discoveredIPs.get(ipAddress);

    if (neighbourIPDryRun.equals("true")) {

        if (deviceMap != null) {
            return null;
        }//  ww  w. ja v a 2 s .  com

    }

    String deviceType = null;
    if (deviceMap != null) {
        deviceType = deviceMap.get("deviceType");
    } else {
        return "UNKNOWN";
    }

    if ("".equals(deviceType) || deviceType == null) {
        return "UNKNOWN";
    } else {
        return deviceType;
    }

}

From source file:com.vertica.hivestoragehandler.VerticaOutputFormat.java

/**
  * Optionally called at the end of a job to optimize any newly created and
  * loaded tables. Useful for new tables with more than 100k records.
  * /* www  .  j  a va  2  s .c  o  m*/
  * @param conf
  * @throws Exception
  */
public static void optimize(Configuration conf) throws Exception {
    VerticaConfiguration vtconfig = new VerticaConfiguration(conf);
    Connection conn = vtconfig.getConnection(true);

    // TODO: consider more tables and skip tables with non-temp projections 
    VerticaRelation vTable = new VerticaRelation(vtconfig.getOutputTableName());
    Statement stmt = conn.createStatement();
    ResultSet rs = null;
    HashSet<String> tablesWithTemp = new HashSet<String>();

    //for now just add the single output table
    tablesWithTemp.add(vTable.getQualifiedName().toString());

    // map from table name to set of projection names
    HashMap<String, Collection<String>> tableProj = new HashMap<String, Collection<String>>();
    rs = stmt.executeQuery("select projection_schema, anchor_table_name, projection_name from projections;");
    while (rs.next()) {
        String ptable = rs.getString(1) + "." + rs.getString(2);
        if (!tableProj.containsKey(ptable)) {
            tableProj.put(ptable, new HashSet<String>());
        }

        tableProj.get(ptable).add(rs.getString(3));
    }

    for (String table : tablesWithTemp) {
        if (!tableProj.containsKey(table)) {
            throw new RuntimeException("Cannot optimize table with no data: " + table);
        }
    }

    String designName = (new Integer(conn.hashCode())).toString();
    stmt.execute("select dbd_create_workspace('" + designName + "')");
    stmt.execute("select dbd_create_design('" + designName + "', '" + designName + "')");
    stmt.execute("select dbd_add_design_tables('" + designName + "', '" + vTable.getQualifiedName().toString()
            + "')");
    stmt.execute("select dbd_populate_design('" + designName + "', '" + designName + "')");

    //Execute
    stmt.execute("select dbd_create_deployment('" + designName + "', '" + designName + "')");
    stmt.execute("select dbd_add_deployment_design('" + designName + "', '" + designName + "', '" + designName
            + "')");
    stmt.execute("select dbd_add_deployment_drop('" + designName + "', '" + designName + "')");
    stmt.execute("select dbd_execute_deployment('" + designName + "', '" + designName + "')");

    //Cleanup
    stmt.execute("select dbd_drop_deployment('" + designName + "', '" + designName + "')");
    stmt.execute("select dbd_remove_design('" + designName + "', '" + designName + "')");
    stmt.execute("select dbd_drop_design('" + designName + "', '" + designName + "')");
    stmt.execute("select dbd_drop_workspace('" + designName + "')");
}

From source file:com.evolveum.midpoint.common.policy.ValuePolicyGenerator.java

/**
 * Count cardinality/*w  ww. ja v a2s .  c o m*/
 */
private static HashMap<Integer, ArrayList<String>> cardinalityCounter(
        HashMap<StringLimitType, ArrayList<String>> lims, ArrayList<String> password, Boolean skipMatchedLims,
        boolean uniquenessReached, OperationResult op) {
    HashMap<String, Integer> counter = new HashMap<String, Integer>();

    for (StringLimitType l : lims.keySet()) {
        int counterKey = 1;
        ArrayList<String> chars = lims.get(l);
        int i = 0;
        if (null != password) {
            i = charIntersectionCounter(lims.get(l), password);
        }
        // If max is exceed then error unable to continue
        if (l.getMaxOccurs() != null && i > l.getMaxOccurs()) {
            OperationResult o = new OperationResult("Limitation check :" + l.getDescription());
            o.recordFatalError("Exceeded maximal value for this limitation. " + i + ">" + l.getMaxOccurs());
            op.addSubresult(o);
            return null;
            // if max is all ready reached or skip enabled for minimal skip
            // counting
        } else if (l.getMaxOccurs() != null && i == l.getMaxOccurs()) {
            continue;
            // other cases minimum is not reached
        } else if ((l.getMinOccurs() == null || i >= l.getMinOccurs()) && !skipMatchedLims) {
            continue;
        }
        for (String s : chars) {
            if (null == password || !password.contains(s) || uniquenessReached) {
                //               if (null == counter.get(s)) {
                counter.put(s, counterKey);
                //               } else {
                //                  counter.put(s, counter.get(s) + 1);
                //               }
            }
        }
        counterKey++;

    }

    // If need to remove disabled chars (already reached limitations)
    if (null != password) {
        for (StringLimitType l : lims.keySet()) {
            int i = charIntersectionCounter(lims.get(l), password);
            if (l.getMaxOccurs() != null && i > l.getMaxOccurs()) {
                OperationResult o = new OperationResult("Limitation check :" + l.getDescription());
                o.recordFatalError("Exceeded maximal value for this limitation. " + i + ">" + l.getMaxOccurs());
                op.addSubresult(o);
                return null;
            } else if (l.getMaxOccurs() != null && i == l.getMaxOccurs()) {
                // limitation matched remove all used chars
                LOGGER.trace("Skip " + l.getDescription());
                for (String charToRemove : lims.get(l)) {
                    counter.remove(charToRemove);
                }
            }
        }
    }

    // Transpone to better format
    HashMap<Integer, ArrayList<String>> ret = new HashMap<Integer, ArrayList<String>>();
    for (String s : counter.keySet()) {
        // if not there initialize
        if (null == ret.get(counter.get(s))) {
            ret.put(counter.get(s), new ArrayList<String>());
        }
        ret.get(counter.get(s)).add(s);
    }
    return ret;
}

From source file:edu.ucsb.nceas.metacat.util.RequestUtil.java

/**
 * Post a request and return the response body
 * //from  w  w w  . jav a 2  s.c om
 * @param httpClient
 *            The HttpClient to use in the post.  This is passed in because
  *            the same client may be used in several posts
 * @param url
 *            the url to post to
 * @param paramMap
 *            map of parameters to add to the post
 * @returns a string holding the response body
 */
public static String post(HttpClient httpClient, String url, HashMap<String, String> paramMap)
        throws IOException, HttpException {

    PostMethod method = new PostMethod(url);

    // Configure the form parameters
    if (paramMap != null) {
        Set<String> paramNames = paramMap.keySet();
        for (String paramName : paramNames) {
            method.addParameter(paramName, paramMap.get(paramName));
        }
    }

    // Execute the POST method
    int statusCode = httpClient.executeMethod(method);
    if (statusCode != -1) {
        String contents = method.getResponseBodyAsString();
        method.releaseConnection();
        return (contents);
    }

    return null;
}

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

/**
 * @param allWords/*from  w  ww .ja v a2 s  .  c  o  m*/
 *            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.savor.ads.core.ApiRequestFactory.java

private static JSONObject getJsonRequest(Object params, Session appSession) throws JSONException {
    if (params == null) {
        return new JSONObject();
    }// w  w  w  . ja va 2s.c  o  m

    HashMap<String, Object> requestParams;
    if (params instanceof HashMap) {
        requestParams = (HashMap<String, Object>) params;
    } else {
        return new JSONObject();
    }

    // add parameter node
    final Iterator<String> keySet = requestParams.keySet().iterator();
    JSONObject jsonParams = new JSONObject();

    try {
        while (keySet.hasNext()) {
            final String key = keySet.next();
            Object val = requestParams.get(key);
            if (val == null) {
                val = "";
            }
            if (val instanceof String || val instanceof Number || val == null) {
                jsonParams.accumulate(key, val);
            } else if (val instanceof List<?>) {
                jsonParams.accumulate(key, getJSONArray((List<?>) val));
            } else {
                jsonParams.accumulate(key, getJSONObject(val).toString());
            }
        }
        LogUtils.i("??:" + jsonParams.toString());
        //            return new StringEntity(DesUtils.encrypt(jsonParams.toString()), HTTP.UTF_8);
        return jsonParams;

    } catch (Exception e) {
        e.printStackTrace();
        return new JSONObject();
    }
}

From source file:edu.yale.cs.hadoopdb.sms.SQLQueryGenerator.java

/**
 * Takes the first column from expression
 *//*from w  w w  .  j a v  a 2s . c  om*/
private static String getColumnFromExpr(exprNodeDesc expr, HashMap<String, String> columnsMapping) {

    exprNodeDesc e = expr;

    if (e instanceof exprNodeColumnDesc) {
        exprNodeColumnDesc col = (exprNodeColumnDesc) e;

        String colStr = columnsMapping.get(col.getColumn());
        if (colStr == null) {
            colStr = col.getColumn();
        }

        return colStr;
    } else if (e instanceof exprNodeFuncDesc) {
        exprNodeFuncDesc func = (exprNodeFuncDesc) e;
        for (exprNodeDesc c : func.getChildExprs()) {
            if (c instanceof exprNodeColumnDesc) {
                exprNodeColumnDesc col = (exprNodeColumnDesc) c;

                String colStr = columnsMapping.get(col.getColumn());
                if (colStr == null) {
                    colStr = col.getColumn();
                }

                return colStr;
            }
        }
    }

    return null;
}

From source file:net.servicestack.client.Utils.java

public static <K, V> HashMap<K, ArrayList<V>> createMap(ArrayList<V> xs, Function<V, K> f) {
    HashMap<K, ArrayList<V>> to = new HashMap<K, ArrayList<V>>();
    if (xs == null)
        return to;

    for (V val : xs) {
        K key = f.apply(val);

        ArrayList<V> list = to.get(key);
        if (list == null)
            to.put(key, list = new ArrayList<V>());

        list.add(val);
    }/*w w  w  .j  a va 2  s.c  o  m*/

    return to;
}

From source file:com.krawler.esp.servlets.FileImporterServlet.java

public static void insertimportedtaskResources(String taskid, String resourcenames, HashMap restaskmap) {
    String[] resArray = resourcenames.split(",");
    ArrayList al = null;//w ww. j a va2  s. co  m
    for (int i = 0; i < resArray.length; i++) {
        String rid = resArray[i];
        if (restaskmap.containsKey(rid)) {
            al = (ArrayList) restaskmap.get(rid);
        } else {
            al = new ArrayList();
        }
        al.add(taskid);
        restaskmap.put(rid, al);
    }
}

From source file:edu.msu.cme.rdp.readseq.utils.RmDupSeqs.java

public static void filterDuplicates(String inFile, String outFile, int length, boolean debug)
        throws IOException {
    HashMap<String, String> idSet = new HashMap<String, String>();
    IndexedSeqReader reader = new IndexedSeqReader(new File(inFile));
    BufferedWriter outWriter = new BufferedWriter(new FileWriter(new File(outFile)));
    Set<String> allseqIDset = reader.getSeqIdSet();
    Sequence seq;/*from ww w  . j a  v a 2  s .c om*/
    if (debug) {
        System.out.println("ID\tdescription" + "\tcontained_by_ID\tdescription");
    }
    for (String id : allseqIDset) {
        seq = reader.readSeq(id);
        boolean dup = false;
        HashSet<String> tempdupSet = new HashSet<String>();
        for (String exID : idSet.keySet()) {
            String exSeq = idSet.get(exID);
            if (exSeq.length() >= seq.getSeqString().length()) {
                if (exSeq.contains(seq.getSeqString())) {
                    dup = true;
                    if (debug) {
                        Sequence temp = reader.readSeq(exID);
                        System.out.println(id + "\t" + seq.getDesc() + "\t" + exID + "\t" + temp.getDesc());
                    }
                    break;
                }
            } else if (seq.getSeqString().contains(exSeq)) {
                tempdupSet.add(exID);
            }
        }

        if (!dup) {
            idSet.put(id, seq.getSeqString());
        }
        for (String dupid : tempdupSet) {
            idSet.remove(dupid);
            if (debug) {
                Sequence temp = reader.readSeq(dupid);
                System.out.println(dupid + "\t" + temp.getDesc() + "\t" + id + "\t" + seq.getDesc());
            }
        }
    }
    // get the unique seq
    for (String id : idSet.keySet()) {
        seq = reader.readSeq(id);
        if (seq.getSeqString().length() >= length) {
            outWriter.write(">" + id + "\t" + seq.getDesc() + "\n" + seq.getSeqString() + "\n");
        }
    }
    reader.close();
    outWriter.close();
}