Java Map Remove removeElementFromJsonMap(Map toscaJson, String elementName)

Here you can find the source of removeElementFromJsonMap(Map toscaJson, String elementName)

Description

removes from Json map (toscaJson) first element found by name (elementName) note that this method could update the received argument toscaJson

License

Open Source License

Parameter

Parameter Description
toscaJson a parameter
elementName a parameter

Declaration

public static void removeElementFromJsonMap(Map<String, Object> toscaJson, String elementName) 

Method Source Code

//package com.java2s;
/*-//from   w  w w  . j  a v  a  2 s  . c  o m
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    /**
     * removes from Json map (toscaJson) first element found by name (elementName) note that this method could update the received argument toscaJson
     * 
     * @param toscaJson
     * @param elementName
     */
    public static void removeElementFromJsonMap(Map<String, Object> toscaJson, String elementName) {
        for (Entry<String, Object> entry : toscaJson.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (key.equals(elementName)) {
                toscaJson.remove(elementName);
                return;
            } else if (value instanceof Map) {
                removeElementFromJsonMap((Map<String, Object>) value, elementName);
            }
        }
    }
}

Related

  1. removeApiUuidMap(String apiName)
  2. removeClassFromMap(final Map the_map, final String the_class_name)
  3. removeColor(Map windowColorCountMap, int windowColorCount, int lastColor)
  4. removeDefaultAnnotationPackage(final String packageName, final Map context)
  5. removeDoubleQuotes(Map argMap)
  6. removeEmptyArray(Map map)
  7. removeEmptyValues(Map params)
  8. removeExistingItemsFromProvided(Map existingItems, Map providedItems)
  9. removeFrom(Map map, K key)