Example usage for java.util LinkedHashMap remove

List of usage examples for java.util LinkedHashMap remove

Introduction

In this page you can find the example usage for java.util LinkedHashMap remove.

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:AndroidUninstallStock.java

public static LinkedHashMap<String, String> getLibFromPatternGlobalExclude(
        LinkedHashMap<String, String> liblist, LinkedList<AusInfo> section, String sectionname)
        throws IOException {
    System.out.println();/*  ww w . java  2 s .  c om*/
    System.out.println("Global Exclude libraries from section (" + sectionname + "):");
    for (AusInfo info : section) {
        for (HashMap<String, String> pattern : info.exclude) {
            if (!getBoolean(pattern.get("global"))) {
                continue;
            }
            for (Map.Entry<String, String> exc : _getListFromPattern(liblist, pattern, info, "exclude: ", true)
                    .entrySet()) {
                liblist.remove(exc.getKey());
            }
        }
    }
    return liblist;
}

From source file:AndroidUninstallStock.java

public static LinkedHashMap<String, String> getApkFromPattern(LinkedHashMap<String, String> apklist,
        LinkedList<AusInfo> section, boolean globalexclude) {
    LinkedHashMap<String, String> res = new LinkedHashMap<String, String>();
    if (globalexclude) {
        res.putAll(apklist);//  w ww  . j ava2s .  c  o m
    }
    for (AusInfo info : section) {
        System.out.println("* " + info.apk.get("name"));
        if (!globalexclude) {
            LinkedHashMap<String, String> inc = new LinkedHashMap<String, String>();
            for (HashMap<String, String> pattern : info.include) {
                inc.putAll(_getListFromPattern(apklist, pattern, info, "include: ", false));
            }
            for (HashMap<String, String> pattern : info.exclude) {
                if (getBoolean(pattern.get("global"))) {
                    continue;
                }
                for (Map.Entry<String, String> exc : _getListFromPattern(inc, pattern, info, "exclude: ", false)
                        .entrySet()) {
                    inc.remove(exc.getKey());
                }
            }
            res.putAll(inc);
        } else {
            for (HashMap<String, String> pattern : info.exclude) {
                if (!getBoolean(pattern.get("global"))) {
                    continue;
                }
                for (Map.Entry<String, String> exc : _getListFromPattern(res, pattern, info, "exclude: ", false)
                        .entrySet()) {
                    res.remove(exc.getKey());
                }
            }
        }
    }
    return res;
}

From source file:org.apache.solr.util.CommandOperation.java

/**
 * Get all the values from the metadata for the command
 * without the specified keys/* w w w .  j a  va 2  s .  c o m*/
 */
public Map<String, Object> getValuesExcluding(String... keys) {
    getMapVal(null);
    if (hasError())
        return emptyMap();//just to verify the type is Map
    @SuppressWarnings("unchecked")
    LinkedHashMap<String, Object> cp = new LinkedHashMap<>((Map<String, Object>) commandData);
    if (keys == null)
        return cp;
    for (String key : keys) {
        cp.remove(key);
    }
    return cp;
}

From source file:org.sonatype.nexus.plugins.p2.repository.proxy.P2ProxyMetadataSource.java

