Example usage for java.util Map containsKey

List of usage examples for java.util Map containsKey

Introduction

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

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:helper.util.DateHelper.java

/**
 * Count items in day buckets/*from w ww  .  j  a va2 s .c o  m*/
 **/
public static void tallyItemsPerDay(Map<Calendar, Integer> itemsPerDay, Date date) {
    Calendar day = asUtcDay(date);
    if (itemsPerDay.containsKey(day)) {
        itemsPerDay.put(day, itemsPerDay.get(day) + 1);
    } else {
        itemsPerDay.put(day, 1);
    }
}

From source file:Main.java

private static void autoQualify(Document document, Element element, Map<String, String> namespaces,
        String parentPrefix) {//from  ww  w .j a  va2s . co  m
    String localName = element.getLocalName();
    element = renameElement(document, element, localName, namespaces.get(parentPrefix));
    String prefix = parentPrefix;
    if (namespaces.containsKey(localName.toLowerCase())) {
        prefix = localName;
    } else if (genericBranchCoverageTypes.contains(localName.toLowerCase())) {
        prefix = GENERIC_BRANCH_COVERAGE;
    }
    NodeList nodes = element.getChildNodes();
    for (int i = 0, iEnd = nodes.getLength(); i < iEnd; ++i) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            autoQualify(document, (Element) node, namespaces, prefix);
        }
    }
}

From source file:au.org.ala.biocache.util.AlaFileUtils.java

/**
 * Generates a map of feature names to original headers.
 * @param headers/*from ww  w . j a  v  a  2  s.c  om*/
 * @return
 */
public static Map<String, String> generateShapeHeader(String[] headers) {
    Map<String, String> headerMap = new LinkedHashMap<String, String>();
    int i = 0;
    for (String header : headers) {
        String newHeader = reduceNameByVowels(header, 10);
        if (headerMap.containsKey(newHeader)) {
            newHeader = reduceNameByVowels(header, 9) + i;
        }
        headerMap.put(newHeader, header);
        i++;
    }
    return headerMap;
}

From source file:com.meetingninja.csse.database.TaskDatabaseAdapter.java

public static Task createTask(Task t) throws IOException {
    String _url = getBaseUri().build().toString();
    URL url = new URL(_url);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    // add request header
    conn.setRequestMethod(IRequest.POST);
    addRequestHeader(conn, false);//from  w  w w . j av a  2  s  . co  m
    ByteArrayOutputStream json = new ByteArrayOutputStream();
    // this type of print stream allows us to get a string easily
    PrintStream ps = new PrintStream(json);
    // Create a generator to build the JSON string
    JsonGenerator jgen = JFACTORY.createGenerator(ps, JsonEncoding.UTF8);
    // Build JSON Object for Title
    jgen.writeStartObject();
    jgen.writeStringField(Keys.Task.TITLE, t.getTitle());
    jgen.writeStringField(Keys.Task.COMPLETED, Boolean.toString(t.getIsCompleted()));
    jgen.writeStringField(Keys.Task.DESC, t.getDescription());
    jgen.writeStringField(Keys.Task.DEADLINE, Long.toString(t.getEndTimeInMillis()));
    jgen.writeStringField(Keys.Task.DATE_CREATED, t.getDateCreated());
    jgen.writeStringField(Keys.Task.DATE_ASSIGNED, t.getDateAssigned());
    jgen.writeStringField(Keys.Task.CRITERIA, t.getCompletionCriteria());
    jgen.writeStringField(Keys.Task.ASSIGNED_TO, t.getAssignedTo());
    jgen.writeStringField(Keys.Task.ASSIGNED_FROM, t.getAssignedFrom());
    jgen.writeStringField(Keys.Task.CREATED_BY, t.getCreatedBy());
    jgen.writeEndObject();
    jgen.close();

    String payload = json.toString("UTF8");
    ps.close();
    // Get server response
    sendPostPayload(conn, payload);
    String response = getServerResponse(conn);
    Map<String, String> responseMap = new HashMap<String, String>();
    if (responseMap.containsKey(Keys.Task.ID)) {
        t.setID(responseMap.get(Keys.Task.ID));
    }
    return t;
}

From source file:com.qualogy.qafe.web.ContextLoaderHelper.java

