Example usage for java.util Map remove

List of usage examples for java.util Map remove

Introduction

In this page you can find the example usage for java.util Map 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:com.lithium.flow.store.FileStore.java

@Override
public void putValue(@Nonnull String key, @Nullable String value) {
    Map<String, String> map = read();
    if (value != null) {
        map.put(key, value);/*  www  .  j  a v  a  2 s .co  m*/
    } else {
        map.remove(key);
    }
    write(map);
}

From source file:io.lightlink.oracle.OracleStructArrayType.java

@Override
public Object convertToJdbc(Connection connection, RunnerContext runnerContext, String name, Object value)
        throws IOException, SQLException {
    OracleConnection con = unwrap(connection);

    ArrayDescriptor arrayStructDesc = safeCreateArrayDescriptor(getCustomSQLTypeName(), con);

    if (value == null) {
        return null;
    } else if (value instanceof List || value.getClass().isArray()) {
        if (value.getClass().isArray()) {
            value = Arrays.asList((Object[]) value);
        }/*w w w. j  a  v a 2  s .  com*/

        List records = (List) value;

        STRUCT[] structArray = new STRUCT[records.size()];

        for (int i = 0; i < structArray.length; i++) {
            Object record = records.get(i);

            if (!(record instanceof Map)) { // create a Map from bean
                Map map = new CaseInsensitiveMap(new BeanMap(record));
                map.remove("class");
                record = map;
            }

            structArray[i] = createStruct(con, (Map) record, arrayStructDesc.getBaseName());
        }

        return new ARRAY(arrayStructDesc, con, structArray);

    } else {

        throw new IllegalArgumentException("Type " + getCustomSQLTypeName() + " of converter="
                + this.getClass().getName() + " accepts array/list of objects.");
    }
}

From source file:org.energyos.espi.datacustodian.oauth.AccessConfirmationController.java

@RequestMapping("/oauth/confirm_access")
public ModelAndView getAccessConfirmation(Map<String, Object> model, Principal principal) throws Exception {
    AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest");
    ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId());
    model.put("auth_request", clientAuth);
    model.put("client", client);
    Map<String, String> scopes = new LinkedHashMap<String, String>();
    for (String scope : clientAuth.getScope()) {
        scopes.put(OAuth2Utils.SCOPE_PREFIX + scope, "false"); //Spring Security OAuth2 2.0.0.M2 change
    }//from  ww  w  . ja  v a  2s  . c  o  m
    for (Approval approval : approvalStore.getApprovals(principal.getName(), client.getClientId())) {
        if (clientAuth.getScope().contains(approval.getScope())) {
            scopes.put(OAuth2Utils.SCOPE_PREFIX + approval.getScope(),
                    approval.getStatus() == ApprovalStatus.APPROVED ? "true" : "false");
        }
    }
    model.put("scopes", scopes);
    return new ModelAndView("access_confirmation", model);
}

From source file:io.cloudslang.lang.compiler.modeller.transformers.JavaActionTransformer.java

private void transformKeys(Map<String, String> rawData) {
    // snake_case -> camelCase
    rawData.put(ScoreLangConstants.JAVA_ACTION_CLASS_KEY,
            rawData.remove(SlangTextualKeys.JAVA_ACTION_CLASS_NAME_KEY));
    rawData.put(ScoreLangConstants.JAVA_ACTION_METHOD_KEY,
            rawData.remove(SlangTextualKeys.JAVA_ACTION_METHOD_NAME_KEY));
    String gav = rawData.remove(SlangTextualKeys.JAVA_ACTION_GAV_KEY);
    dependencyFormatValidator.validateDependency(gav);
    rawData.put(ScoreLangConstants.JAVA_ACTION_GAV_KEY, gav);
}

From source file:com.bstek.dorado.idesupport.parse.PropertyParser.java