@Override
protected Map<String, StorageFileItem> doRetrieveArtifactsFileItems(final RequestContext context,
        final P2ProxyRepository repository) throws RemoteStorageException, ItemNotFoundException {
    Xpp3Dom dom;/* w  ww. j  a va 2s. co  m*/

    try {
        final File artifactRepositoryDir = File.createTempFile("artifacts", "");
        DirSupport.delete(artifactRepositoryDir.toPath());
        DirSupport.mkdir(artifactRepositoryDir.toPath());

        final File artifactMappingsXmlFile = File.createTempFile("p2proxy.artifact-mappings", ".xml");
        try {
            String username = null;
            String password = null;
            final RemoteAuthenticationSettings remoteAuthenticationSettings = repository
                    .getRemoteAuthenticationSettings();
            if (remoteAuthenticationSettings instanceof UsernamePasswordRemoteAuthenticationSettings) {
                final UsernamePasswordRemoteAuthenticationSettings upras = (UsernamePasswordRemoteAuthenticationSettings) remoteAuthenticationSettings;
                username = upras.getUsername();
                password = upras.getPassword();
            }

            try {
                artifactRepository.createProxyRepository(new URI(repository.getRemoteUrl()), username, password,
                        artifactRepositoryDir.toURI(), artifactMappingsXmlFile);
            } catch (RuntimeException e) {
                // another implementation detail: M2 proxy with bad URL would just bore you with 404s
                // while P2 would return HTTP 500 Internal Error
                // while the path will not be quite exact (we are NOT asking for XML but P2 engine does multiple
                // queries, but the meaning is fine for now
                throw new P2RuntimeExceptionMaskedAsINFException(
                        new ResourceStoreRequest(repository.getRemoteUrl() + "artifacts.xml"), repository, e);
            }

            dom = Xpp3DomBuilder.build(new XmlStreamReader(new File(artifactRepositoryDir, "artifacts.xml")));
            storeItemFromFile(P2Constants.ARTIFACT_MAPPINGS_XML, artifactMappingsXmlFile, repository);
            repository.initArtifactMappingsAndMirrors();
        } finally {
            FileUtils.deleteDirectory(artifactRepositoryDir);
            artifactMappingsXmlFile.delete();
        }
    } catch (final XmlPullParserException e) {
        throw new RemoteStorageException(e);
    } catch (final UnsupportedStorageOperationException e) {
        throw new RemoteStorageException(e);
    } catch (final URISyntaxException e) {
        throw new RemoteStorageException(e);
    } catch (final IOException e) {
        throw new RemoteStorageException(e);
    }

    final Artifacts metadata = new Artifacts(dom);
    metadata.setRepositoryAttributes(repository.getName());
    final LinkedHashMap<String, String> properties = metadata.getProperties();
    final String mirrorsURL = properties.get(P2Constants.PROP_MIRRORS_URL);
    if (mirrorsURL != null) {
        context.put(CTX_MIRRORS_URL, mirrorsURL);
    }
    properties.remove(P2Constants.PROP_MIRRORS_URL);
    metadata.setProperties(properties);

    try {
        return createMetadataItems(repository, P2Constants.ARTIFACTS_XML, P2Constants.ARTIFACTS_JAR, metadata,
                P2Constants.XMLPI_ARTIFACTS, context);
    } catch (IOException e) {
        throw new RemoteStorageException(e);
    }
}

From source file:com.sillelien.dollar.api.types.DollarMap.java

@NotNull
@Override/*from  w w w . ja v  a 2 s  . c om*/
public var $removeByKey(@NotNull String key) {
    final LinkedHashMap<var, var> newMap = new LinkedHashMap<>(map);
    newMap.remove(key);
    return DollarFactory.fromValue(newMap, errors());
}

From source file:com.sillelien.dollar.api.types.DollarMap.java

@NotNull
@Override//from w  w  w .j a  va  2s .c o m
public var $remove(var key) {
    final LinkedHashMap<var, var> newMap = new LinkedHashMap<>(map);
    newMap.remove(key);
    return DollarFactory.fromValue(newMap, errors());
}

From source file:com.sillelien.dollar.api.types.DollarMap.java

@NotNull
@Override/*w  ww  .  j a  v a2  s . c o m*/
public var $minus(@NotNull var rhs) {
    var rhsFix = rhs._fixDeep();
    if (rhsFix.map()) {
        LinkedHashMap<var, var> copy = copyMap();
        for (Map.Entry<var, var> entry : rhsFix.toVarMap().entrySet()) {
            copy.remove(entry.getKey());
        }
        return DollarFactory.wrap(new DollarMap(errors(), copy));
    } else {
        LinkedHashMap<var, var> copy = copyMap();
        copy.remove(rhsFix.$S());
        return DollarFactory.wrap(new DollarMap(errors(), copy));
    }
}

