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:com.hp.hpl.jena.sparql.modify.UpdateProcessRemoteBase.java

/**
 * <p>//from   www  .j a  v a  2 s  . c o  m
 * Helper method which applies configuration from the Context to the query
 * engine if a service context exists for the given URI
 * </p>
 * <p>
 * Based off proposed patch for JENA-405 but modified to apply all relevant
 * configuration, this is in part also based off of the private
 * {@code configureQuery()} method of the {@link Service} class though it
 * omits parameter merging since that will be done automatically whenever
 * the {@link QueryEngineHTTP} instance makes a query for remote submission.
 * </p>
 * 
 * @param serviceURI
 *            Service URI
 */
private static void applyServiceConfig(String serviceURI, UpdateProcessRemoteBase engine) {
    @SuppressWarnings("unchecked")
    Map<String, Context> serviceContextMap = (Map<String, Context>) engine.context.get(Service.serviceContext);
    if (serviceContextMap != null && serviceContextMap.containsKey(serviceURI)) {
        Context serviceContext = serviceContextMap.get(serviceURI);
        if (log.isDebugEnabled())
            log.debug("Endpoint URI {} has SERVICE Context: {} ", serviceURI, serviceContext);

        // Apply authentication settings
        String user = serviceContext.getAsString(Service.queryAuthUser);
        String pwd = serviceContext.getAsString(Service.queryAuthPwd);

        if (user != null || pwd != null) {
            user = user == null ? "" : user;
            pwd = pwd == null ? "" : pwd;
            if (log.isDebugEnabled())
                log.debug("Setting basic HTTP authentication for endpoint URI {} with username: {} ",
                        serviceURI, user);

            engine.setAuthentication(user, pwd.toCharArray());
        }
    }
}

From source file:be.fedict.eid.applet.service.impl.tlv.TlvParser.java

private static <T> T parseThrowing(byte[] file, Class<T> tlvClass) throws InstantiationException,
        IllegalAccessException, DataConvertorException, UnsupportedEncodingException {
    Field[] fields = tlvClass.getDeclaredFields();
    Map<Integer, Field> tlvFields = new HashMap<Integer, Field>();
    for (Field field : fields) {
        TlvField tlvFieldAnnotation = field.getAnnotation(TlvField.class);
        if (null == tlvFieldAnnotation) {
            continue;
        }//  w w w .j  av a  2  s  . c  o m
        int tagId = tlvFieldAnnotation.value();
        if (tlvFields.containsKey(new Integer(tagId))) {
            throw new IllegalArgumentException("TLV field duplicate: " + tagId);
        }
        tlvFields.put(new Integer(tagId), field);
    }
    T tlvObject = tlvClass.newInstance();

    int idx = 0;
    while (idx < file.length - 1) {
        byte tag = file[idx];
        idx++;
        byte lengthByte = file[idx];
        int length = lengthByte & 0x7f;
        while ((lengthByte & 0x80) == 0x80) {
            idx++;
            lengthByte = file[idx];
            length = (length << 7) + (lengthByte & 0x7f);
        }
        idx++;
        if (0 == tag) {
            idx += length;
            continue;
        }
        if (tlvFields.containsKey(new Integer(tag))) {
            Field tlvField = tlvFields.get(new Integer(tag));
            Class<?> tlvType = tlvField.getType();
            ConvertData convertDataAnnotation = tlvField.getAnnotation(ConvertData.class);
            byte[] tlvValue = copy(file, idx, length);
            Object fieldValue;
            if (null != convertDataAnnotation) {
                Class<? extends DataConvertor<?>> dataConvertorClass = convertDataAnnotation.value();
                DataConvertor<?> dataConvertor = dataConvertorClass.newInstance();
                fieldValue = dataConvertor.convert(tlvValue);
            } else if (String.class == tlvType) {
                fieldValue = new String(tlvValue, "UTF-8");
            } else if (Boolean.TYPE == tlvType) {
                fieldValue = true;
            } else if (tlvType.isArray() && Byte.TYPE == tlvType.getComponentType()) {
                fieldValue = tlvValue;
            } else {
                throw new IllegalArgumentException("unsupported field type: " + tlvType.getName());
            }
            LOG.debug("setting field: " + tlvField.getName());
            if (null != tlvField.get(tlvObject) && false == tlvField.getType().isPrimitive()) {
                throw new RuntimeException("field was already set: " + tlvField.getName());
            }
            tlvField.setAccessible(true);
            tlvField.set(tlvObject, fieldValue);
        } else {
            LOG.debug("unknown tag: " + (tag & 0xff) + ", length: " + length);
        }
        idx += length;
    }
    return tlvObject;
}

