Example usage for java.util HashMap put

List of usage examples for java.util HashMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:Main.java

/**
 * Get all attributes as a Map from a node
 *
 * @param node the node taht contains the attributes to read
 * @return the values or a empty map/*w w w .  j av  a2  s  . c  o m*/
 */
public static HashMap<String, String> getAttributes(Node node) {
    final HashMap<String, String> result = new HashMap<>();

    final NamedNodeMap atts = node.getAttributes();
    for (int i = 0; i < atts.getLength(); i++) {
        final Node att = atts.item(i);
        result.put(att.getNodeName(), att.getNodeValue());
    }
    return result;
}

From source file:com.baasbox.service.storage.StatisticsService.java

public static ImmutableMap db() {
    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method Start");
    ODatabaseRecordTx db = DbHelper.getConnection();
    HashMap dbProp = new HashMap();
    HashMap map = new HashMap();
    dbProp.put("version", OConstants.getVersion());
    dbProp.put("url", OConstants.ORIENT_URL);
    if (db != null) {
        if (BBConfiguration.getStatisticsSystemOS())
            dbProp.put("path", db.getStorage().getConfiguration().getDirectory());
        else//from   www.  j  a  v  a 2s  .  c o  m
            dbProp.put("path", "N/A");
        dbProp.put("timezone", db.getStorage().getConfiguration().getTimeZone());
        dbProp.put("locale.language", db.getStorage().getConfiguration().getLocaleLanguage());
        dbProp.put("locale.country", db.getStorage().getConfiguration().getLocaleCountry());
        map.put("status", db.getStatus());
    }
    map.put("properties", dbProp);
    map.put("configuration", dbConfiguration());
    map.put("physical_size", DbHelper.getDBTotalSize());
    map.put("datafile_freespace", DbHelper.getDBStorageFreeSpace());
    map.put("size_threshold_percentage", BBConfiguration.getDBAlertThreshold());

    ImmutableMap response = ImmutableMap.builder().build().copyOf(map);

    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method End");
    return response;
}

From source file:com.openkm.util.ImageUtils.java

/**
 * Execute ImageMagick convert with parameters.
 *//*from   w w w . j  a va  2s.c  o  m*/
public static void ImageMagickConvert(String input, String output, String params) {
    log.debug("ImageMagickConvert({}, {}, {})", new Object[] { input, output, params });
    String cmd = null;

    try {
        HashMap<String, Object> hm = new HashMap<String, Object>();
        hm.put("fileIn", input);
        hm.put("fileOut", output);
        String tpl = Config.SYSTEM_IMAGEMAGICK_CONVERT + " " + params;
        cmd = TemplateUtils.replace("IMAGE_CONVERT", tpl, hm);
        ExecutionResult er = ExecutionUtils.runCmd(cmd);

        if (er.getExitValue() != 0) {
            throw new RuntimeException(er.getStderr());
        }
    } catch (SecurityException e) {
        throw new RuntimeException("Security exception executing command: " + cmd, e);
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted exception executing command: " + cmd, e);
    } catch (IOException e) {
        throw new RuntimeException("IO exception executing command: " + cmd, e);
    } catch (TemplateException e) {
        throw new RuntimeException("Template exception", e);
    }
}

From source file:Main.java

/**
 * Processes the POST request from the client instructing the server to process 
 * a serverStart or serverProxy. Returns the fields in this request as a HashMap for
 * easy handling.//from ww  w  . ja  v  a  2s .  co  m
 * 
 * @param xmlStream the InputStream obtained from an HttpServletRequest object. This contains the desired pipeline from the client.
 * @param search a HashMap with arbitrary names as keys and XPath Strings as values, the results of which are assigned as values to the names in the returned HashMap. 
 * @return
 */