From source file:org.mitre.dsmiley.httpproxy.URITemplateProxyServlet.java

@Override
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws ServletException, IOException {

    //First collect params
    /*//w  w  w  .  j  a  v a  2  s.  com
     * Do not use servletRequest.getParameter(arg) because that will
     * typically read and consume the servlet InputStream (where our
     * form data is stored for POST). We need the InputStream later on.
     * So we'll parse the query string ourselves. A side benefit is
     * we can keep the proxy parameters in the query string and not
     * have to add them to a URL encoded form attachment.
     */
    String queryString = "?" + servletRequest.getQueryString();//no "?" but might have "#"
    int hash = queryString.indexOf('#');
    if (hash >= 0) {
        queryString = queryString.substring(0, hash);
    }
    List<NameValuePair> pairs;
    try {
        //note: HttpClient 4.2 lets you parse the string without building the URI
        pairs = URLEncodedUtils.parse(new URI(queryString), "UTF-8");
    } catch (URISyntaxException e) {
        throw new ServletException("Unexpected URI parsing error on " + queryString, e);
    }
    LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
    for (NameValuePair pair : pairs) {
        params.put(pair.getName(), pair.getValue());
    }

    //Now rewrite the URL
    StringBuffer urlBuf = new StringBuffer();//note: StringBuilder isn't supported by Matcher
    Matcher matcher = TEMPLATE_PATTERN.matcher(targetUriTemplate);
    while (matcher.find()) {
        String arg = matcher.group(1);
        String replacement = params.remove(arg);//note we remove
        if (replacement == null) {
            throw new ServletException("Missing HTTP parameter " + arg + " to fill the template");
        }
        matcher.appendReplacement(urlBuf, replacement);
    }
    matcher.appendTail(urlBuf);
    String newTargetUri = urlBuf.toString();
    servletRequest.setAttribute(ATTR_TARGET_URI, newTargetUri);
    URI targetUriObj;
    try {
        targetUriObj = new URI(newTargetUri);
    } catch (Exception e) {
        throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri, e);
    }
    servletRequest.setAttribute(ATTR_TARGET_HOST, URIUtils.extractHost(targetUriObj));

    //Determine the new query string based on removing the used names
    StringBuilder newQueryBuf = new StringBuilder(queryString.length());
    for (Map.Entry<String, String> nameVal : params.entrySet()) {
        if (newQueryBuf.length() > 0)
            newQueryBuf.append('&');
        newQueryBuf.append(nameVal.getKey()).append('=');
        if (nameVal.getValue() != null)
            newQueryBuf.append(nameVal.getValue());
    }
    servletRequest.setAttribute(ATTR_QUERY_STRING, newQueryBuf.toString());

    super.service(servletRequest, servletResponse);
}

From source file:com.opengamma.component.ComponentManager.java

/**
 * Initialize the component.//from  w  w w . j  a  va  2s.  c  om
 * 
 * @param groupName  the group name, not null
 * @param groupConfig  the config data, not null
 */
protected void initComponent(String groupName, LinkedHashMap<String, String> groupConfig) {
    _logger.logInfo("--- Initializing " + groupName + " ---");
    long startInstant = System.nanoTime();

    LinkedHashMap<String, String> remainingConfig = new LinkedHashMap<String, String>(groupConfig);
    String typeStr = remainingConfig.remove("factory");
    _logger.logDebug(" Initializing factory '" + typeStr);
    _logger.logDebug(" Using properties " + remainingConfig);

    // load factory
    ComponentFactory factory = loadFactory(typeStr);

    // set properties
    try {
        setFactoryProperties(factory, remainingConfig);
    } catch (Exception ex) {
        throw new OpenGammaRuntimeException(
                "Failed to set component factory properties: '" + groupName + "' with " + groupConfig, ex);
    }

    // init
    try {
        initFactory(factory, remainingConfig);
    } catch (Exception ex) {
        throw new OpenGammaRuntimeException(
                "Failed to init component factory: '" + groupName + "' with " + groupConfig, ex);
    }

    long endInstant = System.nanoTime();
    _logger.logInfo(
            "--- Initialized " + groupName + " in " + ((endInstant - startInstant) / 1000000L) + "ms ---");
}