@SuppressWarnings("unchecked")
@Override//w w w.  ja  v  a  2  s.  com
protected Object doParse(Node node, ParseContext context) throws Exception {
    Element element = (Element) node;
    ConfigRuleParseContext parserContext = (ConfigRuleParseContext) context;

    PropertyTemplate propertyTemplate = new PropertyTemplate();
    Map<String, Object> properties = this.parseProperties(element, context);

    String reference = (String) properties.remove("reference");
    if (StringUtils.isNotEmpty(reference)) {
        String ruleName, prop;
        int i = reference.indexOf(':');
        if (i > 0) {
            ruleName = reference.substring(0, i);
            prop = reference.substring(i + 1);
        } else {
            ruleName = reference;
            prop = "id";
        }
        propertyTemplate.setReference(
                new LazyReferenceTemplate(parserContext.getRuleTemplateManager(), ruleName, prop));
    }

    String clientTypesText = (String) properties.remove("clientTypes");
    int clientTypes = ClientType.parseClientTypes(clientTypesText);
    if (clientTypes > 0) {
        propertyTemplate.setClientTypes(clientTypes);
    }

    String compositeTypeConfig = (String) properties.remove("compositeType");
    if (StringUtils.isNotEmpty(compositeTypeConfig)) {
        CompositeType compositeType = CompositeType.valueOf(compositeTypeConfig);
        propertyTemplate.setCompositeType(compositeType);
    }

    BeanUtils.copyProperties(propertyTemplate, properties);

    if (propertyTemplate.getCompositeType() == CompositeType.Fixed
            || propertyTemplate.getCompositeType() == CompositeType.Open) {
        propertyTemplate
                .addProperties((Collection<PropertyTemplate>) dispatchChildElements(element, parserContext));
    }
    return propertyTemplate;
}

From source file:com.linuxbox.enkive.statistics.consolidation.EmbeddedConsolidator.java

private List<Map<String, Object>> getStatTypeData(String gathererName, String type) {
    StatsQuery query = new MongoStatsQuery(gathererName, filterType, type, startDate, endDate);
    List<Map<String, Object>> result = createListOfMaps();
    Set<Map<String, Object>> stats = client.queryStatistics(query);
    for (Map<String, Object> statsMap : stats) {
        statsMap.remove("_id");// WARNING mongo specific pollution
        statsMap.remove(STAT_TIMESTAMP);
        statsMap.remove(STAT_GATHERER_NAME);
        statsMap.remove(CONSOLIDATION_TYPE);

        if (statsMap != null && !statsMap.isEmpty()) {
            result.add(statsMap);/*w  w w.j  av  a 2 s .c  om*/
        }
    }
    return result;
}

From source file:fr.recolnat.database.ExportsDatabase.java

public void removeUserExport(String user, String fileName) {
    while (database.isClosed()) {
        try {// ww w.  j  a v a2 s .  com
            Thread.sleep(500);
        } catch (InterruptedException ex) {
            return;
        }
    }
    Map userFiles = database.treeMap(user).createOrOpen();
    userFiles.remove(fileName);
    database.commit();
}

From source file:com.netflix.spinnaker.fiat.roles.UserRolesSyncer.java

public long updateUserPermissions(Map<String, UserPermission> permissionsById) {
    if (permissionsById.remove(UnrestrictedResourceConfig.UNRESTRICTED_USERNAME) != null) {
        permissionsRepository.put(permissionsResolver.resolveUnrestrictedUser());
        log.info("Synced anonymous user role.");
    }/*from  w w w .ja  va  2s .c om*/

    List<ExternalUser> extUsers = permissionsById.values().stream().map(permission -> new ExternalUser()
            .setId(permission.getId())
            .setExternalRoles(permission.getRoles().stream()
                    .filter(role -> role.getSource() == Role.Source.EXTERNAL).collect(Collectors.toList())))
            .collect(Collectors.toList());

    long count = permissionsResolver.resolve(extUsers).values().stream()
            .map(permission -> permissionsRepository.put(permission)).count();
    log.info("Synced {} non-anonymous user roles.", count);
    return count;
}

From source file:io.neba.core.resourcemodels.mapping.CyclicMappingSupport.java

/**
 * Ends a mapping that was {@link #begin(Mapping) begun}.
 *
 * @param mapping must not be <code>null</code>.
 *//*  ww w . ja  va2 s .  c om*/
public void end(Mapping mapping) {
    notNull(mapping, "Method argument mapping must not be null.");
    Map<Mapping, Mapping> ongoingMappings = this.ongoingMappings.get();
    if (ongoingMappings != null) {
        ongoingMappings.remove(mapping);
        if (ongoingMappings.isEmpty()) {
            this.ongoingMappings.remove();
        }
    }
}

From source file:com.alibaba.jstorm.ui.utils.UIUtils.java

/**
 * gets a topology tree & nodes for topology graph utilization
 *
 * @param stormTopology jstorm sys-topology
 * @return a TopologyGraph/*from www .jav  a 2s.c  om*/
 */
