Example usage for java.util Map keySet

List of usage examples for java.util Map keySet

Introduction

In this page you can find the example usage for java.util Map keySet.

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:org.carewebframework.api.security.SecurityUtil.java

/**
 * Returns the target of a url pattern mapping.
 * //from www . ja v a2s  . co m
 * @param url Ant-style url pattern
 * @param urlMappings Map of url pattern mappings
 * @return String mapped to pattern, or null if none.
 */
public static String getUrlMapping(String url, Map<String, String> urlMappings) {
    if (urlMappings != null) {
        for (String pattern : urlMappings.keySet()) {
            if (urlMatcher.match(pattern, url)) {
                return urlMappings.get(pattern);
            }
        }
    }

    return null;
}

From source file:de.thischwa.pmcms.tool.ChecksumTool.java

/**
 * Comparing the Map with the file checksums from the server with the local one.
 * /*w w w .jav a 2  s  .c  o  m*/
 * @return A sorted collection of files, which have to be copied to the server.
 */
public static Collection<File> merge(final String pathPart, final Map<String, String> localChecksums,
        final Map<String, String> serverChecksums) {
    List<File> files = new ArrayList<File>();
    for (String key : serverChecksums.keySet()) {
        String localChecksum = localChecksums.get(key);
        if (StringUtils.isNotBlank(localChecksum)) {
            String serverChecksum = serverChecksums.get(key);
            if (!StringUtils.equals(serverChecksum, localChecksum)) {
                files.add(new File(pathPart, key).getAbsoluteFile());
                logger.debug("Merge is diff: ".concat(key).concat(" cause ").concat(localChecksum).concat(" ")
                        .concat(serverChecksum));
            }
        }
    }
    for (String key : localChecksums.keySet())
        if (!serverChecksums.containsKey(key)) {
            files.add(new File(pathPart, key).getAbsoluteFile());
            logger.debug("Merge is new: " + key);
        }

    Collections.sort(files, new FileComparator());
    return files;
}

From source file:com.core.util.wx.XmlUtils.java

/**
 * arrayxml/*from w ww  . j a  v  a2 s  . c om*/
 * 
 * @param map
 * @return
 */
public static String mapToXml(Map<String, String> map) {
    StringBuilder xml = new StringBuilder();
    xml.append("<xml>");
    String value = null;
    for (String key : map.keySet()) {
        value = map.get(key);
        xml.append("<").append(key).append(">");
        if (StringUtils.isNumeric(value)) {
            xml.append(value);
        } else {
            xml.append("<![CDATA[").append(value).append("]]>");
        }
        xml.append("</").append(key).append(">");
    }
    xml.append("</xml>");
    return xml.toString();
}

From source file:com.microsoft.azure.shortcuts.resources.samples.NetworksSample.java

private static void testProvisionWithSubnets(Subscription subscription) throws Exception {
    String suffix = String.valueOf(System.currentTimeMillis());
    String existingGroupName = "rg" + suffix;
    String newNetworkName = "net" + suffix;

    // Create a test group
    ResourceGroup group = subscription.resourceGroups().define(existingGroupName).withRegion(Region.US_WEST)
            .create();/*from  www  .  ja va  2s.  c o  m*/

    Network network = subscription.networks().define(newNetworkName).withRegion(Region.US_WEST)
            .withExistingResourceGroup(existingGroupName).withAddressSpace("10.0.0.0/28")
            .withSubnet("Foo", "10.0.0.0/29").withSubnet("Bar", "10.0.0.8/29").create();

    printNetwork(network);

    // Listing networks in a specific resource group
    Map<String, Network> networks = subscription.networks().asMap(existingGroupName);
    System.out.println(String.format("Network ids in group '%s': \n\t%s", existingGroupName,
            StringUtils.join(networks.keySet(), ",\n\t")));

    // Clean up
    network.delete();
    group.delete();
}

From source file:Main.java

public static <T> List<Map<String, T>> permutations(Map<String, List<T>> parameterValues) {
    List<Map<String, T>> list = new ArrayList<Map<String, T>>();
    if (parameterValues == null || parameterValues.size() == 0) {
        return list;
    }/*  ww  w  . j  av  a  2 s. c  o  m*/

    permute(new HashMap<String, T>(), new ArrayList<String>(parameterValues.keySet()), parameterValues, list);

    return list;

}

From source file:hrytsenko.csv.IO.java

/**
 * Saves records into CSV file./* w w  w .  j ava 2s. c o m*/
 * 
 * <p>
 * If file already exists, then it will be overridden.
 * 
 * @param args
 *            the named arguments {@link IO}.
 * 
 * @throws IOException
 *             if file could not be written.
 */
public static void save(Map<String, ?> args) throws IOException {
    Path path = getPath(args);
    LOGGER.info("Save: {}.", path.getFileName());

    @SuppressWarnings("unchecked")
    Collection<Record> records = (Collection<Record>) args.get("records");
    if (records.isEmpty()) {
        LOGGER.info("No records to save.");
        return;
    }

    try (Writer dataWriter = newBufferedWriter(path, getCharset(args), StandardOpenOption.CREATE,
            StandardOpenOption.TRUNCATE_EXISTING)) {
        Set<String> columns = new LinkedHashSet<>();
        List<Map<String, String>> rows = new ArrayList<>();
        for (Record record : records) {
            Map<String, String> values = record.values();
            columns.addAll(values.keySet());
            rows.add(values);
        }

        CsvSchema.Builder csvSchema = getSchema(args).setUseHeader(true);
        for (String column : columns) {
            csvSchema.addColumn(column);
        }
        CsvMapper csvMapper = new CsvMapper();
        ObjectWriter csvWriter = csvMapper.writer().withSchema(csvSchema.build());
        csvWriter.writeValue(dataWriter, rows);
    }
}