From source file:io.hops.hopsworks.api.jupyter.URITemplateProxyServlet.java

@Override
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws ServletException, IOException {

    //First collect params
    /*/*from ww w .j ava2 s.com*/
     * Do not use servletRequest.getParameter(arg) because that will
     * typically read and consume the servlet InputStream (where our
     * form data is stored for POST). We need the InputStream later on.
     * So we'll parse the query string ourselves. A side benefit is
     * we can keep the proxy parameters in the query string and not
     * have to add them to a URL encoded form attachment.
     */
    String queryString = "?" + servletRequest.getQueryString();//no "?" but might have "#"
    int hash = queryString.indexOf('#');
    if (hash >= 0) {
        queryString = queryString.substring(0, hash);
    }
    List<NameValuePair> pairs;
    try {
        //note: HttpClient 4.2 lets you parse the string without building the URI
        pairs = URLEncodedUtils.parse(new URI(queryString), "UTF-8");
    } catch (URISyntaxException e) {
        throw new ServletException("Unexpected URI parsing error on " + queryString, e);
    }
    LinkedHashMap<String, String> params = new LinkedHashMap<>();
    for (NameValuePair pair : pairs) {
        params.put(pair.getName(), pair.getValue());
    }

    //Now rewrite the URL
    StringBuffer urlBuf = new StringBuffer();//note: StringBuilder isn't supported by Matcher
    Matcher matcher = TEMPLATE_PATTERN.matcher(targetUriTemplate);
    while (matcher.find()) {
        String arg = matcher.group(1);
        String replacement = params.remove(arg);//note we remove
        if (replacement != null) {
            matcher.appendReplacement(urlBuf, replacement);
            port = replacement;
        } else if (port != null) {
            matcher.appendReplacement(urlBuf, port);
        } else {
            throw new ServletException("Missing HTTP parameter " + arg + " to fill the template");
        }
    }
    matcher.appendTail(urlBuf);
    String newTargetUri = urlBuf.toString();
    servletRequest.setAttribute(ATTR_TARGET_URI, newTargetUri);
    try {
        targetUriObj = new URI(newTargetUri);
    } catch (Exception e) {
        throw new ServletException("Rewritten targetUri is invalid: " + newTargetUri, e);
    }
    servletRequest.setAttribute(ATTR_TARGET_HOST, URIUtils.extractHost(targetUriObj));

    //Determine the new query string based on removing the used names
    StringBuilder newQueryBuf = new StringBuilder(queryString.length());
    for (Map.Entry<String, String> nameVal : params.entrySet()) {
        if (newQueryBuf.length() > 0) {
            newQueryBuf.append('&');
        }
        newQueryBuf.append(nameVal.getKey()).append('=');
        if (nameVal.getValue() != null) {
            newQueryBuf.append(nameVal.getValue());
        }
    }
    servletRequest.setAttribute(ATTR_QUERY_STRING, newQueryBuf.toString());

    // Create Exchange object with targetUriObj
    // create transport object
    //    ServiceProxy sp = new ServiceProxy();
    //    sp.setTargetUrl(ATTR_TARGET_URI);
    //    super.service(servletRequest, servletResponse);

    //              RouterUtil.initializeRoutersFromSpringWebContext(appCtx, config.
    //              getServletContext(), getProxiesXmlLocation(config));
}