Here you can find the source of removeKeyAndConvertToListOfMaps( Object obj, String key)
Parameter | Description |
---|---|
obj | , Key |
@SuppressWarnings("unchecked") public static List<Map<Object, Object>> removeKeyAndConvertToListOfMaps( Object obj, String key)
//package com.java2s; /*//ww w . j ava 2s . c om Pulsar Copyright (C) 2013-2015 eBay Software Foundation Licensed under the GPL v2 license. See LICENSE for full terms. */ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main { private static final String EPL_STREAM_NAME = "name"; private static final String EPL_STREAM_VALUE = "value"; /** * removeKeyAndConvertToListOfMaps - This method is written to meet the requirement for BML Indigo. Input would be * key/value pair which will be converted to list of Maps for each entry. Incoming Map's Key and value would become * separate entry. incoming Map's Key will associate with the keyname of "Name" String Value will associate with the * keyname "Value" String. Also incoming key is present in the Object, that entry will be removed and will be * converted to ListOfMaps * * @param obj * , Key * @return List of Maps */ @SuppressWarnings("unchecked") public static List<Map<Object, Object>> removeKeyAndConvertToListOfMaps( Object obj, String key) { List<Map<Object, Object>> listofMaps = null; if (obj instanceof Map) { listofMaps = new ArrayList<Map<Object, Object>>(); Map<Object, Object> map = (Map<Object, Object>) obj; if (map.containsKey(key)) map.remove(key); for (Entry<Object, Object> mapEntry : map.entrySet()) { Map<Object, Object> listmap = new HashMap<Object, Object>(); listmap.put(EPL_STREAM_NAME, mapEntry.getKey()); listmap.put(EPL_STREAM_VALUE, mapEntry.getValue()); listofMaps.add(listmap); } } obj = null; return listofMaps; } /** * * @param event * @param key * @return */ public static String getValue(Map<String, Object> event, String key) { if (event != null && key != null) { return (String) event.get(key); } return null; } }