From source file:com.baasbox.controllers.Social.java

/**
 * Unlink given social network from current user.
 * In case that the user was generated by any social network and
 * at the moment of the unlink the user has only one social network connected
 * the controller will throw an Exception with a clear message.
 * Otherwise a 200 code will be returned
 * @param socialNetwork//from   w w  w .j a  va  2s. c  o  m
 * @return
 * @throws SqlInjectionException 
 */
@With({ UserCredentialWrapFilter.class, ConnectToDBFilter.class })
public static Result unlink(String socialNetwork) throws SqlInjectionException {
    ODocument user = null;
    try {
        user = UserService.getCurrentUser();
    } catch (Exception e) {
        internalServerError(ExceptionUtils.getMessage(e));
    }
    Map<String, ODocument> logins = user.field(UserDao.ATTRIBUTES_SYSTEM + "." + UserDao.SOCIAL_LOGIN_INFO);
    if (logins == null || logins.isEmpty() || !logins.containsKey(socialNetwork)
            || logins.get(socialNetwork) == null) {
        return notFound("User's account is not linked with " + StringUtils.capitalize(socialNetwork));
    } else {
        boolean generated = UserService.isSocialAccount(DbHelper.getCurrentUserNameFromConnection());
        if (logins.size() == 1 && generated) {
            return internalServerError("User's account can't be unlinked.");
        } else {
            try {
                UserService.removeSocialLoginTokens(user, socialNetwork);
                return ok();
            } catch (Exception e) {
                return internalServerError(ExceptionUtils.getMessage(e));
            }
        }
    }
}

From source file:net.sourceforge.vulcan.spring.jdbc.BuildHistoryMetricsQuery.java

static void splitMetricsByBuildId(List<JdbcBuildOutcomeDto> builds, List<JdbcMetricDto> metrics) {
    final Map<Integer, JdbcBuildOutcomeDto> buildsById = new HashMap<Integer, JdbcBuildOutcomeDto>();

    for (JdbcBuildOutcomeDto build : builds) {
        buildsById.put(build.getPrimaryKey(), build);
    }//from   ww  w . j  a v  a  2 s .c  o  m

    final int size = metrics.size();

    final Integer buildId = metrics.get(0).getBuildId();
    if (size == 1) {
        if (buildsById.containsKey(buildId)) {
            buildsById.get(buildId).setMetrics(Collections.<MetricDto>unmodifiableList(metrics));
        } else {
            LOG.error("Got metrics for missing build " + buildId);
        }
        return;
    }

    Integer currentBuildId = buildId;
    int i = 0;
    int j = 1;

    while (j < size) {
        while (j < size && metrics.get(j).getBuildId().equals(currentBuildId)) {
            j++;
        }

        final List<MetricDto> metricsForBuild = Collections.<MetricDto>unmodifiableList(metrics.subList(i, j));

        if (buildsById.containsKey(currentBuildId)) {
            buildsById.get(currentBuildId).setMetrics(metricsForBuild);
        } else {
            LOG.error("Got metrics for missing build " + currentBuildId);
        }

        i = j;

        if (j < size) {
            currentBuildId = metrics.get(j).getBuildId();
        }
    }
}

From source file:org.openscore.lang.compiler.modeller.ExecutableBuilder.java