public static TopologyGraph getTopologyGraph(StormTopology stormTopology, List<MetricInfo> componentMetrics) {
    Map<String, Bolt> bolts = stormTopology.get_bolts();
    Map<String, SpoutSpec> spouts = stormTopology.get_spouts();

    //remove system bolts
    String[] remove_ids = new String[] { "__acker", "__system", "__topology_master" };
    for (String id : remove_ids) {
        bolts.remove(id);
    }

    //<id, node>
    Map<String, TopologyNode> nodes = Maps.newHashMap();
    //<from:to,edge>
    Map<String, TopologyEdge> edges = Maps.newHashMap();

    List<TreeNode> roots = Lists.newArrayList(); //this is used to get tree depth
    Map<String, TreeNode> linkMap = Maps.newHashMap(); //this is used to get tree depth
    // init the nodes
    for (Map.Entry<String, SpoutSpec> entry : spouts.entrySet()) {
        String componentId = entry.getKey();
        nodes.put(componentId, new TopologyNode(componentId, componentId, true));

        TreeNode node = new TreeNode(componentId);
        roots.add(node);
        linkMap.put(componentId, node);
    }
    for (Map.Entry<String, Bolt> entry : bolts.entrySet()) {
        String componentId = entry.getKey();
        nodes.put(componentId, new TopologyNode(componentId, componentId, false));
        linkMap.put(componentId, new TreeNode(componentId));
    }

    //init the edges
    int edgeId = 1;
    for (Map.Entry<String, Bolt> entry : bolts.entrySet()) {
        String componentId = entry.getKey();
        Bolt bolt = entry.getValue();
        TreeNode node = linkMap.get(componentId);
        for (Map.Entry<GlobalStreamId, Grouping> input : bolt.get_common().get_inputs().entrySet()) {
            GlobalStreamId streamId = input.getKey();
            String src = streamId.get_componentId();
            if (nodes.containsKey(src)) {
                TopologyEdge edge = new TopologyEdge(src, componentId, edgeId++);
                edges.put(edge.getKey(), edge);
                // put into linkMap
                linkMap.get(src).addChild(node);
                node.addSource(src);
                node.addParent(linkMap.get(src));
            }
        }
    }

    //calculate whether has circle
    boolean isFixed = false;
    while (!isFixed) {
        isFixed = true;
        for (TreeNode node : linkMap.values()) {
            for (TreeNode parent : node.getParents()) {
                if (!node.addSources(parent.getSources())) {
                    isFixed = false;
                }
            }
        }
    }

    // fill value to edges
    fillTPSValue2Edge(componentMetrics, edges);
    fillTLCValue2Edge(componentMetrics, edges);

    // fill value to nodes
    fillValue2Node(componentMetrics, nodes);

    // calculate notes' depth
    int maxDepth = bfsDepth(roots);

    // set nodes level & get max breadth
    Map<Integer, Integer> counter = Maps.newHashMap();
    int maxBreadth = 1;
    for (Map.Entry<String, TreeNode> entry : linkMap.entrySet()) {
        int layer = entry.getValue().getLayer();
        nodes.get(entry.getKey()).setLevel(layer);
        int breadth = 1;
        if (counter.containsKey(layer)) {
            breadth = counter.get(layer) + 1;
        }
        counter.put(layer, breadth);
        if (maxBreadth < breadth) {
            maxBreadth = breadth;
        }
    }

    //adjust graph for components in one line
    String PREFIX = "__adjust_prefix_";
    int count = 1;
    for (TreeNode node : linkMap.values()) {
        int layer = node.getLayer();
        node.setBreadth(counter.get(layer));
    }
    for (TreeNode tree : linkMap.values()) {
        if (isInOneLine(tree.getChildren())) {
            String id = PREFIX + count++;
            TopologyNode node = new TopologyNode(id, id, false);
            node.setLevel(tree.getLayer() + 1);
            node.setIsHidden(true);
            nodes.put(id, node);

            TreeNode furthest = getFurthestNode(tree.getChildren());

            TopologyEdge toEdge = new TopologyEdge(id, furthest.getComponentId(), edgeId++);
            toEdge.setIsHidden(true);
            edges.put(toEdge.getKey(), toEdge);

            TopologyEdge fromEdge = new TopologyEdge(tree.getComponentId(), id, edgeId++);
            fromEdge.setIsHidden(true);
            edges.put(fromEdge.getKey(), fromEdge);
        }
    }

    TopologyGraph graph = new TopologyGraph(Lists.newArrayList(nodes.values()),
            Lists.newArrayList(edges.values()));

    graph.setDepth(maxDepth);
    graph.setBreadth(maxBreadth);

    //create graph object
    return graph;
}