List of usage examples for java.util LinkedHashMap entrySet
public Set<Map.Entry<K, V>> entrySet()
From source file:com.streamsets.pipeline.stage.lib.hive.HiveMetastoreUtil.java
/** * Convert a Record to LinkedHashMap. This is for comparing the structure with TypeInfo in cache. * @param record incoming Record/*from w w w .ja va2 s. c o m*/ * @return LinkedHashMap version of record. Key is the column name, and value is column type in HiveType * @throws StageException */ public static LinkedHashMap<String, HiveType> convertRecordToHMSType(Record record) throws StageException { LinkedHashMap<String, HiveType> columns = new LinkedHashMap<>(); LinkedHashMap<String, Field> list = record.get().getValueAsListMap(); for (Map.Entry<String, Field> pair : list.entrySet()) { columns.put(pair.getKey(), HiveType.getHiveTypeforFieldType(pair.getValue().getType())); } return columns; }
From source file:org.loklak.api.p2p.HelloService.java
public static void propagate(final String[] hoststubs) { // get some configuration int httpport = (int) DAO.getConfig("port.http", 9000); int httpsport = (int) DAO.getConfig("port.https", 9443); String peername = (String) DAO.getConfig("peername", "anonymous"); // retrieve some simple statistics from the index final String backend = DAO.getConfig("backend", ""); final boolean backend_push = DAO.getConfig("backend.push.enabled", false); JSONObject backend_status = null;/*from www .j a v a 2 s . c om*/ JSONObject backend_status_index_sizes = null; if (backend.length() > 0 && !backend_push) { try { backend_status = StatusService.status(backend); } catch (IOException e) { Log.getLog().warn(e); } backend_status_index_sizes = backend_status == null ? null : (JSONObject) backend_status.get("index_sizes"); } long backend_messages = backend_status_index_sizes == null ? 0 : ((Number) backend_status_index_sizes.get("messages")).longValue(); long backend_users = backend_status_index_sizes == null ? 0 : ((Number) backend_status_index_sizes.get("users")).longValue(); long local_messages = DAO.countLocalMessages(-1); long local_users = DAO.countLocalUsers(); int timezoneOffset = DateParser.getTimezoneOffset(); // retrieve more complex data: date histogram LinkedHashMap<String, Long> fullDateHistogram = DAO.FullDateHistogram(timezoneOffset); // complex operation can take some time! String peakDay = ""; long peakCount = -1; String lastDay = ""; long lastCount = -1; for (Map.Entry<String, Long> day : fullDateHistogram.entrySet()) { lastDay = day.getKey(); lastCount = day.getValue(); if (lastCount > peakCount) { peakDay = lastDay; peakCount = lastCount; } } String firstDay = ""; long firstCount = -1; if (fullDateHistogram.size() > 0) { Map.Entry<String, Long> firstDayEntry = fullDateHistogram.entrySet().iterator().next(); firstDay = firstDayEntry.getKey(); firstCount = firstDayEntry.getValue(); } // send data to peers for (String hoststub : hoststubs) { if (hoststub.endsWith("/")) hoststub = hoststub.substring(0, hoststub.length() - 1); try { String urlstring = hoststub + "/api/hello.json?port.http=" + httpport + "&port.https=" + httpsport + "&peername=" + peername + "&time=" + System.currentTimeMillis() + "&timezoneOffset=" + timezoneOffset + "&local_messages=" + local_messages + "&local_users=" + local_users + "&backend_messages=" + backend_messages + "&backend_users=" + backend_users + "&peakDay=" + peakDay + "&peakCount=" + peakCount + "&firstDay=" + firstDay + "&firstCount=" + firstCount + "&lastDay=" + lastDay + "&lastCount=" + lastCount; byte[] jsonb = ClientConnection.downloadPeer(urlstring); if (jsonb == null || jsonb.length == 0) throw new IOException("empty content from " + hoststub); String jsons = UTF8.String(jsonb); JSONObject json = new JSONObject(jsons); Log.getLog().info("Hello response: " + json.toString()); } catch (IOException e) { } } }
From source file:ext.usercenter.UserAuthURLFilter.java
/** * ????// www. j a va 2 s . c o m * * @return RULE,?NULL */ private static RULE getLastMatchRule(String httpMethod, String path) { LinkedHashMap<String, RULE> urlAndRule = config.get(httpMethod); if (null != urlAndRule) { for (Map.Entry<String, RULE> e : urlAndRule.entrySet()) { boolean isMatch = pathMatcher.match(e.getKey(), path); if (isMatch) { return e.getValue(); } } } return null; }
From source file:com.streamsets.pipeline.stage.lib.hive.HiveQueryExecutor.java
private static void buildNameTypeFormatWithElements(StringBuilder sb, LinkedHashMap<String, HiveType> linkedHashMap) { boolean needComma = false; for (Map.Entry<String, HiveType> keyVal : linkedHashMap.entrySet()) { if (needComma) { sb.append(COMMA);/*from w w w . j a v a2 s . co m*/ } sb.append(String.format(COLUMN_TYPE, keyVal.getKey(), keyVal.getValue().name())); needComma = true; } }
From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.JsonNormalizer.java
private static Map<String, JacksonMonolingualTextValue> getNewLabels(LinkedHashMap<String, String> labels) { LinkedHashMap<String, JacksonMonolingualTextValue> result = new LinkedHashMap<String, JacksonMonolingualTextValue>(); if (labels != null) { for (Entry<String, String> entry : labels.entrySet()) { JacksonMonolingualTextValue mltv = new JacksonMonolingualTextValue(entry.getKey(), entry.getValue());/*w w w .j a v a 2 s .co m*/ result.put(entry.getKey(), mltv); } } return result; }
From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.JsonNormalizer.java
private static Map<String, JacksonSiteLink> getNewSiteLinks( LinkedHashMap<String, OldJacksonSiteLink> siteLinks) { Map<String, JacksonSiteLink> result = new LinkedHashMap<String, JacksonSiteLink>(); if (siteLinks != null) { for (Entry<String, OldJacksonSiteLink> entry : siteLinks.entrySet()) { String siteKey = entry.getKey(); OldJacksonSiteLink oldSitelink = entry.getValue(); JacksonObjectFactory factory = new JacksonObjectFactory(); JacksonSiteLink sitelink = (JacksonSiteLink) factory.getSiteLink(oldSitelink.getName(), siteKey, oldSitelink.getBadges()); result.put(siteKey, sitelink); }//from ww w . j a v a 2 s. co m } return result; }
From source file:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.JsonNormalizer.java
private static Map<String, List<JacksonMonolingualTextValue>> getNewAliases( LinkedHashMap<String, List<String>> aliases) { Map<String, List<JacksonMonolingualTextValue>> result = new LinkedHashMap<String, List<JacksonMonolingualTextValue>>(); if (aliases != null) { for (Entry<String, List<String>> entry : aliases.entrySet()) { String languageCode = entry.getKey(); List<String> langAliases = entry.getValue(); List<JacksonMonolingualTextValue> list = new ArrayList<JacksonMonolingualTextValue>(); result.put(languageCode, list); for (String langAlias : langAliases) { JacksonMonolingualTextValue mltv = new JacksonMonolingualTextValue(languageCode, langAlias); list.add(mltv);//from ww w.j av a 2s .c o m } } } return result; }
From source file:org.springframework.security.web.access.expression.ExpressionBasedFilterInvocationSecurityMetadataSource.java
private static LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> processMap( LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap, ExpressionParser parser) { Assert.notNull(parser, "SecurityExpressionHandler returned a null parser object"); LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestToExpressionAttributesMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>( requestMap);//from w ww .java2 s . c om for (Map.Entry<RequestMatcher, Collection<ConfigAttribute>> entry : requestMap.entrySet()) { RequestMatcher request = entry.getKey(); Assert.isTrue(entry.getValue().size() == 1, () -> "Expected a single expression attribute for " + request); ArrayList<ConfigAttribute> attributes = new ArrayList<>(1); String expression = entry.getValue().toArray(new ConfigAttribute[1])[0].getAttribute(); logger.debug("Adding web access control expression '" + expression + "', for " + request); AbstractVariableEvaluationContextPostProcessor postProcessor = createPostProcessor(request); try { attributes.add(new WebExpressionConfigAttribute(parser.parseExpression(expression), postProcessor)); } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse expression '" + expression + "'"); } requestToExpressionAttributesMap.put(request, attributes); } return requestToExpressionAttributesMap; }
From source file:com.streamsets.pipeline.stage.lib.hive.HiveQueryExecutor.java
private static void buildPartitionNameValuePair(StringBuilder sb, LinkedHashMap<String, String> partitionValueMap, Map<String, HiveType> partitionTypeMap) { boolean needComma = false; for (Map.Entry<String, String> partitionValEntry : partitionValueMap.entrySet()) { if (needComma) { sb.append(COMMA);/*from w w w.j a va2 s . c o m*/ } HiveType partitionType = partitionTypeMap.get(partitionValEntry.getKey()); String format = (QUOTES_HIVE_TYPES.contains(partitionType)) ? PARTITION_FIELD_EQUALS_QUOTES_VAL : PARTITION_FIELD_EQUALS_NON_QUOTES_VAL; sb.append(String.format(format, partitionValEntry.getKey(), partitionValEntry.getValue())); needComma = true; } }
From source file:de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.vocabulary.TopNWordsCorrelation.java
/** * Computes Spearman correlation by comparing order of two corpora vocabularies * * @param goldCorpus gold corpus/*from w w w. ja v a 2s . co m*/ * @param otherCorpus other corpus * @param topN how many entries from the gold corpus should be taken * @throws IOException I/O exception */ public static void spearmanCorrelation(File goldCorpus, File otherCorpus, int topN) throws IOException { LinkedHashMap<String, Integer> gold = loadCorpusToRankedVocabulary(new FileInputStream(goldCorpus)); LinkedHashMap<String, Integer> other = loadCorpusToRankedVocabulary(new FileInputStream(otherCorpus)); double[][] matrix = new double[topN][]; if (gold.size() < topN) { throw new IllegalArgumentException( "topN (" + topN + ") cannot be greater than vocabulary size (" + gold.size() + ")"); } Iterator<Map.Entry<String, Integer>> iterator = gold.entrySet().iterator(); int counter = 0; while (counter < topN) { Map.Entry<String, Integer> next = iterator.next(); String goldWord = next.getKey(); Integer goldValue = next.getValue(); // look-up position in other corpus Integer otherValue = other.get(goldWord); if (otherValue == null) { // System.err.println("Word " + goldWord + " not found in the other corpus"); otherValue = Integer.MAX_VALUE; } matrix[counter] = new double[2]; matrix[counter][0] = goldValue; matrix[counter][1] = otherValue; counter++; } RealMatrix realMatrix = new Array2DRowRealMatrix(matrix); SpearmansCorrelation spearmansCorrelation = new SpearmansCorrelation(realMatrix); double pValue = spearmansCorrelation.getRankCorrelation().getCorrelationPValues().getEntry(0, 1); double correlation = spearmansCorrelation.getRankCorrelation().getCorrelationMatrix().getEntry(0, 1); System.out.println("Gold: " + goldCorpus.getName()); System.out.println("Other: " + otherCorpus.getName()); System.out.printf(Locale.ENGLISH, "Top N:\n%d\nCorrelation\n%.3f\np-value\n%.3f\n", topN, correlation, pValue); }