private static String resolveRefId(String refIdString, Map<String, String> imports) {
    String alias = StringUtils.substringBefore(refIdString, ".");
    Validate.notNull(imports, "No imports specified for source: " + refIdString);
    if (!imports.containsKey(alias))
        throw new RuntimeException("Unresolved alias: " + alias);
    String refName = StringUtils.substringAfter(refIdString, ".");
    return imports.get(alias) + "." + refName;
}

From source file:com.microfocus.application.automation.tools.octane.executor.UFTTestDetectionService.java

private static Map<OctaneStatus, Integer> computeStatusMap(List<? extends SupportsOctaneStatus> entities) {
    Map<OctaneStatus, Integer> statusMap = new HashMap<>();
    for (SupportsOctaneStatus item : entities) {
        if (!statusMap.containsKey(item.getOctaneStatus())) {
            statusMap.put(item.getOctaneStatus(), 0);
        }// ww w  . jav a2 s . c  om
        statusMap.put(item.getOctaneStatus(), statusMap.get(item.getOctaneStatus()) + 1);
    }
    return statusMap;
}

From source file:com.common.volley.toolbox.BasicNetwork.java

/**
 * ?header Cache-Control?max-age ?/*  w ww.java  2 s . c o  m*/
 * ???max-age
 * @param responseHeaders  ?headers
 * @param request  ?
 * @return  maxageheaders
 */
protected static Map<String, String> convertMaxAge(Map<String, String> responseHeaders, Request<?> request) {
    if (responseHeaders == null) {
        return null;
    }
    if (request.shouldCache() && request.getCacheTime() != 0) {
        if (responseHeaders.containsKey("Cache-Control")) {
            String[] tokens = responseHeaders.get("Cache-Control").split(",");
            for (int i = 0; i < tokens.length; i++) {
                String token = tokens[i].trim();
                if (token.equals("no-cache") || token.equals("no-store")) {
                    return responseHeaders;
                } else if (token.startsWith("max-age=")) {
                    return responseHeaders;
                }
            }
            String temp = responseHeaders.get("Cache-Control");
            responseHeaders.put("Cache-Control", temp + ",max-age=" + request.getCacheTime());
        } else {
            responseHeaders.put("Cache-Control", "max-age=" + request.getCacheTime());
        }
    }
    return responseHeaders;
}

From source file:com.allinfinance.startup.init.MenuInfoUtil.java

/**
 * ??// w w  w  .j  a  v a 2 s  . co m
 */
