List of usage examples for java.util Map remove
V remove(Object key);
From source file:com.spotify.helios.common.descriptors.JobTest.java
private static void removeFieldAndParse(final Job job, final String... fieldNames) throws Exception { final String jobJson = job.toJsonString(); final ObjectMapper objectMapper = new ObjectMapper(); final Map<String, Object> fields = objectMapper.readValue(jobJson, new TypeReference<Map<String, Object>>() { });/* w w w. j a va 2 s . c om*/ for (final String field : fieldNames) { fields.remove(field); } final String modifiedJobJson = objectMapper.writeValueAsString(fields); final Job parsedJob = parse(modifiedJobJson, Job.class); assertEquals(job, parsedJob); }
From source file:com.fengduo.bee.search.utils.PinyinParser.java
/** * ?????//w ww .java 2 s. c o m * * @param args */ private static List<Map<String, Integer>> discountTheChinese(String pinyin) { // ??? List<Map<String, Integer>> mapList = new ArrayList<Map<String, Integer>>(); // ???? Map<String, Integer> onlyOne = null; String[] firsts = pinyin.split(" "); // ? for (String str : firsts) { onlyOne = new Hashtable<String, Integer>(); String[] china = str.split(","); // ? for (String s : china) { Integer count = onlyOne.get(s); if (count == null) { onlyOne.put(s, new Integer(1)); } else { onlyOne.remove(s); count++; onlyOne.put(s, count); } } mapList.add(onlyOne); } return mapList; }
From source file:com.lcw.one.modules.sys.web.LoginController.java
/** * TODO REST ???//from w w w .j ava 2 s.c om * @param useruame ?? * @param isFail 1 * @param clean * @return */ @SuppressWarnings("unchecked") public static boolean isValidateCodeLogin(String useruame, boolean isFail, boolean clean) { Map<String, Integer> loginFailMap = (Map<String, Integer>) CacheUtils.get("loginFailMap"); if (loginFailMap == null) { loginFailMap = Maps.newHashMap(); CacheUtils.put("loginFailMap", loginFailMap); } Integer loginFailNum = loginFailMap.get(useruame); if (loginFailNum == null) { loginFailNum = 0; } if (isFail) { loginFailNum++; loginFailMap.put(useruame, loginFailNum); } if (clean) { loginFailMap.remove(useruame); } return loginFailNum >= 3; }
From source file:com.espertech.esper.epl.join.base.JoinSetComposerPrototypeFactory.java
/** * Builds join tuple composer./*from w ww . ja v a2s. com*/ * @param outerJoinDescList - list of descriptors for outer join criteria * @param optionalFilterNode - filter tree for analysis to build indexes for fast access * @param streamTypes - types of streams * @param streamNames - names of streams * @return composer implementation * @throws ExprValidationException is thrown to indicate that * validation of view use in joins failed. */ public static JoinSetComposerPrototype makeComposerPrototype(String statementName, String statementId, OuterJoinDesc[] outerJoinDescList, ExprNode optionalFilterNode, EventType[] streamTypes, String[] streamNames, StreamJoinAnalysisResult streamJoinAnalysisResult, boolean queryPlanLogging, Annotation[] annotations, HistoricalViewableDesc historicalViewableDesc, ExprEvaluatorContext exprEvaluatorContext, boolean selectsRemoveStream, boolean hasAggregations) throws ExprValidationException { // Determine if there is a historical stream, and what dependencies exist DependencyGraph historicalDependencyGraph = new DependencyGraph(streamTypes.length, false); for (int i = 0; i < streamTypes.length; i++) { if (historicalViewableDesc.getHistorical()[i]) { SortedSet<Integer> streamsThisStreamDependsOn = historicalViewableDesc .getDependenciesPerHistorical()[i]; historicalDependencyGraph.addDependency(i, streamsThisStreamDependsOn); } } if (log.isDebugEnabled()) { log.debug("Dependency graph: " + historicalDependencyGraph); } // Handle a join with a database or other historical data source for 2 streams if ((historicalViewableDesc.isHasHistorical()) && (streamTypes.length == 2)) { return makeComposerHistorical2Stream(outerJoinDescList, optionalFilterNode, streamTypes, historicalViewableDesc, queryPlanLogging, exprEvaluatorContext); } boolean isOuterJoins = !OuterJoinDesc.consistsOfAllInnerJoins(outerJoinDescList); // Query graph for graph relationships between streams/historicals // For outer joins the query graph will just contain outer join relationships QueryGraph queryGraph = new QueryGraph(streamTypes.length); if (outerJoinDescList.length > 0) { OuterJoinAnalyzer.analyze(outerJoinDescList, queryGraph); if (log.isDebugEnabled()) { log.debug(".makeComposer After outer join queryGraph=\n" + queryGraph); } } // Let the query graph reflect the where-clause if (optionalFilterNode != null) { // Analyze relationships between streams using the optional filter expression. // Relationships are properties in AND and EQUALS nodes of joins. FilterExprAnalyzer.analyze(optionalFilterNode, queryGraph, isOuterJoins); if (log.isDebugEnabled()) { log.debug(".makeComposer After filter expression queryGraph=\n" + queryGraph); } // Add navigation entries based on key and index property equivalency (a=b, b=c follows a=c) QueryGraph.fillEquivalentNav(streamTypes, queryGraph); if (log.isDebugEnabled()) { log.debug(".makeComposer After fill equiv. nav. queryGraph=\n" + queryGraph); } } // Historical index lists HistoricalStreamIndexList[] historicalStreamIndexLists = new HistoricalStreamIndexList[streamTypes.length]; QueryPlan queryPlan = QueryPlanBuilder.getPlan(streamTypes, outerJoinDescList, queryGraph, streamNames, historicalViewableDesc, historicalDependencyGraph, historicalStreamIndexLists, streamJoinAnalysisResult, queryPlanLogging, annotations, exprEvaluatorContext); // remove unused indexes - consider all streams or all unidirectional HashSet<String> usedIndexes = new HashSet<String>(); QueryPlanIndex[] indexSpecs = queryPlan.getIndexSpecs(); for (int streamNum = 0; streamNum < queryPlan.getExecNodeSpecs().length; streamNum++) { QueryPlanNode planNode = queryPlan.getExecNodeSpecs()[streamNum]; if (planNode != null) { planNode.addIndexes(usedIndexes); } } for (QueryPlanIndex indexSpec : indexSpecs) { if (indexSpec == null) { continue; } Map<String, QueryPlanIndexItem> items = indexSpec.getItems(); String[] indexNames = items.keySet().toArray(new String[items.size()]); for (String indexName : indexNames) { if (!usedIndexes.contains(indexName)) { items.remove(indexName); } } } if (queryPlanLogging && queryPlanLog.isInfoEnabled()) { queryPlanLog.info("Query plan: " + queryPlan.toQueryPlan()); QueryPlanIndexHook hook = QueryPlanIndexHookUtil.getHook(annotations); if (hook != null) { hook.join(queryPlan); } } boolean joinRemoveStream = selectsRemoveStream || hasAggregations; return new JoinSetComposerPrototypeImpl(statementName, statementId, outerJoinDescList, optionalFilterNode, streamTypes, streamNames, streamJoinAnalysisResult, annotations, historicalViewableDesc, exprEvaluatorContext, indexSpecs, queryPlan, historicalStreamIndexLists, joinRemoveStream, isOuterJoins); }
From source file:ext.sns.auth.AuthResponse.java
/** * AuthResonpse//from w ww . ja v a 2 s . com * * @param params ? * @return AuthResonpse null - ??? */ public static AuthResponse create(Map<String, String> params) { if (MapUtils.isEmpty(params)) { return null; } String code = params.get("code"); String error = params.get("error"); if (StringUtils.isBlank(code) && StringUtils.isBlank(error)) { LOGGER.error("code and error is blank."); return null; } String state = params.get("state"); AuthResponse authResponse = new AuthResponse(); authResponse.code = code; authResponse.state = state; authResponse.raw = params; authResponse.error = error; ProviderConfig providerConfig = ConfigManager.getProviderConfigByAuthResponse(authResponse); if (null == providerConfig) { LOGGER.error("No match ProviderConfig by " + authResponse.toString() + "."); return null; } Map<String, String> callbackParam = providerConfig.getCallbackParam(authResponse); if (MapUtils.isEmpty(callbackParam)) { LOGGER.error("callbackParam is null."); return null; } String type = callbackParam.get(ConfigManager.TYPE_KEY); if (StringUtils.isBlank(type)) { LOGGER.error("type is blank."); return null; } authResponse.type = type; authResponse.providerName = providerConfig.getName(); callbackParam.remove(ConfigManager.TYPE_KEY); authResponse.backExtParam = callbackParam; return authResponse; }
From source file:com.palantir.ptoss.cinch.core.BindingContext.java
private static <T> Map<String, T> dotIndex(Collection<T> items, Function<T, String> qualifierFn, Function<T, String> blindFn) { Set<String> ambiguousNames = Sets.newHashSet(); Map<String, T> results = Maps.newHashMap(); for (T item : items) { String blindKey = blindFn.apply(item); if (!ambiguousNames.contains(blindKey)) { if (results.containsKey(blindKey)) { results.remove(blindKey); ambiguousNames.add(blindKey); } else { results.put(blindKey, item); }// ww w . j a va 2s .co m } String qualifiedKey = qualifierFn.apply(item) + "." + blindKey; results.put(qualifiedKey, item); } return results; }
From source file:com.shieldsbetter.sbomg.Cli.java
private static ProjectDescriptor parseProjectDescriptor(File location, InputStream d) throws OperationException { String locationPath = location.getPath(); ProjectDescriptor result;/*www.jav a 2s . c o m*/ Object rawDescriptor; try { rawDescriptor = new Yaml().load(d); } catch (RuntimeException re) { throw new OperationException( "Couldn't parse project descriptor " + locationPath + ": \n" + re.getMessage()); } if (!(rawDescriptor instanceof Map)) { throw new OperationException("Project descriptor " + locationPath + " must be a YAML map."); } Map rawDescriptorMap = (Map) rawDescriptor; Object rawSrcDirs = rawDescriptorMap.remove("source directories"); if (rawSrcDirs == null) { throw new OperationException("Project descriptor " + locationPath + " must contain 'source directories' key. Keys are case " + "sensitive."); } List rawSrcDirsList; if (rawSrcDirs instanceof List) { rawSrcDirsList = (List) rawSrcDirs; } else if (rawSrcDirs instanceof String) { rawSrcDirsList = ImmutableList.of(rawSrcDirs); } else { throw new OperationException("In project descriptor " + location + ", 'source directories' key must map to a string or a " + "list of strings."); } List<File> srcDirs = new LinkedList<>(); for (Object rawSrcDir : rawSrcDirsList) { if (!(rawSrcDir instanceof String)) { throw new OperationException("In project descriptor " + location + ", 'source directories' contains a non-string " + "element: " + rawSrcDir); } srcDirs.add(new File((String) rawSrcDir)); } Object rawTargetDir = rawDescriptorMap.remove("target directory"); if (rawTargetDir == null) { throw new OperationException("Project descriptor " + location + " must contain 'target directory' key. Keys are case " + "sensitive."); } if (!(rawTargetDir instanceof String)) { throw new OperationException("In project descriptor " + location + ", 'target directory' maps to a non-string element: " + rawTargetDir); } File targetDir = new File((String) rawTargetDir); return new ProjectDescriptor(location.getParentFile(), srcDirs, targetDir); }
From source file:com.wolvereness.overmapped.lib.WellOrdered.java
private static <T> boolean handleTokens(final T token, final Map<T, Collection<T>> map, final Set<T> in) { final Iterator<T> it = getIterator(token, map); if (it == null) return true; while (it.hasNext()) { if (in.contains(it.next())) return false; // Short the search for next time it.remove();// www .j a va 2s.c o m } // Short the search further for next time as collection is empty map.remove(token); return true; }
From source file:net.ftb.util.OSUtils.java
/** * Removes environment variables which may cause faulty JVM memory allocations *///from w w w. j a va 2s . com public static void cleanEnvVars(Map<String, String> environment) { environment.remove("_JAVA_OPTIONS"); environment.remove("JAVA_TOOL_OPTIONS"); environment.remove("JAVA_OPTIONS"); }
From source file:ai.susi.tools.JsonSignature.java
public static boolean verify(Map<String, byte[]> obj, PublicKey key) throws SignatureException, InvalidKeyException { if (!obj.containsKey(signatureString)) throw new SignatureException("No signature supplied"); Signature signature;//from w w w. java2 s . c o m try { signature = Signature.getInstance("SHA256withRSA"); } catch (NoSuchAlgorithmException e) { return false; //does not happen } byte[] sigString = obj.get(signatureString); byte[] sig = Base64.getDecoder().decode(sigString); obj.remove(signatureString); signature.initVerify(key); signature.update(obj.toString().getBytes(StandardCharsets.UTF_8)); boolean res = signature.verify(sig); obj.put(signatureString, sigString); return res; }