List of usage examples for java.util LinkedHashMap containsKey
boolean containsKey(Object key);
From source file:org.ff4j.store.FeatureStoreSpringJdbc.java
/** {@inheritDoc} */ public Map<String, Feature> readAll() { LinkedHashMap<String, Feature> mapFP = new LinkedHashMap<String, Feature>(); List<Feature> lFp = getJdbcTemplate().query(getQueryBuilder().getAllFeatures(), FMAPPER); for (Feature flipPoint : lFp) { mapFP.put(flipPoint.getUid(), flipPoint); }/* w w w . j ava2 s.c o m*/ // Populating Roles RoleRowMapper rrm = new RoleRowMapper(); getJdbcTemplate().query(getQueryBuilder().getAllRoles(), rrm); Map<String, Set<String>> roles = rrm.getRoles(); for (Map.Entry<String, Set<String>> featId : roles.entrySet()) { if (mapFP.containsKey(featId.getKey())) { mapFP.get(featId.getKey()).getPermissions().addAll(featId.getValue()); } } return mapFP; }
From source file:com.baidu.rigel.biplatform.tesseract.isservice.search.service.impl.CallbackSearchServiceImpl.java
/** * @param context ?// w ww . java2 s. c om * @param query ? * @return * @throws IndexAndSearchException exception occurred when */ public SearchIndexResultSet query(QueryContext context, QueryRequest query) throws IndexAndSearchException { LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_BEGIN, "callbackquery", "[callbackquery:" + query + "]")); if (query == null || context == null || StringUtils.isEmpty(query.getCubeId())) { LOGGER.error(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_EXCEPTION, "callbackquery", "[callbackquery:" + query + "]")); throw new IndexAndSearchException( TesseractExceptionUtils.getExceptionMessage(IndexAndSearchException.QUERYEXCEPTION_MESSAGE, IndexAndSearchExceptionType.ILLEGALARGUMENT_EXCEPTION), IndexAndSearchExceptionType.ILLEGALARGUMENT_EXCEPTION); } // TODO ??? if (query.getGroupBy() == null || query.getSelect() == null) { return null; } Map<String, String> requestParams = ((QueryContextAdapter) context).getQuestionModel().getRequestParams(); // Build query target map Map<String, List<MiniCubeMeasure>> callbackMeasures = context.getQueryMeasures().stream() .filter(m -> m.getType().equals(MeasureType.CALLBACK)).map(m -> { CallbackMeasure tmp = (CallbackMeasure) m; for (Map.Entry<String, String> entry : tmp.getCallbackParams().entrySet()) { if (requestParams.containsKey(entry.getKey())) { tmp.getCallbackParams().put(entry.getKey(), requestParams.get(entry.getKey())); } } return m; }).collect(Collectors.groupingBy(c -> ((CallbackMeasure) c).getCallbackUrl(), Collectors.toList())); if (callbackMeasures == null || callbackMeasures.isEmpty()) { LOGGER.error(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_EXCEPTION, "Empty callback measure", "[callbackquery:" + query + "]")); throw new IndexAndSearchException( TesseractExceptionUtils.getExceptionMessage(IndexAndSearchException.QUERYEXCEPTION_MESSAGE, IndexAndSearchExceptionType.ILLEGALARGUMENT_EXCEPTION), IndexAndSearchExceptionType.ILLEGALARGUMENT_EXCEPTION); } LOGGER.info("Find callback targets " + callbackMeasures); // Keep group-by sequence. List<String> groupby = new ArrayList<String>(query.getGroupBy().getGroups()); LinkedHashMap<String, List<String>> groupbyParams = new LinkedHashMap<String, List<String>>(groupby.size()); for (String g : groupby) { groupbyParams.put(g, new ArrayList<String>()); } LinkedHashMap<String, List<String>> whereParams = new LinkedHashMap<String, List<String>>(); for (Expression e : query.getWhere().getAndList()) { List<String> l = e.getQueryValues().stream().filter(v -> !StringUtils.isEmpty(v.getValue())) .map(v -> v.getValue()).collect(Collectors.toList()); if (groupbyParams.containsKey(e.getProperties())) { // if not contains SUMMARY_KEY, add it into group by list if (!l.contains(TesseractConstant.SUMMARY_KEY)) { l.add(TesseractConstant.SUMMARY_KEY); } // Put it into group by field groupbyParams.get(e.getProperties()).addAll(l); } else { // Put it into filter field if (CollectionUtils.isEmpty(l)) { List<Set<String>> tmp = e.getQueryValues().stream().map(v -> v.getLeafValues()) .collect(Collectors.toList()); List<String> values = Lists.newArrayList(); tmp.forEach(t -> values.addAll(t)); whereParams.put(e.getProperties(), values); } else { whereParams.put(e.getProperties(), new ArrayList<String>(l)); } } } // Prepare query tools // CountDownLatch latch = new CountDownLatch(response.size()); // List<Future<CallbackResponse>> results = Lists.newArrayList(); Map<CallbackExecutor, Future<CallbackResponse>> results = Maps.newHashMap(); ExecutorCompletionService<CallbackResponse> service = new ExecutorCompletionService<CallbackResponse>( taskExecutor); StringBuilder callbackMeasureNames = new StringBuilder(); for (Entry<String, List<MiniCubeMeasure>> e : callbackMeasures.entrySet()) { CallbackExecutor ce = new CallbackExecutor(e, groupbyParams, whereParams); results.put(ce, service.submit(ce)); e.getValue().forEach(m -> { callbackMeasureNames.append(" " + m.getCaption() + " "); }); } // } Map<CallbackExecutor, CallbackResponse> response = new ConcurrentHashMap<CallbackExecutor, CallbackResponse>( callbackMeasures.size()); StringBuffer sb = new StringBuffer(); results.forEach((k, v) -> { try { response.put(k, v.get()); } catch (Exception e1) { LOGGER.error(e1.getMessage(), e1); sb.append(": " + callbackMeasureNames.toString() + " ??, ?"); } }); if (!StringUtils.isEmpty(sb.toString())) { if (ThreadLocalPlaceholder.getProperty(ThreadLocalPlaceholder.ERROR_MSG_KEY) != null) { ThreadLocalPlaceholder.unbindProperty(ThreadLocalPlaceholder.ERROR_MSG_KEY); } ThreadLocalPlaceholder.bindProperty(ThreadLocalPlaceholder.ERROR_MSG_KEY, sb.toString()); } // Package result SqlQuery sqlQuery = QueryRequestUtil.transQueryRequest2SqlQuery(query); SearchIndexResultSet result = null; if (!response.isEmpty()) { result = packageResultRecords(query, sqlQuery, response); } else { result = new SearchIndexResultSet(new Meta(query.getGroupBy().getGroups().toArray(new String[0])), 0); } LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_END, "query", "[query:" + query + "]")); return result; }
From source file:org.opennms.web.controller.ksc.AscoTlcCustomViewController.java
/** {@inheritDoc} */ @Override/*from w w w .j a v a 2 s . c o m*/ protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { // Get Form Variable String username = request.getRemoteUser(); if (username == null) throw new ServletException("Username is null: must be authenticated"); Integer reportId = getReportId(username); if (reportId == null) { System.out.println("AscoTlc: DEBUG no KSC report found for username: " + username); KscReportEditor editor = KscReportEditor.getFromSession(request.getSession(), false); editor.loadNewWorkingReport(); Report newreport = editor.getWorkingReport(); newreport.setTitle(username); newreport.setShow_graphtype_button(false); newreport.setGraphs_per_line(getDefaultGraphsPerLine()); newreport.setShow_timespan_button(true); System.out.println("AscoTlc: DEBUG creating new KSC report for username: " + username); List<String> resources = new ArrayList<String>(); OnmsCriteria criteria = new OnmsCriteria(OnmsSnmpInterface.class); criteria.add(Restrictions.ilike("ifAlias", username, MatchMode.ANYWHERE)); for (OnmsSnmpInterface snmpiface : m_snmpInterfaceDao.findMatching(criteria)) { String resourceId = "node[" + snmpiface.getNode().getNodeId() + "].interfaceSnmp[" + snmpiface.computeLabelForRRD() + "]"; System.out.println("AscoTlc: DEBUG snmpinterface ifalias match found: resourceId:" + resourceId); resources.add(resourceId); } for (String resourceId : resources) { System.out.println("AscoTlc: DEBUG try to add graph for resource: " + resourceId); Graph vGraph = new Graph(); vGraph.setTitle(""); vGraph.setResourceId(resourceId); vGraph.setTimespan(DEFAULT_TIME_SPAN); // Check the resource OnmsResource resource = getResourceService().getResourceById(resourceId); if (resource == null) { System.out.println("AscoTlc: DEBUG no active resource found: skipping"); continue; } else { System.out.println("AscoTlc: DEBUG adding graphs for active resource: " + resource.getId()); } PrefabGraph[] prefab_graphs = getResourceService().findPrefabGraphsForResource(resource); for (PrefabGraph pg : prefab_graphs) { if (OPT_GRAPH_TYPE.equals(pg.getName())) { vGraph.setGraphtype(OPT_GRAPH_TYPE); break; } else if (DEFAULT_GRAPH_TYPE.equals(pg.getName())) { vGraph.setGraphtype(DEFAULT_GRAPH_TYPE); break; } } if (vGraph.getGraphtype() != null) { System.out.println("AscoTlc: DEBUG adding graph: " + vGraph.getResourceId()); System.out.println("AscoTlc: DEBUG adding graph: " + vGraph.getGraphtype()); newreport.addGraph(vGraph); } else { System.out.println("AscoTlc: DEBUG no default graph found: skipping resource: " + resourceId); } } System.out.println("AscoTlc: DEBUG saving KSC report for username: " + username); editor.unloadWorkingReport(getKscReportFactory()); // Save the changes to the config file getKscReportFactory().saveCurrent(); reportId = getReportId(username); if (reportId == null) throw new ServletException( "Report could not be found in config file for username: '" + username + "'"); } String overrideTimespan = WebSecurityUtils .sanitizeString(request.getParameter(Parameters.timespan.toString())); if ("null".equals(overrideTimespan) || "none".equals(overrideTimespan)) { overrideTimespan = null; } String overrideGraphType = WebSecurityUtils .sanitizeString(request.getParameter(Parameters.graphtype.toString())); if ("null".equals(overrideGraphType) || "none".equals(overrideGraphType)) { overrideGraphType = null; } // Load report to view Report report = m_kscReportFactory.getReportByIndex(reportId); if (report == null) { throw new ServletException("Report could not be found in config file for index '" + reportId + "'"); } // Get the list of available prefabricated graph options Map<String, OnmsResource> resourceMap = new HashMap<String, OnmsResource>(); Set<PrefabGraph> prefabGraphs = new TreeSet<PrefabGraph>(); removeBrokenGraphsFromReport(report); List<Graph> graphCollection = report.getGraphCollection(); if (!graphCollection.isEmpty()) { List<OnmsResource> resources = getKscReportService().getResourcesFromGraphs(graphCollection); for (int i = 0; i < graphCollection.size(); i++) { Graph graph = graphCollection.get(i); OnmsResource resource = null; try { resource = resources.get(i); } catch (IndexOutOfBoundsException e) { log().debug("Resource List Index Out Of Bounds Caught ", e); } resourceMap.put(graph.toString(), resource); if (resource == null) { log().debug("Could not get resource for graph " + graph + " in report " + report.getTitle()); } else { prefabGraphs.addAll(Arrays.asList(getResourceService().findPrefabGraphsForResource(resource))); } } // Get default graph type from first element of graph_options // XXX Do we care about the tests on reportType? } List<KscResultSet> resultSets = new ArrayList<KscResultSet>(report.getGraphCount()); for (Graph graph : graphCollection) { OnmsResource resource = resourceMap.get(graph.toString()); if (resource != null) { promoteResourceAttributesIfNecessary(resource); } String displayGraphType; if (overrideGraphType == null) { displayGraphType = graph.getGraphtype(); } else { displayGraphType = overrideGraphType; } PrefabGraph displayGraph; try { displayGraph = getResourceService().getPrefabGraph(displayGraphType); } catch (ObjectRetrievalFailureException e) { if (log().isDebugEnabled()) { log().debug("The prefabricated graph '" + displayGraphType + "' does not exist: " + e, e); } displayGraph = null; } boolean foundGraph = false; if (resource != null) { for (PrefabGraph availableGraph : getResourceService().findPrefabGraphsForResource(resource)) { if (availableGraph.equals(displayGraph)) { foundGraph = true; break; } } } if (!foundGraph) { displayGraph = null; } // gather start/stop time information String displayTimespan = null; if (overrideTimespan == null) { displayTimespan = graph.getTimespan(); } else { displayTimespan = overrideTimespan; } Calendar beginTime = Calendar.getInstance(); Calendar endTime = Calendar.getInstance(); KSC_PerformanceReportFactory.getBeginEndTime(displayTimespan, beginTime, endTime); KscResultSet resultSet = new KscResultSet(graph.getTitle(), beginTime.getTime(), endTime.getTime(), resource, displayGraph); resultSets.add(resultSet); } ModelAndView modelAndView = new ModelAndView("/dashboard/ascoTlcCustomView"); modelAndView.addObject("loggedIn", request.getRemoteUser() != null); if (report != null) { modelAndView.addObject("report", username); } modelAndView.addObject("title", report.getTitle()); modelAndView.addObject("resultSets", resultSets); if (report.getShow_timespan_button()) { if (overrideTimespan == null || !getKscReportService().getTimeSpans(true).containsKey(overrideTimespan)) { modelAndView.addObject("timeSpan", "none"); } else { modelAndView.addObject("timeSpan", overrideTimespan); } modelAndView.addObject("timeSpans", getKscReportService().getTimeSpans(true)); } else { // Make sure it's null so the pulldown list isn't shown modelAndView.addObject("timeSpan", null); } if (report.getShow_graphtype_button()) { LinkedHashMap<String, String> graphTypes = new LinkedHashMap<String, String>(); graphTypes.put("none", "none"); for (PrefabGraph graphOption : prefabGraphs) { graphTypes.put(graphOption.getName(), graphOption.getName()); } if (overrideGraphType == null || !graphTypes.containsKey(overrideGraphType)) { modelAndView.addObject("graphType", "none"); } else { modelAndView.addObject("graphType", overrideGraphType); } modelAndView.addObject("graphTypes", graphTypes); } else { // Make sure it's null so the pulldown list isn't shown modelAndView.addObject("graphType", null); } modelAndView.addObject("showCustomizeButton", false); if (report.getGraphs_per_line() > 0) { modelAndView.addObject("graphsPerLine", report.getGraphs_per_line()); } else { modelAndView.addObject("graphsPerLine", getDefaultGraphsPerLine()); } return modelAndView; }
From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java
/** * Test method for 'java.util.LinkedHashMap.putAll(Map)'. */// w w w . j av a2 s . c om public void testPutAll() { LinkedHashMap<String, String> srcMap = new LinkedHashMap<String, String>(); checkEmptyLinkedHashMapAssumptions(srcMap); srcMap.put(KEY_1, VALUE_1); srcMap.put(KEY_2, VALUE_2); srcMap.put(KEY_3, VALUE_3); // Make sure that the data is copied correctly LinkedHashMap<String, String> dstMap = new LinkedHashMap<String, String>(); checkEmptyLinkedHashMapAssumptions(dstMap); dstMap.putAll(srcMap); assertEquals(srcMap.size(), dstMap.size()); assertTrue(dstMap.containsKey(KEY_1)); assertTrue(dstMap.containsValue(VALUE_1)); assertFalse(dstMap.containsKey(KEY_1.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_1.toUpperCase(Locale.ROOT))); assertTrue(dstMap.containsKey(KEY_2)); assertTrue(dstMap.containsValue(VALUE_2)); assertFalse(dstMap.containsKey(KEY_2.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_2.toUpperCase(Locale.ROOT))); assertTrue(dstMap.containsKey(KEY_3)); assertTrue(dstMap.containsValue(VALUE_3)); assertFalse(dstMap.containsKey(KEY_3.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_3.toUpperCase(Locale.ROOT))); // Check that an empty map does not blow away the contents of the // destination map LinkedHashMap<String, String> emptyMap = new LinkedHashMap<String, String>(); checkEmptyLinkedHashMapAssumptions(emptyMap); dstMap.putAll(emptyMap); assertTrue(dstMap.size() == srcMap.size()); // Check that put all overwrite any existing mapping in the destination map srcMap.put(KEY_1, VALUE_2); srcMap.put(KEY_2, VALUE_3); srcMap.put(KEY_3, VALUE_1); dstMap.putAll(srcMap); assertEquals(dstMap.size(), srcMap.size()); assertEquals(dstMap.get(KEY_1), VALUE_2); assertEquals(dstMap.get(KEY_2), VALUE_3); assertEquals(dstMap.get(KEY_3), VALUE_1); // Check that a putAll does adds data but does not remove it srcMap.put(KEY_4, VALUE_4); dstMap.putAll(srcMap); assertEquals(dstMap.size(), srcMap.size()); assertTrue(dstMap.containsKey(KEY_4)); assertTrue(dstMap.containsValue(VALUE_4)); assertEquals(dstMap.get(KEY_1), VALUE_2); assertEquals(dstMap.get(KEY_2), VALUE_3); assertEquals(dstMap.get(KEY_3), VALUE_1); assertEquals(dstMap.get(KEY_4), VALUE_4); dstMap.putAll(dstMap); }
From source file:com.inmobi.conduit.AbstractService.java
private String getPartVal(LinkedHashMap<String, String> partSpecs, String partCol) { if (partSpecs.containsKey(partCol)) { return partSpecs.get(partCol); }/*from ww w . j ava 2s . c om*/ return null; }
From source file:com.spankingrpgs.scarletmoon.loader.CharacterLoader.java
/** * Hydrates the character's primary statistics. * * @param statistics The JSON nodes containing the character's statistics * * @return The hydrated statistics//from w w w . java2 s . co m */ private LinkedHashMap<String, Integer> hydrateStatistics(JsonNode statistics, Function<String, String> hydrateStatName, Stream<Enum> allStatisticNames) { LinkedHashMap<String, Integer> hydratedStatistics = new LinkedHashMap<>( PrimaryStatisticName.values().length); Iterator<String> statisticNames = statistics.fieldNames(); while (statisticNames.hasNext()) { String jsonStatisticName = statisticNames.next(); String statisticName = hydrateStatName.apply(jsonStatisticName); hydratedStatistics.put(statisticName, statistics.get(jsonStatisticName).asInt()); } allStatisticNames.map(Enum::name).filter(statistic -> !hydratedStatistics.containsKey(statistic)) .forEach(statistic -> hydratedStatistics.put(statistic, 0)); return hydratedStatistics; }
From source file:org.dkpro.lab.reporting.FlexTable.java
/** * Method to transpose the data in the table, turning columns into rows and vice versa. */// w ww . j ava2 s. c o m public void transposeTable() { LinkedHashMap<String, Object> newColumns = new LinkedHashMap<>(); Map<String, Map<String, V>> newRows = new LinkedHashMap<>(); for (String columnHeader : columns.keySet()) { String newRowID = columnHeader; Map<String, V> row = new LinkedHashMap<>(); Map<String, V> oldRow; for (String rowID : rows.keySet()) { if (!newColumns.containsKey(rowID)) { newColumns.put(rowID, PRESENT); } oldRow = rows.get(rowID); V value = oldRow.get(newRowID); row.put(rowID, value); } newRows.put(newRowID, row); } columns = newColumns; rows = newRows; }
From source file:com.espertech.esper.filter.FilterSpecCompiler.java
private static FilterSpecParamRangeValue handleRangeNodeEndpoint(ExprNode endpoint, LinkedHashMap<String, Pair<EventType, String>> arrayEventTypes, ExprEvaluatorContext exprEvaluatorContext, String statementName) { // constant/* w ww. j av a 2s.c om*/ if (ExprNodeUtility.isConstantValueExpr(endpoint)) { ExprConstantNode node = (ExprConstantNode) endpoint; Object value = node.evaluate(null, true, exprEvaluatorContext); if (value instanceof String) { return new RangeValueString((String) value); } else { return new RangeValueDouble(((Number) value).doubleValue()); } } if (endpoint instanceof ExprContextPropertyNode) { ExprContextPropertyNode node = (ExprContextPropertyNode) endpoint; return new RangeValueContextProp(node.getGetter()); } // or property if (endpoint instanceof ExprIdentNode) { ExprIdentNode identNodeInner = (ExprIdentNode) endpoint; if (identNodeInner.getStreamId() == 0) { return null; } if (arrayEventTypes != null && !arrayEventTypes.isEmpty() && arrayEventTypes.containsKey(identNodeInner.getResolvedStreamName())) { Pair<Integer, String> indexAndProp = getStreamIndex(identNodeInner.getResolvedPropertyName()); return new RangeValueEventPropIndexed(identNodeInner.getResolvedStreamName(), indexAndProp.getFirst(), indexAndProp.getSecond(), statementName); } else { return new RangeValueEventProp(identNodeInner.getResolvedStreamName(), identNodeInner.getResolvedPropertyName()); } } return null; }
From source file:org.rapidcontext.app.web.WebDavRequest.java
/** * Parses a property find request. All properties found will be * added to the query properties map. If no properties node was * provided, all standard properties will be added. * * @param node the properties node, or null * @param isCollection the collection flag *///ww w . jav a 2 s. c o m private void parsePropFind(Element node, boolean isCollection) { LinkedHashMap defaults; String name; defaults = isCollection ? PROPS_COLLECTION : PROPS_FILE; if (node == null) { properties.putAll(defaults); } else { Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() != Node.ELEMENT_NODE) { // Ignore non-elements } else if ("DAV:".equals(child.getNamespaceURI())) { if (defaults.containsKey(child.getLocalName())) { properties.put(child.getLocalName(), ""); } else { properties.put(child.getLocalName(), null); } } else { name = child.getNamespaceURI() + ":" + child.getLocalName(); properties.put(name, null); } child = child.getNextSibling(); } } }
From source file:org.primeframework.mvc.control.form.CountrySelect.java
/** * Adds the countries Map and then calls super. *///from w w w . j a v a2s. com @Override protected Map<String, Object> makeParameters() { LinkedHashMap<String, String> countries = new LinkedHashMap<String, String>(); if (attributes.containsKey("includeBlank") && (Boolean) attributes.get("includeBlank")) { countries.put("", ""); } String preferred = (String) attributes.get("preferredCodes"); if (preferred != null) { String[] parts = preferred.split(","); for (String part : parts) { Locale locale = new Locale("", part); countries.put(part, locale.getDisplayCountry(locale)); } } SortedSet<Locale> alphabetical = new TreeSet<Locale>(new LocaleComparator(locale)); Locale[] locales = Locale.getAvailableLocales(); for (Locale locale : locales) { if (StringUtils.isNotBlank(locale.getCountry()) && StringUtils.isNotBlank(locale.getDisplayCountry(locale))) { alphabetical.add(locale); } } for (Locale locale : alphabetical) { if (!countries.containsKey(locale.getCountry())) { countries.put(locale.getCountry(), locale.getDisplayCountry(this.locale)); } } attributes.put("items", countries); return super.makeParameters(); }