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.alibaba.dubbo.governance.web.governance.module.screen.Services.java

private boolean mock(Map<String, Object> context, String mock) throws Exception {
    String services = (String) context.get("service");
    String application = (String) context.get("application");
    if (services == null || services.length() == 0 || application == null || application.length() == 0) {
        context.put("message", getMessage("NoSuchOperationData"));
        return false;
    }//from w  ww .  ja v a 2s .  com
    for (String service : SPACE_SPLIT_PATTERN.split(services)) {
        if (!super.currentUser.hasServicePrivilege(service)) {
            context.put("message", getMessage("HaveNoServicePrivilege", service));
            return false;
        }
    }
    for (String service : SPACE_SPLIT_PATTERN.split(services)) {
        List<Override> overrides = overrideService.findByServiceAndApplication(service, application);
        if (overrides != null && overrides.size() > 0) {
            for (Override override : overrides) {
                Map<String, String> map = StringUtils.parseQueryString(override.getParams());
                if (mock == null || mock.length() == 0) {
                    map.remove("mock");
                } else {
                    map.put("mock", URL.encode(mock));
                }
                if (map.size() > 0) {
                    override.setParams(StringUtils.toQueryString(map));
                    override.setEnabled(true);
                    override.setOperator(operator);
                    override.setOperatorAddress(operatorAddress);
                    overrideService.updateOverride(override);
                } else {
                    overrideService.deleteOverride(override.getId());
                }
            }
        } else if (mock != null && mock.length() > 0) {
            Override override = new Override();
            override.setService(service);
            override.setApplication(application);
            override.setParams("mock=" + URL.encode(mock));
            override.setEnabled(true);
            override.setOperator(operator);
            override.setOperatorAddress(operatorAddress);
            overrideService.saveOverride(override);
        }
    }
    return true;
}

From source file:org.elasticsearch.xpack.watcher.notification.jira.JiraIssueTests.java

public void testEquals() {
    final JiraIssue issue1 = randomJiraIssue();
    final boolean equals = randomBoolean();

    final Map<String, Object> fields = new HashMap<>(issue1.getFields());
    if (equals == false) {
        if (fields.isEmpty()) {
            fields.put(randomAlphaOfLength(5), randomAlphaOfLength(10));
        } else {/*w w w . ja v a 2 s. co m*/
            fields.remove(randomFrom(fields.keySet()));
        }
    }

    JiraIssue issue2 = new JiraIssue(issue1.getAccount(), fields, issue1.getRequest(), issue1.getResponse(),
            issue1.getFailureReason());
    assertThat(issue1.equals(issue2), is(equals));
}

From source file:com.bstek.dorado.view.resolver.SkinSettingManager.java

protected synchronized SkinSetting doGetSkinSetting(DoradoContext context, String skin) throws Exception {
    SkinSetting skinSetting = skinSettingMap.get(skin);
    if (skinSetting == null) {
        boolean shouldCache = true;
        String metaInfoPath = null;
        String customSkinPath = WebConfigure.getString("view.skin." + skin);
        if (StringUtils.isNotEmpty(customSkinPath)) {
            metaInfoPath = PathUtils.concatPath(customSkinPath, META_INFO_FILE);
        } else {// www.  j a v  a  2s.  c o m
            String libraryRoot = Configure.getString("view.libraryRoot");

            if ("debug".equals(Configure.getString("core.runMode")) && libraryRoot != null
                    && StringUtils.indexOfAny(libraryRoot, RESOURCE_PREFIX_DELIM) >= 0) {
                String[] roots = StringUtils.split(libraryRoot, RESOURCE_PREFIX_DELIM);
                for (String root : roots) {
                    String tempPath = PathUtils.concatPath(root, SKINS, skin, META_INFO_FILE);
                    if (context.getResource(tempPath).exists()) {
                        metaInfoPath = tempPath;
                        break;
                    }
                }
            } else {
                metaInfoPath = PathUtils.concatPath(libraryRoot, SKINS, skin, META_INFO_FILE);
            }
        }

        if (StringUtils.isNotEmpty(metaInfoPath)) {
            Resource metaInfoResource = context.getResource(metaInfoPath);
            if (metaInfoResource.exists()) {
                InputStream in = metaInfoResource.getInputStream();
                try {
                    Map<String, Object> map = objectMapper.readValue(in,
                            new TypeReference<Map<String, Object>>() {
                            });

                    if (VariantUtils.toBoolean(map.remove("tempSkin"))) {
                        shouldCache = false;
                    }

                    skinSetting = new SkinSetting();

                    String clientTypes = (String) map.remove("clientType");
                    if (StringUtils.isNotEmpty(clientTypes)) {
                        skinSetting.setClientTypes(ClientType.parseClientTypes(clientTypes));
                    } else {
                        skinSetting.setClientTypes(ClientType.DESKTOP);
                    }

                    BeanUtils.copyProperties(skinSetting, map);
                } finally {
                    in.close();
                }
            }
        }

        if (shouldCache) {
            if (skinSetting == null) {
                skinSettingMap.put(skin, NULL_SKIN_SETTING);
            } else {
                skinSettingMap.put(skin, skinSetting);
            }
        }
    } else if (skinSetting == NULL_SKIN_SETTING) {
        skinSetting = null;
    }
    return skinSetting;
}

