List of usage examples for java.util Map remove
V remove(Object key);
From source file:com.cheusov.Jrep.java
private static void processFile(InputStream in, String filename) throws IOException { Iterator<String> it; if (wholeContent) { String fileContent = IOUtils.toString(in, encoding); it = Arrays.asList(fileContent).iterator(); } else {//from w w w . jav a 2 s . co m it = IOUtils.lineIterator(in, encoding); } int matchCount = 0; List<Pair<Integer, Integer>> startend = null; int lineNumber = 0; int lastMatchedLineNumber = 0; Map<Integer, String> lines = new HashMap<Integer, String>(); while (it.hasNext()) { ++lineNumber; String line = (String) it.next(); if (opt_B > 0) { lines.put(lineNumber, line); lines.remove(lineNumber - opt_B - 1); } boolean matched = false; boolean nextFile = false; if (!inverseMatch && !outputFilename && !opt_o && !opt_L && !opt_c) startend = new ArrayList<Pair<Integer, Integer>>(); String lineToPrint = null; for (JrepPattern pattern : patterns) { int pos = 0; JrepMatchResult m = pattern.matcher(line); int lineLength = line.length(); // boolean nextLine = false; while (pos < lineLength && m.find(pos)) { matched = true; if (outputFilename || opt_c || opt_L || inverseMatch) { break; } else if (opt_o) { printlnWithPrefix(filename, getOutputString(line, m), lineNumber, ':'); } else if (colorEscStart != null) { startend.add(Pair.of(m.start(), m.end())); } pos = m.end(); if (m.start() == m.end()) ++pos; } } matched ^= inverseMatch; if (matched) { if (exitStatus == 1) exitStatus = 0; if (!outputFilename && !opt_o && !opt_L && !opt_c) { if (colorEscStart == null || startend == null) lineToPrint = line; else lineToPrint = getLineToPrint(line, startend); } if (outputFilename) { println(filename); nextFile = true; } } if (lineToPrint != null) { for (int prevLineNumber = lineNumber - opt_B; prevLineNumber < lineNumber; ++prevLineNumber) { String prevLine = lines.get(prevLineNumber); if (prevLine != null) { lines.remove(prevLineNumber); printlnWithPrefix(filename, prevLine, prevLineNumber, '-'); } } lastMatchedLineNumber = lineNumber; lines.remove(lineNumber); printlnWithPrefix(filename, lineToPrint, lineNumber, ':'); } else if (lastMatchedLineNumber > 0 && lastMatchedLineNumber + opt_A >= lineNumber) { lines.remove(lineNumber); printlnWithPrefix(filename, line, lineNumber, '-'); } if (matched) { ++matchCount; if (matchCount == opt_m) nextFile = true; } if (nextFile) break; } if (opt_L && matchCount == 0) println(filename); if (opt_c) printlnWithPrefix(filename, "" + matchCount, lineNumber, ':'); }
From source file:com.discovery.darchrow.net.ParamUtil.java
/** * ?./* ww w. java2s. c o m*/ * * @param uri * the uri * @param paramNameList * the param name list * @param charsetType * ? * @return the string */ public static String removeParameterList(URI uri, List<String> paramNameList, String charsetType) { if (null == uri) { return ""; } String url = uri.toString(); // paramNameList null if (Validator.isNullOrEmpty(paramNameList)) { return url; } // *********************************************************************** String before = URIUtil.getBeforePath(url); // *********************************************************************** // URI ? URI ???? URI String query = uri.getRawQuery(); // *********************************************************************** // url?? if (Validator.isNullOrEmpty(query)) { // ?? return url; } else { Map<String, String[]> map = URIUtil.parseQueryToArrayMap(query, null); for (String paramName : paramNameList) { map.remove(paramName); } return URIUtil.getEncodedUrlByArrayMap(before, map, charsetType); } }
From source file:com.hpe.application.automation.tools.octane.executor.UftTestDiscoveryDispatcher.java
/** * Go over discovered and octane data tables * 1.if DT doesn't exist on octane - this is new DT * 2. all DTs that are found in Octane but not discovered - delete those DTs from server */// ww w . ja v a2s . co m private static boolean validateDataTablesDiscoveryForFullDetection(MqmRestClient client, UFTTestDetectionResult detectionResult) { boolean hasDiff = false; List<ScmResourceFile> discoveredDataTables = new ArrayList(detectionResult.getNewScmResourceFiles()); detectionResult.getNewScmResourceFiles().clear(); Map<String, Entity> octaneDataTablesMap = getDataTablesFromServer(client, Long.parseLong(detectionResult.getWorkspaceId()), Long.parseLong(detectionResult.getScmRepositoryId())); for (ScmResourceFile dataTable : discoveredDataTables) { Entity octaneDataTable = octaneDataTablesMap.remove(dataTable.getRelativePath()); if (octaneDataTable == null) { detectionResult.getNewScmResourceFiles().add(dataTable); } else { hasDiff = true; } } //go over DT that exist in Octane but not discovered for (Entity octaneDataTable : octaneDataTablesMap.values()) { hasDiff = true; ScmResourceFile dt = new ScmResourceFile(); dt.setId(octaneDataTable.getId()); dt.setName(octaneDataTable.getName()); dt.setRelativePath(octaneDataTable.getStringValue(OctaneConstants.DataTables.RELATIVE_PATH_FIELD)); detectionResult.getDeletedScmResourceFiles().add(dt); } return hasDiff; }
From source file:frequencyanalysis.FrequencyAnalysis.java
public static List<Item> sortByValue(Map map) { List sortedList = new ArrayList<Item>(); while (!map.isEmpty()) { int Highest = 0; Object HighestKey = null; Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); if ((Integer) entry.getValue() > Highest) { Highest = (Integer) entry.getValue(); HighestKey = entry.getKey(); }//w w w . j a v a2 s . c o m } if (HighestKey != null) { sortedList.add(new Item(HighestKey, Highest)); map.remove(HighestKey); } } return sortedList; }
From source file:org.activiti.rest.api.process.ProcessInstancePost.java
/** * Creates a new process instance base on a process definition id and collects details about the new * process instance for the webscript template. * * @param req The webscripts request//from w ww .jav a 2s .c o m * @param status The webscripts status * @param cache The webscript cache * @param model The webscripts template model */ @Override protected void executeWebScript(WebScriptRequest req, Status status, Cache cache, Map<String, Object> model) { ActivitiWebScriptBody body = getBody(req); String processDefinitionId = getMandatoryString(body, "processInstanceId"); Map<String, Object> variables = getFormVariables(body); variables.remove("processInstanceId"); model.put("instance", getRuntimeService().startProcessInstanceById(processDefinitionId, variables)); }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableRuntimeContext.java
public static SortedSetMultimap<TableContext, TableRuntimeContext> initializeAndUpgradeFromV1Offsets( Map<String, TableContext> tableContextMap, Map<String, String> offsets, Set<String> offsetKeysToRemove) throws StageException { SortedSetMultimap<TableContext, TableRuntimeContext> returnMap = buildSortedPartitionMap(); for (Map.Entry<String, TableContext> tableEntry : tableContextMap.entrySet()) { final String tableName = tableEntry.getKey(); final TableContext tableContext = tableEntry.getValue(); Map<String, String> startingOffsets; String offsetValue = null; Map<String, String> storedOffsets = null; if (offsets.containsKey(tableName)) { offsetValue = offsets.remove(tableName); storedOffsets = OffsetQueryUtil.validateStoredAndSpecifiedOffset(tableContext, offsetValue); offsetKeysToRemove.add(tableName); startingOffsets = OffsetQueryUtil.getOffsetsFromSourceKeyRepresentation(offsetValue); tableContext.getOffsetColumnToStartOffset().putAll(startingOffsets); }/*from w ww . j a v a 2s . c om*/ final TableRuntimeContext partition = createInitialPartition(tableContext, storedOffsets); returnMap.put(tableContext, partition); if (offsetValue != null) { offsets.put(partition.getOffsetKey(), offsetValue); } } return returnMap; }
From source file:com.ebay.jetstream.epl.EPLUtilities.java
/** * 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/* w ww . j a v a2 s . c o m*/ * * @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; }
From source file:backtype.storm.utils.LocalState.java
public synchronized void remove(Object key, boolean cleanup) throws IOException { Map<Object, Object> curr = snapshot(); curr.remove(key); persist(curr, cleanup);//from ww w. j ava2 s .c om }
From source file:net.sf.jsfcomp.chartcreator.ChartListener.java
private void emptySession(Map sessionMap, String id) { sessionMap.remove(id); }
From source file:io.lightlink.oracle.OracleStructType.java
@Override public Object convertToJdbc(Connection connection, RunnerContext runnerContext, String name, Object value) throws IOException, SQLException { OracleConnection con = unwrap(connection); if (!(value instanceof Map)) { // create a Map from bean Map map = new CaseInsensitiveMap(new BeanMap(value)); map.remove("class"); value = map;//from w w w.ja va 2s . c o m } return createStruct(con, (Map) value, getCustomSQLTypeName()); }