public static HashMap<String, String> procPipelineReq(InputStream xmlStream, HashMap<String, String> search) {
    HashMap<String, String> returnHash = new HashMap<String, String>();
    try {
        for (String item : search.keySet()) {
            Document xmlDoc = parse(xmlStream);
            XPath xpath = xpathFactory.newXPath();
            returnHash.put(item, xpath.evaluate(search.get(item), xmlDoc));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return returnHash;
}

From source file:Main.java

public static Map<String, String> asMap(String[][] args) {
    HashMap<String, String> result = new HashMap<String, String>();
    if (args != null) {
        for (int i = 0; i < args.length; ++i) {
            String key = args[i][0];
            String value = args[i][1];
            result.put(key, value);
        }//from ww  w  .j a v  a  2  s.co m
    }
    return result;
}

From source file:fr.paris.lutece.plugins.seo.service.RuleFileService.java

/**
 * Generate the rule file content//  w  w w  . j av  a 2s .  co  m
 * @return The file content
 */
private static String generateFileContent() {
    HashMap model = new HashMap();
    Collection<UrlRewriterRule> listRules = UrlRewriterRuleHome.findAll();
    List<FriendlyUrl> listUrl = FriendlyUrlHome.findAll();

    model.put(MARK_RULES_LIST, listRules);
    model.put(MARK_URL_LIST, listUrl);

    HtmlTemplate t = AppTemplateService.getTemplate(TEMPLATE_FILE, Locale.getDefault(), model);

    String strResult = "OK";
    String strDate = DateFormat.getDateTimeInstance().format(new Date());
    Object[] args = { strDate, listRules.size() + listUrl.size(), strResult };
    String strLogFormat = I18nService.getLocalizedString(PROPERTY_REWRITE_CONFIG_LOG, Locale.getDefault());
    String strLog = MessageFormat.format(strLogFormat, args);
    DatastoreService.setDataValue(SEODataKeys.KEY_REWRITE_CONFIG_UPDATE, strLog);
    DatastoreService.setDataValue(SEODataKeys.KEY_CONFIG_UPTODATE, DatastoreService.VALUE_TRUE);

    return t.getHtml();
}

From source file:Main.java

public static HashMap<String, Element> createIndex(Element root, String tagName, String idName) {
    NodeList nodes = root.getElementsByTagName(tagName);
    HashMap<String, Element> index = new HashMap<>(nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element el = (Element) nodes.item(i);
        String key = el.getAttribute(idName);
        if (!key.isEmpty())
            index.put(key, el);
    }//  w w  w .j  a va  2s  .com
    return index;
}

From source file:com.opengamma.analytics.util.amount.SurfaceValue.java

/**
 * Builder from on point.//w  ww .  j a  v a2  s.  c  om
 * @param point The surface point.
 * @param value The associated value.
 * @return The surface value.
 */
public static SurfaceValue from(final DoublesPair point, final Double value) {
    ArgumentChecker.notNull(point, "Point");
    final HashMap<DoublesPair, Double> data = new HashMap<>();
    data.put(point, value);
    return new SurfaceValue(data);
}

From source file:com.microsoftopentechnologies.windowsazurestorage.helper.Utils.java

public static OperationContext updateUserAgent() throws IOException {

    String userInfo = BaseRequest.getUserAgent();
    String version = null;//from w  ww  .  j a v  a 2  s .co m
    String instanceId = null;

    try {
        version = Utils.getPluginVersion();
        if (version == null) {
            version = "local";
        }
        instanceId = Utils.getPluginInstance();
    } catch (Exception e) {
    }

    String pluginInfo = Constants.PLUGIN_NAME + "/" + version + "/" + instanceId;

    if (userInfo == null) {
        userInfo = pluginInfo;
    } else {
        userInfo = pluginInfo + "/" + userInfo;
    }

    OperationContext opContext = new OperationContext();
    HashMap<String, String> temp = new HashMap<String, String>();
    temp.put("User-Agent", userInfo);

    opContext.setUserHeaders(temp);
    return opContext;
}

From source file:Main.java

public static Vector<HashMap> xmlToVector222(InputStream is, String xpath) {
    try {/*from   ww w  . ja  v  a2 s  . c om*/
        XPathFactory factory = XPathFactory.newInstance();
        XPath xPath = factory.newXPath();
        InputSource inputSource = new InputSource(is);

        NodeList nodes = (NodeList) xPath.evaluate(xpath, inputSource, XPathConstants.NODESET);
        Vector<HashMap> vector = new Vector<HashMap>();

        for (int x = 0; x < nodes.getLength(); x++) {
            NodeList nodeList = nodes.item(x).getChildNodes();
            HashMap hashmap = new HashMap();
            for (int y = 0; y < nodeList.getLength(); y++) {
                Node node = nodeList.item(y);
                if (!node.getNodeName().equals("#text")) {
                    hashmap.put(node.getNodeName(), node.getTextContent());
                }
            }
            vector.add(hashmap);
        }
        return vector;
    } catch (Exception ex) {
        ex.printStackTrace();
        return new Vector();
    }
}