From source file:com.glaf.report.web.springmvc.MxReportTaskController.java

@RequestMapping("/update")
public ModelAndView update(HttpServletRequest request, ModelMap modelMap) {
    LoginContext loginContext = RequestUtils.getLoginContext(request);
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    params.remove("status");
    params.remove("wfStatus");
    String reportTaskId = ParamUtils.getString(params, "reportTaskId");
    ReportTask reportTask = null;/*from ww  w. j  a  v  a2s .co  m*/
    if (StringUtils.isNotEmpty(reportTaskId)) {
        reportTask = reportTaskService.getReportTask(reportTaskId);
    }

    if (reportTask != null && StringUtils.equals(reportTask.getCreateBy(), loginContext.getActorId())) {
        // if (reportTask.getStatus() == 0
        // || reportTask.getStatus() == -1) {
        Tools.populate(reportTask, params);
        reportTaskService.save(reportTask);
        // }
    }

    return this.list(request, modelMap);
}

From source file:jp.eisbahn.oauth2.server.fetcher.accesstoken.impl.RequestParameter.java

/**
 * Fetch an access token from a request parameter and return it. This method
 * must be called when a result of the match() method is true only.
 *
 * @param request/*from   w w w .  j  a va  2 s.  c om*/
 *            The request object.
 * @return the fetched access token.
 */
@Override
public FetchResult fetch(Request request) {
    Map<String, String[]> params = new HashMap<String, String[]>();
    Map<String, String[]> parameterMap = request.getParameterMap();
    params.putAll(parameterMap);
    String[] atokens = params.get("access_token");
    String[] otokens = params.get("oauth_token");
    params.remove("access_token");
    String token = null;

    if (atokens != null && atokens.length > 0) {
        token = atokens[0];
    }
    if (otokens != null && otokens.length > 0) {
        if (StringUtils.isNotEmpty(otokens[0])) {
            token = otokens[0];
            params.remove("oauth_token");
        }
    }

    return new FetchResult(token, params);
}

From source file:net.cpollet.jixture.asserts.JixtureAssert.java

private void resetIgnoredColumns(List<Map<String, ?>> maps) {
    if (null == columnsToIgnore) {
        return;//from  www .  j a  v  a2 s  .c  o  m
    }

    for (Map<String, ?> map : maps) {
        for (String column : columnsToIgnore) {
            map.remove(column);
        }
    }
}

From source file:com.sk89q.craftbook.sponge.mechanics.variable.Variables.java

public void removeVariable(String namespace, String key) {
    Map<String, String> map = variableStore.getOrDefault(namespace, new HashMap<>());
    map.remove(key);
    if (!map.isEmpty())
        variableStore.put(namespace, map);
    else//from ww  w .j  a  v a2s . c om
        variableStore.remove(namespace);
}

From source file:com.autentia.common.statemachine.StateMachine.java

