Example usage for org.apache.commons.collections4.map MultiValueMap remove

List of usage examples for org.apache.commons.collections4.map MultiValueMap remove

Introduction

In this page you can find the example usage for org.apache.commons.collections4.map MultiValueMap remove.

Prototype

Object remove(Object key);

Source Link

Document

Removes all values associated with the specified key.

Usage

From source file:org.lockss.plugin.silverchair.PostHttpClientUrlConnection.java

public void storeResponseHeaderInto(Properties props, String prefix) {
    // store all header properties (this is the only way to iterate)
    // first collect all values for any repeated headers.
    MultiValueMap<String, String> map = new MultiValueMap<String, String>();
    Header[] headers = method.getResponseHeaders();
    for (int ix = 0; ix < headers.length; ix++) {
        Header hdr = headers[ix];//from   w  w w .java 2  s.co  m
        String key = hdr.getName();
        String value = hdr.getValue();
        if (value != null) {
            // only store headers with values
            // qualify header names to avoid conflict with our properties
            if (key == null) {
                key = "header_" + ix;
            }
            String propKey = (prefix == null) ? key : prefix + key;
            if (!singleValuedHdrs.isEmpty() && singleValuedHdrs.contains(key.toLowerCase())) {
                map.remove(propKey);
            }
            map.put(propKey, value);
        }
    }
    // now combine multiple values into comma-separated string
    for (String key : map.keySet()) {
        Collection<String> val = map.getCollection(key);
        props.setProperty(key,
                ((val.size() > 1) ? StringUtil.separatedString(val, ",") : CollectionUtil.getAnElement(val)));
    }
}

From source file:pltag.parser.semantics.DepTreeState.java

/**
 * Updates and/or adds new dependencies based on the current fringe, and more specifically
 * the integration point on the prefix tree, and the incoming elementary tree. The routine
 * checks first whether the attachment node (i.e., foot or substitution node) is on the prefix
 * tree or on the elementary tree. In case it is on the prefix tree (Down Substitution and Up Adjunction),
 * we assume that there already exists a dependency in the list of dependencies, so we retrieve and update 
 * it accordingly given the incoming information from the the elementary tree (i.e., roles, argument or relation anchors).
 * If the attachment node is on the elementary tree (Up Substitution and Down Adjunction), 
 * we add a new dependency, given the operation, head information from the prefix tree node and the roles on
 * the elementary tree. See {@link #addDependency(DepNode,ElementaryStringTree,short,MultiValueMap,Node,boolean)} 
 * @param elemTreeState the treeState of the elementary tree
 * @param prefixTreeNode the integration point {@see pltag.parser.Node} on the prefix tree
 * @param tree the {@see pltag.corpus.ElementaryStringTree} tree which attaches to the prefix tree via some TAG operation
 * @param adjoiningNodeInElemTreeId the id of the {@see pltag.parser.Node} that attaches to the integration point on the prefix tree
 * @param elemTreeOffset the offset of id positions in order to correctly identify the node ids of the elementary tree
 * after it has been integrated in the prefix tree
 * @param adjoiningNodeOnPrefixTree whether the attaching node is on the prefix tree. <code>true</code> in case we
 * are Substituting Down or Adjoining Up, <code>false</code> if we are Substituting Up or Adjoining Down
 * @param isShadowTree <code>true</code> if the incoming {@see pltag.corpus.ElementaryStringTree} tree is a shadow (prediction) tree
 * @param origPosTags an array of the gold POS tags, used for constructing the feature vector for identification/labeling
 * @param words//  w ww . j  a v a 2s .  com
 * @param operation the parsing operation applied (adjunction, substitution, verification or initial)
 * @param direction true if the prefix tree was adjoined up on the elementary, false otherwise
 * @param timestamp the current word index
 */
public void updateDependencies(TreeState elemTreeState, Node prefixTreeNode, ElementaryStringTree tree,
        short adjoiningNodeInElemTreeId, short elemTreeOffset, boolean adjoiningNodeOnPrefixTree,
        boolean isShadowTree, String[] words, String[] origPosTags, String operation, boolean direction,
        int timestamp) {
    retainInfoFromTreeHeuristics(elemTreeState, prefixTreeNode, tree, elemTreeOffset, isShadowTree, timestamp,
            false, null, null);
    MultiValueMap<Integer, Role> rolesPerNode = getRolesPerNode(tree, elemTreeOffset);
    //        DepNode integrationPoint = new DepNode(ipOnPrefixTree ? integrationPointId : integrationPointId + ipIdOffset, isShadowTree);                
    // The integration point is always set to be on the prefix tree node where the operation is taking place
    DepNode integrationPoint = new DepNode(prefixTreeNode.getNodeId(), timestamp, isShadowTree);
    // First check whether the attaching node is on the prefix tree
    if (adjoiningNodeOnPrefixTree) // Down-Subst, Up-Adj
    {
        Node shadowTreeRootNode = isShadowTree ? findNodeInFringeById((short) (tree.getRoot() + elemTreeOffset))
                : null;
        if (prefixIntegrationPointHasRole(integrationPoint)) // the prefix tree attaching node has a role. 
            updateDependency(integrationPoint, shadowTreeRootNode, tree, elemTreeOffset, isShadowTree, words,
                    origPosTags, operation, direction, isShadowTree, timestamp);
        //            else if() // the elementary tree attaching node has a role.

    }
    // Then check whether the attaching node is on the elementary tree and has a role.
    else if (!adjoiningNodeOnPrefixTree
            && elemIntegrationPointHasRole(tree, rolesPerNode, adjoiningNodeInElemTreeId + elemTreeOffset)) // Up-Subst, Down-Adj
    {
        addDependency(integrationPoint, tree, adjoiningNodeInElemTreeId, elemTreeOffset, rolesPerNode,
                prefixTreeNode, isShadowTree, words, origPosTags, operation, direction, timestamp);
        // remove ip node (on elementary tree) from rolesPerNode map after it's been dealt with
        //            rolesPerNode.remove(integrationPoint.getId());
        rolesPerNode.remove(adjoiningNodeInElemTreeId + elemTreeOffset);
    }
    // Process the rest roles in the elementary tree
    if (tree.hasRoles()) // !rolesPerNode.isEmpty()
    {
        addIncompleteDependencies(tree, elemTreeOffset, isShadowTree, tree.isRelation(), rolesPerNode,
                prefixTreeNode, words, origPosTags, operation, direction, timestamp);
    }
    // fill in an incomplete argument that is part-filled by the head node of a shadow tree.
    // Assign the anchor of the elementary tree as the argument, even if it's not the head of the whole subtree.
    // This is based on the assumption, that it is the first leaf node inside the argument boundaries (i.e, 
    // subtree that is rooted at the head node of the shadow tree), whose head is a token outside the
    // argument boundaries (i.e., the relation of the incomplete proposition).  WRONG assumption       
    //     fillShadowArgument(prefixTreeNode, tree, elemTreeOffset);        
    // If the tree (//has no roles but) is a relation, make a note of it in a separate map
    // of hanging relations for later use.
    if (tree.isRelation()) {
        addHangingRelation(tree, elemTreeOffset, words, origPosTags, operation, direction, isShadowTree,
                timestamp);
    }
    dependencies.postProcessArcs(operation, direction, isShadowTree);
}