@SuppressWarnings("unchecked")
public static void init() {
    String hql = "from com.allinfinance.po.TblFuncInf t where t.FuncType in ('0','1','2') order by t.FuncId";
    ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO");
    List<TblFuncInf> funcInfList = commQueryDAO.findByHQLQuery(hql);
    for (int i = 0, n = funcInfList.size(); i < n; i++) {
        TblFuncInf tblFuncInf = funcInfList.get(i);
        Map<String, Object> menuBean = new LinkedHashMap<String, Object>();
        if (StringUtil.isEmpty(tblFuncInf.getIconPath()) || "-".equals(tblFuncInf.getIconPath().trim())) {
            menuBean.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
        } else {
            menuBean.put(Constants.TOOLBAR_ICON, tblFuncInf.getIconPath().trim());
        }

        if (Constants.MENU_LVL_1.equals(tblFuncInf.getFuncType())) {//??
            //            Map<String, Object> menuBean = new LinkedHashMap<String, Object>();
            menuBean.put(Constants.MENU_ID, tblFuncInf.getFuncId().toString().trim());
            menuBean.put(Constants.MENU_TEXT, tblFuncInf.getFuncName().trim());
            menuBean.put(Constants.MENU_CLS, Constants.MENU_FOLDER);
            allMenuBean.addJSONArrayElement(menuBean);
        } else if (Constants.MENU_LVL_2.equals(tblFuncInf.getFuncType())) {//??
            //            Map<String, Object> menuBean = new LinkedHashMap<String, Object>();
            menuBean.put(Constants.MENU_ID, tblFuncInf.getFuncId().toString().trim());
            menuBean.put(Constants.MENU_TEXT, tblFuncInf.getFuncName().trim());
            menuBean.put(Constants.MENU_PARENT_ID, tblFuncInf.getFuncParentId().toString().trim());
            menuBean.put(Constants.MENU_CLS, Constants.MENU_FOLDER);
            addLvl2Menu(menuBean);
        } else if (Constants.MENU_LVL_3.equals(tblFuncInf.getFuncType())) {
            //            Map<String, Object> menuBean = new LinkedHashMap<String, Object>();
            menuBean.put(Constants.MENU_ID, tblFuncInf.getFuncId().toString().trim());
            menuBean.put(Constants.MENU_TEXT, tblFuncInf.getFuncName().trim());
            menuBean.put(Constants.MENU_PARENT_ID, tblFuncInf.getFuncParentId().toString().trim());
            menuBean.put(Constants.MENU_LEAF, true);
            menuBean.put(Constants.MENU_URL, tblFuncInf.getPageUrl().trim());
            menuBean.put(Constants.MENU_CLS, Constants.MENU_FILE);

            //            if("-".equals(tblFuncInf.getIconPath().trim())) {
            //               menuBean.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
            //            } else {
            //               menuBean.put(Constants.TOOLBAR_ICON, tblFuncInf.getIconPath().trim());
            //            }
            addLvl3Menu(menuBean);

        }
    }

    //??
    List<Object> menuLvl1List = allMenuBean.getDataList();
    for (int i = 0; i < menuLvl1List.size(); i++) {
        Map<String, Object> menuLvl1Bean = (Map<String, Object>) menuLvl1List.get(i);
        if (!menuLvl1Bean.containsKey(Constants.MENU_CHILDREN)) {
            menuLvl1List.remove(i);
            i--;
            continue;
        }
        List<Object> menuLvl2List = (List<Object>) menuLvl1Bean.get(Constants.MENU_CHILDREN);
        for (int j = 0; j < menuLvl2List.size(); j++) {
            Map<String, Object> menuLvl2Bean = (Map<String, Object>) menuLvl2List.get(j);
            if (!menuLvl2Bean.containsKey(Constants.MENU_CHILDREN)) {
                menuLvl2List.remove(j);
                menuLvl1Bean.put(Constants.MENU_CHILDREN, menuLvl2List);
                menuLvl1List.set(i, menuLvl1Bean);
                allMenuBean.setDataList(menuLvl1List);
                j--;
            }
        }
    }
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static List<String> applyZscoringModel(Map<Integer, Pair<Double, Double>> model, List<String> examples) {
    return examples.stream().map(LibSVMUtils::split).map(triple -> triple.getLeft()
            + String.join(" ", triple.getMiddle().stream().map(pair -> Pair.of(pair.getLeft(),
                    (!model.containsKey(pair.getLeft()) || model.get(pair.getLeft()).getRight() == 0) ? 1f
                            : ((pair.getRight() - model.get(pair.getLeft()).getLeft())
                                    / model.get(pair.getLeft()).getRight())))
                    .filter(pair -> pair.getRight().floatValue() != 0f)
                    .map(pair -> pair.getLeft() + ":" + pair.getRight().floatValue()).collect(toList()))
            + triple.getRight()).collect(toList());
}

From source file:net.ontopia.topicmaps.entry.XMLConfigSource.java

/**
 * INTERNAL: Returns a collection containing the topic map sources
 * created by reading the configuration file.
 *///from  w ww .  j a  v a 2s.c om
public static List<TopicMapSourceIF> readSources(String config_file, Map<String, String> environ) {
    if (environ == null)
        environ = new HashMap<String, String>(1);
    // add CWD entry
    if (!environ.containsKey(CWD)) {
        File file = new File(config_file);
        if (!file.exists())
            throw new OntopiaRuntimeException("Config file '" + config_file + "' does not exist.");
        environ.put(CWD, file.getParent());
    }

    return readSources(new InputSource(URIUtils.toURL(new File(config_file)).toString()), environ);
}