/**
 * Mtodo para recorrer recursivamente todos los estados y determinar si hay inconsistencias, por ejemplo porque
 * quede algun nodo sin visitar, es decir un nodo inalcanczable.
 * <p>// w ww.j ava2s . co  m
 * El algoritmo para cuando se han visitado todos los estados de la mquina de estados o cuando se han recorrido
 * todas las transiciones.
 * <p>
 * Este mtodo es recursivo para visitar los estado a los que se puede acceder desde el estado que se pasa como
 * parmetro y para visitar sus estados padres.
 * 
 * @param state estado de partida
 * @param notVisitedStates mapa de estados no visitados todava.
 */
private void visitStates(T state, Map<T, T> notVisitedStates) {
    if (notVisitedStates.remove(state) == null) {
        return; // Este nodo ya ha sido visitado, as que salimos
    }
    if (notVisitedStates.isEmpty()) {
        return; // Si no quedan estados por visitar, podemos terminar
    }

    final Pair<State<T>, List<Transition<T>>> pair = states.get(state);
    final State<T> actualState = pair.getLeft();
    final List<Transition<T>> tos = pair.getRight();
    final CompositeState<T> parentState = actualState.getParent();

    // Los estados finales no tienen transiciones de salida.
    // Los estados intenrnos no tienen porque tener transiciones de salida, siempre y cuando
    // al menos uno de sus estados padres (estados compuestos) tenga transiciones de salida.
    if (!finalStates.contains(state) && CollectionUtils.isEmpty(tos)) {
        Assert.state(checkParentTransitions(parentState),
                "State " + state + " does not have output transitions");
    }

    // Visitamos los estados a los que se puede acceder por las transiciones
    for (Transition<T> transition : tos) {
        visitStates(transition.getTo(), notVisitedStates);
    }

    // Estar en un estado interno significa que tambin estamos en el padre,
    // as que vamos a visitar al padre si lo tuviera
    if (parentState != null) {
        visitStates(parentState.getId(), notVisitedStates);
    }
}

From source file:edu.uci.ics.jung.algorithms.scoring.DistanceCentralityScorer.java

/**
 * Calculates the score for the specified vertex.  Returns {@code null} if 
 * there are missing distances and such are not ignored by this instance.
 *//*from  w  ww. jav a  2s .co m*/
public Double getVertexScore(V v) {
    Double value = output.get(v);
    if (value != null) {
        if (value < 0)
            return null;
        return value;
    }

    Map<V, Number> v_distances = new HashMap<V, Number>(distance.getDistanceMap(v));
    if (ignore_self_distances)
        v_distances.remove(v);

    // if we don't ignore missing distances and there aren't enough
    // distances, output null (shortcut)
    if (!ignore_missing) {
        int num_dests = graph.getVertexCount() - (ignore_self_distances ? 1 : 0);
        if (v_distances.size() != num_dests) {
            output.put(v, -1.0);
            return null;
        }
    }

    Double sum = 0.0;
    for (V w : graph.getVertices()) {
        if (w.equals(v) && ignore_self_distances)
            continue;
        Number w_distance = v_distances.get(w);
        if (w_distance == null)
            if (ignore_missing)
                continue;
            else {
                output.put(v, -1.0);
                return null;
            }
        else
            sum += w_distance.doubleValue();
    }
    value = sum;
    if (averaging)
        value /= v_distances.size();

    double score = value == 0 ? Double.POSITIVE_INFINITY : 1.0 / value;
    output.put(v, score);

    return score;
}

From source file:org.graylog.plugins.beats.BeatsCodec.java

@Nullable
private Message parseEvent(Map<String, Object> event) {
    @SuppressWarnings("unchecked")
    final Map<String, String> metadata = (HashMap<String, String>) event.remove("@metadata");
    final String type;
    if (metadata == null) {
        LOG.warn("Couldn't recognize Beats type");
        type = "unknown";
    } else {//ww w. ja v a 2s.c  o m
        type = metadata.get("beat");
    }
    final Message gelfMessage;
    switch (type) {
    case "filebeat":
        gelfMessage = parseFilebeat(event);
        break;
    case "topbeat":
        gelfMessage = parseTopbeat(event);
        break;
    case "packetbeat":
        gelfMessage = parsePacketbeat(event);
        break;
    case "winlogbeat":
        gelfMessage = parseWinlogbeat(event);
        break;
    default:
        LOG.debug("Unknown beats type {}. Using generic handler.", type);
        gelfMessage = parseGenericBeat(event);
        break;
    }

    return gelfMessage;
}