public static Boolean loadOnStartup(String windowId, ApplicationContext context,
        SessionContainer sessionContainer) {
    boolean loadOnStartup = false;
    if (context != null && windowId != null) {
        // default behavior from the context
        if (ApplicationCluster.getInstance().getConfigurationItem(Configuration.LOAD_ON_STARTUP) != null) {
            String absoluteWindowId = context.getId() + "." + windowId;
            if (absoluteWindowId != null) {
                String[] loadOnStartupWindows = StringUtils.split(
                        ApplicationCluster.getInstance().getConfigurationItem(Configuration.LOAD_ON_STARTUP),
                        ",");
                if (loadOnStartupWindows != null) {
                    for (int i = 0; i < loadOnStartupWindows.length && !loadOnStartup; i++) {
                        if (absoluteWindowId.equals(loadOnStartupWindows[i])) {
                            loadOnStartup = true;
                        }//from  w  w w. j a v a  2  s  .c o  m

                    }
                }
            }
        }
        // behavior from the paramater
        Map<String, String> parameters = sessionContainer.getParameters();
        if (parameters != null) {
            if (parameters.containsKey(Configuration.LOAD_ON_STARTUP)) {
                String absoluteWindowId = context.getId() + "." + windowId;
                String window = parameters.get(Configuration.LOAD_ON_STARTUP);
                String[] loadOnStartupWindows = StringUtils.split(window, ",");
                if (window != null && window.length() > 0) {
                    if (window.contains(".")) {
                        for (int i = 0; i < loadOnStartupWindows.length && !loadOnStartup; i++) {
                            if (absoluteWindowId.equals(loadOnStartupWindows[i])) {
                                loadOnStartup = true;
                            }
                        }
                    } else {
                        if (context.getId().toString().equals(window)) {
                            if (context.getApplicationMapping() != null
                                    && context.getApplicationMapping().getPresentationTier() != null
                                    && context.getApplicationMapping().getPresentationTier().getView() != null
                                    && context.getApplicationMapping().getPresentationTier().getView()
                                            .getWindows() != null) {
                                List<Window> windows = context.getApplicationMapping().getPresentationTier()
                                        .getView().getWindows();
                                // The first window is always the authentication window,
                                // so the size must be greater than 1
                                if (windows.size() > 1) {
                                    Window w = windows.get(1);
                                    if (w.getId().equals(windowId)) {
                                        loadOnStartup = true;
                                    }
                                }

                            }
                        }

                    }
                }
            }
        }
    }
    return loadOnStartup;
}

From source file:com.evolveum.openicf.lotus.util.DominoUtils.java

public static <T> T getOperationOptionValue(OperationOptions options, DominoOperationOption option,
        T defaultValue) {// w  w  w . j a v a  2  s .c o m
    Map<String, Object> opts = options.getOptions();
    if (opts == null || !opts.containsKey(option.getName())) {
        return defaultValue;
    }

    return (T) opts.get(option);
}

From source file:com.spectralogic.ds3client.utils.Signature.java

public static String canonicalizeResource(final String path, final Map<String, String> queryParams) {
    final StringBuilder canonicalizedResource = new StringBuilder();
    // path is escaped
    canonicalizedResource.append(path);//from w ww.  jav a2 s  .  com

    if (queryParams != null) {
        if (queryParams.containsKey("delete")) {
            canonicalizedResource.append("?delete");
        }
        if (queryParams.containsKey("versioning")) {
            canonicalizedResource.append("?versioning=").append(queryParams.get("versioning"));
        }
        if (queryParams.containsKey("uploads")) {
            canonicalizedResource.append("?uploads");
        }
    }
    return canonicalizedResource.toString();
}

From source file:data.intelligence.platform.yarn.etl.io.CodecPool.java

private static <T> T borrow(Map<Class<T>, List<T>> pool, Class<? extends T> codecClass) {
    T codec = null;// www  .j a  va  2 s . co  m

    // Check if an appropriate codec is available
    synchronized (pool) {
        if (pool.containsKey(codecClass)) {
            List<T> codecList = pool.get(codecClass);

            if (codecList != null) {
                synchronized (codecList) {
                    if (!codecList.isEmpty()) {
                        codec = codecList.remove(codecList.size() - 1);
                    }
                }
            }
        }
    }

    return codec;
}

From source file:io.lavagna.service.CardService.java

private static Map<Integer, Map<String, CardDataCount>> aggregateByCardId(List<CardDataCount> counts) {
    Map<Integer, Map<String, CardDataCount>> r = new TreeMap<>();

    for (CardDataCount c : counts) {
        if (!r.containsKey(c.getCardId())) {
            r.put(c.getCardId(), new TreeMap<String, CardDataCount>());
        }// w w  w.j  a v  a  2s .  c om
        r.get(c.getCardId()).put(c.getType(), c);
    }

    return r;
}

From source file:transaction.script.ProjectTrScript.java

/**
 * @param template//from ww  w .  j  a va2 s  . c o m
 * @param query
 * @param conditionsMapList
 * @return
 * @throws SQLException
 */
public static boolean query(JdbcTemplate template, String query, List<Map<String, Object>> conditionsMapList)
        throws SQLException {
    logger.info("Query to execute is: " + query);

    SqlRowSet set = template.queryForRowSet(query);
    boolean result = true;

    SqlRowSetMetaData mdata = set.getMetaData();
    int columnAmount = mdata.getColumnCount();
    logger.info("Columns: " + columnAmount);
    logger.info("Map size: " + conditionsMapList.size());

    //TODO
    if (set.first()) {
        set.last();
        int rowNum = set.getRow();
        result = (rowNum == conditionsMapList.size());
        set.beforeFirst();
    } else {
        if (!conditionsMapList.get(0).isEmpty()) {
            result = false;
        }
    }

    logger.info("Two maps comparison result is " + result);

    if (result) {
        while (set.next()) {
            int rowNum = set.getRow();

            Map<String, Object> map = conditionsMapList.get(rowNum - 1);

            for (int i = 1; i <= columnAmount; i++) {
                result &= map.containsKey(mdata.getColumnName(i))
                        && map.get(mdata.getColumnName(i)).toString().equals(set.getObject(i).toString());
            }
        }
    }
    return result;
}