From source file:net.big_oh.common.web.listener.session.SimpleSessionTrackingListener.java

/**
 * // w ww  . ja  v  a2  s.c  o m
 * @return Returns a set of all <code>HttpSession</code> objects observed by
 *         web applications that used the same classloader to instantiate
 *         the <code>HttpSessionListener</code> listener.
 */
// TODO DSW Need better documentation here
public static synchronized Set<HttpSession> getSessionsForClassloader() {
    Set<HttpSession> sessionsForJvm = new HashSet<HttpSession>();

    for (String servletContextKey : contextToSessionCollectionMap.keySet()) {
        Map<HttpSession, Object> sessionsMapForServletContext = contextToSessionCollectionMap
                .get(servletContextKey);
        sessionsForJvm.addAll(sessionsMapForServletContext.keySet());
    }

    return sessionsForJvm;
}

From source file:com.firewallid.util.FISQL.java

public static String getFirstFieldInsertIfNotExist(Connection conn, String tableName, String field,
        Map<String, String> fields) throws SQLException {
    /* Query *///from   w w w  . ja  v  a  2 s.c  o m
    String query = "SELECT " + field + " FROM " + tableName + " WHERE "
            + Joiner.on(" = ? AND ").join(fields.keySet()) + " = ?";

    /* Execute */
    PreparedStatement pst = conn.prepareStatement(query);
    int i = 1;
    for (String value : fields.values()) {
        pst.setString(i, value);
        i++;
    }
    ResultSet executeQuery = pst.executeQuery();
    if (executeQuery.next()) {
        return executeQuery.getString(field);
    }

    /* Row is not exists. Insert */
    query = "INSERT INTO " + tableName + " (" + Joiner.on(", ").join(fields.keySet()) + ") VALUES ("
            + StringUtils.repeat("?, ", fields.size() - 1) + "?)";
    pst = conn.prepareStatement(query);
    i = 1;
    for (String value : fields.values()) {
        pst.setString(i, value);
        i++;
    }
    if (pst.execute()) {
        return null;
    }
    return getFirstFieldInsertIfNotExist(conn, tableName, field, fields);
}

From source file:com.innoq.ldap.connector.Utils.java

public static LdapUser addAttributes(LdapUser user, String uid) {
    Map<String, String> attributes = getTestUserAttributes(uid);
    for (String key : attributes.keySet()) {
        user.set(key, attributes.get(key));
    }//from   ww  w. j  a v a 2  s  .  co m
    return user;
}

From source file:com.rdsic.pcm.service.impl.GenericQueryImpl.java

/**
 * Implementation method for operation Select
 *
 * @param req//  w w  w . j a v  a  2 s . co m
 * @return
 */
public static SelectQueryRes select(SelectQueryReq req) {
    String key = UUID.randomUUID().toString();
    String opr = "GenericQuery/Select";
    Logger.LogReq(key, opr, req);

    Date now = new Date();
    SelectQueryRes res = new SelectQueryRes();
    if (!Util.validateRequest(req, opr, Constant.FUNCTIONALITY_ACTION.WS_INVOKE, res)) {
        Logger.LogRes(key, opr, res);
        return res;
    }

    try {
        int maxRow = req.getQuery().getMaxRowCount() == null
                ? Configuration.getInt(Constant.CONFIG_KEY.PCM_QUERY_MAX_ROW)
                : req.getQuery().getMaxRowCount();
        String sql = req.getQuery().getSQL();

        List<Object> params = new ArrayList<>();

        if (req.getQuery().getParams() != null) {
            if (req.getQuery().getParams().getDatetimeParam() != null) {
                req.getQuery().getParams().getDatetimeParam().stream().map((p) -> {
                    params.add(p.getName());
                    return p;
                }).forEach((p) -> {
                    params.add(Util.toDate(p.getValue()));
                });
            }

            if (req.getQuery().getParams().getNumericParam() != null) {
                req.getQuery().getParams().getNumericParam().stream().map((p) -> {
                    params.add(p.getName());
                    return p;
                }).forEach((p) -> {
                    params.add(p.getValue());
                });
            }

            if (req.getQuery().getParams().getStringParam() != null) {
                req.getQuery().getParams().getStringParam().stream().map((p) -> {
                    params.add(p.getName());
                    return p;
                }).forEach((p) -> {
                    params.add(p.getValue());
                });
            }
        }
        // execute the query
        List<Map<String, Object>> list = GenericHql.INSTANCE.querySQL(sql, maxRow, params.toArray());

        // this setting for all null object to empty string to advoid item missing in output json
        for (Map<String, Object> m : list) {
            for (String k : m.keySet()) {
                if (m.get(k) == null) {
                    m.put(k, "");
                }
            }
        }
        JSONObject json = new JSONObject();
        json.put("items", list);

        SelectQueryResponseType response = new SelectQueryResponseType();
        response.setRecordCount(list.size());
        response.setJSONData(json.toString());

        res.setDataSet(response);

        res.setStatus(Constant.STATUS_CODE.OK);
    } catch (Exception e) {
        Util.handleException(e, res);
    }

    res.setResponseDateTime(Util.toXmlGregorianCalendar(now));
    Logger.LogRes(key, opr, res);
    return res;

}