List of usage examples for java.util LinkedHashMap entrySet
public Set<Map.Entry<K, V>> entrySet()
From source file:org.apache.solr.handler.component.AlfrescoSolrClusteringComponent.java
/** * Setup the default clustering engine.//from w w w.j a v a2 s . c o m * @see "https://issues.apache.org/jira/browse/SOLR-5219" */ private static <T extends ClusteringEngine> void setupDefaultEngine(String type, LinkedHashMap<String, T> map) { // If there's already a default algorithm, leave it as is. if (map.containsKey(ClusteringEngine.DEFAULT_ENGINE_NAME)) { return; } // If there's no default algorithm, and there are any algorithms available, // the first definition becomes the default algorithm. if (!map.isEmpty()) { Entry<String, T> first = map.entrySet().iterator().next(); map.put(ClusteringEngine.DEFAULT_ENGINE_NAME, first.getValue()); log.info("Default engine for " + type + ": " + first.getKey()); } }
From source file:org.apache.solr.handler.clustering.ClusteringComponent.java
/** * Setup the default clustering engine./*from w ww . ja v a2 s . co m*/ * @see "https://issues.apache.org/jira/browse/SOLR-5219" */ private static <T extends ClusteringEngine> void setupDefaultEngine(String type, LinkedHashMap<String, T> map) { // If there's already a default algorithm, leave it as is. String engineName = ClusteringEngine.DEFAULT_ENGINE_NAME; T defaultEngine = map.get(engineName); if (defaultEngine == null || !defaultEngine.isAvailable()) { // If there's no default algorithm, and there are any algorithms available, // the first definition becomes the default algorithm. for (Map.Entry<String, T> e : map.entrySet()) { if (e.getValue().isAvailable()) { engineName = e.getKey(); defaultEngine = e.getValue(); map.put(ClusteringEngine.DEFAULT_ENGINE_NAME, defaultEngine); break; } } } if (defaultEngine != null) { log.info("Default engine for " + type + ": " + engineName + " [" + defaultEngine.getClass().getSimpleName() + "]"); } else { log.warn("No default engine for " + type + "."); } }
From source file:org.fusesource.meshkeeper.util.internal.IntrospectionSupport.java
public static String toString(Object target, Class<?> stopClass, Map<String, Object> overrideFields) { LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(); addFields(target, target.getClass(), stopClass, map); if (overrideFields != null) { for (String key : overrideFields.keySet()) { Object value = overrideFields.get(key); map.put(key, value);/*from w w w . j a va 2 s .c om*/ } } StringBuffer buffer = new StringBuffer(simpleName(target.getClass())); buffer.append(" {"); Set<Entry<String, Object>> entrySet = map.entrySet(); boolean first = true; for (Iterator<Entry<String, Object>> iter = entrySet.iterator(); iter.hasNext();) { Entry<String, Object> entry = iter.next(); if (first) { first = false; } else { buffer.append(", "); } buffer.append(entry.getKey()); buffer.append(" = "); appendToString(buffer, entry.getValue()); } buffer.append("}"); return buffer.toString(); }
From source file:com.publisnet.leydeinfogobierno.CapituloActivity.java
public static String RomanNumerals(int Int) { LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>(); roman_numerals.put("M", 1000); roman_numerals.put("CM", 900); roman_numerals.put("D", 500); roman_numerals.put("CD", 400); roman_numerals.put("C", 100); roman_numerals.put("XC", 90); roman_numerals.put("L", 50); roman_numerals.put("XL", 40); roman_numerals.put("X", 10); roman_numerals.put("IX", 9); roman_numerals.put("V", 5); roman_numerals.put("IV", 4); roman_numerals.put("I", 1); String res = ""; for (Map.Entry<String, Integer> entry : roman_numerals.entrySet()) { int matches = Int / entry.getValue(); res += repeat(entry.getKey(), matches); Int = Int % entry.getValue();/*w w w .j a v a2 s . c o m*/ } return res; }
From source file:com.act.lcms.db.analysis.AnalysisHelper.java
/** * This function does a naive scoring algorithm where it just picks the first element of the sorted hashed map as * the best metlin ion.//from w w w . j a va 2 s.co m * @param sortedIonList - This is sorted map of ion to best intensity,time values. * @return The lowest score ion, which is the best prediction. */ public static String getBestMetlinIonFromPossibleMappings(LinkedHashMap<String, XZ> sortedIonList) { String result = ""; for (Map.Entry<String, XZ> metlinIonToData : sortedIonList.entrySet()) { // Get the first value from the input since it is already sorted. result = metlinIonToData.getKey(); break; } return result; }
From source file:com.smart.common.officeFile.CSVUtils.java
/** * * @param exportData ?/*from w w w.j a va 2s .c o m*/ * @param rowMapper ?? * @param outPutPath * @param filename ?? * @return */ public static File createCSVFile(List exportData, LinkedHashMap rowMapper, String outPutPath, String filename) { File csvFile = null; BufferedWriter csvFileOutputStream = null; try { csvFile = new File(outPutPath + filename + ".csv"); // csvFile.getParentFile().mkdir(); File parent = csvFile.getParentFile(); if (parent != null && !parent.exists()) { parent.mkdirs(); } csvFile.createNewFile(); // GB2312?"," csvFileOutputStream = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(csvFile), "GB2312"), 1024); // for (Iterator propertyIterator = rowMapper.entrySet().iterator(); propertyIterator.hasNext();) { java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next(); csvFileOutputStream.write("\"" + propertyEntry.getValue().toString() + "\""); if (propertyIterator.hasNext()) { csvFileOutputStream.write(","); } } csvFileOutputStream.newLine(); // for (Iterator iterator = exportData.iterator(); iterator.hasNext();) { LinkedHashMap row = (LinkedHashMap) iterator.next(); System.out.println(row); for (Iterator propertyIterator = row.entrySet().iterator(); propertyIterator.hasNext();) { java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next(); // System.out.println(BeanUtils.getProperty(row, propertyEntry.getKey().toString())); csvFileOutputStream.write("\"" + propertyEntry.getValue().toString() + "\""); if (propertyIterator.hasNext()) { csvFileOutputStream.write(","); } } // for (Iterator propertyIterator = row.entrySet().iterator(); propertyIterator.hasNext();) { // java.util.Map.Entry propertyEntry = (java.util.Map.Entry) propertyIterator.next(); // System.out.println(BeanUtils.getProperty(row, propertyEntry.getKey().toString())); // csvFileOutputStream.write("\"" // + BeanUtils.getProperty(row, propertyEntry.getKey().toString()) + "\""); // if (propertyIterator.hasNext()) { // csvFileOutputStream.write(","); // } // } if (iterator.hasNext()) { csvFileOutputStream.newLine(); } } csvFileOutputStream.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { csvFileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return csvFile; }
From source file:org.trnltk.tokenizer.TextTokenizerCorpusTest.java
protected static void createTokenizedFile(TextTokenizer tokenizer, File sentencesFile, File tokenizedFile, File errorFile, boolean silent, TokenizationCommandCallback tokenizationCommandCallback) throws IOException { int N = 10000; final StopWatch tokenizationStopWatch = new StopWatch(); tokenizationStopWatch.start();/* ww w. ja va 2s.c om*/ tokenizationStopWatch.suspend(); // final BufferedReader lineReader = Files.newReader(sentencesFile, Charsets.UTF_8); // don't read the file into the memory // final int lineCount = lineCount(sentencesFile); // I want to know this in advance to make a ETA statement final List<String> sentences = Files.readLines(sentencesFile, Charsets.UTF_8); final int lineCount = sentences.size(); if (!silent) System.out.println("Number of lines in the file : " + lineCount); final BufferedWriter tokensWriter = Files.newWriter(tokenizedFile, Charsets.UTF_8); final PrintWriter errorWriter = errorFile != null ? new PrintWriter(Files.newWriter(errorFile, Charsets.UTF_8)) : new PrintWriter(System.out); int numberOfLinesInError = 0; int tokenCount = 0; try { // for (Iterator<String> iterator = sentences.iterator(); iterator.hasNext(); ) { // String sentence = iterator.next(); int index; for (index = 0; index < sentences.size(); index++) { final String sentence = sentences.get(index); if (!silent && index % 10000 == 0) { System.out.println("Tokenizing line #" + index); final long totalTimeSoFar = tokenizationStopWatch.getTime(); final double avgTimeForALine = Long.valueOf(totalTimeSoFar).doubleValue() / index; final double remainingTimeEstimate = avgTimeForALine * (lineCount - index); System.out.println("For file --> ETA : " + DurationFormatUtils.formatDurationHMS((long) remainingTimeEstimate) + " So far : " + tokenizationStopWatch.toString()); } if (tokenizationCommandCallback != null && index % N == 0) { tokenizationCommandCallback.reportProgress(N); } tokenizationStopWatch.resume(); final Iterable<Token> tokens; try { tokens = tokenizer.tokenize(sentence); } catch (Exception e) { // skip the line numberOfLinesInError++; e.printStackTrace(errorWriter); errorWriter.println(); tokenizationStopWatch.suspend(); continue; } tokenizationStopWatch.suspend(); final Iterator<Token> tokensIterator = tokens.iterator(); while (tokensIterator.hasNext()) { final Token token = tokensIterator.next(); tokensWriter.write(token.getSurface()); tokenCount++; if (tokensIterator.hasNext()) tokensWriter.write(" "); } tokensWriter.write("\n"); } if (tokenizationCommandCallback != null) { //report the lines since last report tokenizationCommandCallback.reportProgress(index % N); } } finally { tokensWriter.close(); errorWriter.close(); } tokenizationStopWatch.stop(); if (!silent) { System.out.println("Tokenized " + lineCount + " lines."); System.out.println("Found " + tokenCount + " tokens."); System.out.println("Avg time for tokenizing a line : " + Double.valueOf(tokenizationStopWatch.getTime()) / Double.valueOf(lineCount) + " ms"); System.out.println("\tProcessed : " + Double.valueOf(lineCount) / Double.valueOf(tokenizationStopWatch.getTime()) * 1000d + " lines in a second"); System.out.println("Avg time for generating a token : " + Double.valueOf(tokenizationStopWatch.getTime()) / Double.valueOf(tokenCount) + " ms"); System.out.println("\tProcessed : " + Double.valueOf(tokenCount) / Double.valueOf(tokenizationStopWatch.getTime()) * 1000d + " tokens in a second"); final TextTokenizer.TextTokenizerStats stats = tokenizer.getStats(); if (stats != null) { final LinkedHashMap<Pair<TextBlockTypeGroup, TextBlockTypeGroup>, Integer> successMap = stats .buildSortedSuccessMap(); System.out.println("Used " + successMap.size() + " distinct rules"); final LinkedHashMap<Pair<TextBlockTypeGroup, TextBlockTypeGroup>, Set<MissingTokenizationRuleException>> failMap = stats .buildSortedFailMap(); System.out.println("Couldn't find a rule for " + failMap.size() + " distinct specs"); System.out.println("Printing missing rules with occurrence count:"); int countOfMissing = 0; for (Map.Entry<Pair<TextBlockTypeGroup, TextBlockTypeGroup>, Set<MissingTokenizationRuleException>> entry : failMap .entrySet()) { final Pair<TextBlockTypeGroup, TextBlockTypeGroup> theCase = entry.getKey(); final Set<MissingTokenizationRuleException> exceptionsForCase = entry.getValue(); countOfMissing += exceptionsForCase.size(); System.out.println("\t" + theCase + "\t" + exceptionsForCase.size()); int i = 0; for (MissingTokenizationRuleException ex : exceptionsForCase) { final String message = ex.getMessage().replace("\t", "\t\t\t"); final String contextStr = "..." + ex.getContextBlockGroup().getText() + "..."; System.out.println("\t\t" + contextStr + "\n\t\t" + message); if (i == 2) //print only 3 messages for each case break; i++; } } System.out.println("Couldn't find a rule in a total of " + countOfMissing + " times"); } } if (tokenizationCommandCallback != null) { tokenizationCommandCallback.reportFileFinished(tokenCount, numberOfLinesInError); } }
From source file:com.alibaba.wasp.meta.TestFMetaStore.java
public static void compare(LinkedHashMap<String, Field> left, LinkedHashMap<String, Field> right) { if (compareNull(left, right)) { assertTrue(false);//from ww w . ja va 2 s. co m return; } if (left != null && right != null) { assertTrue(left.size() == right.size()); Iterator<Entry<String, Field>> leftIter = left.entrySet().iterator(); Iterator<Entry<String, Field>> rightIter = right.entrySet().iterator(); while (leftIter.hasNext()) { Field leftField = leftIter.next().getValue(); Field rightField = rightIter.next().getValue(); compare(rightField, leftField); } } }
From source file:org.jboss.pressgang.ccms.contentspec.utils.CSTransformer.java
/** * Transforms a MetaData CSNode into a FileList that can be added to a ContentSpec object. * * @param node The CSNode to be transformed. * @return The transformed FileList object. *///from w w w. j ava2 s .co m protected static FileList transformFileList(final CSNodeWrapper node) { final List<File> files = new LinkedList<File>(); // Add all the child files if (node.getChildren() != null && node.getChildren().getItems() != null) { final List<CSNodeWrapper> childNodes = node.getChildren().getItems(); final HashMap<CSNodeWrapper, File> fileNodes = new HashMap<CSNodeWrapper, File>(); for (final CSNodeWrapper childNode : childNodes) { fileNodes.put(childNode, transformFile(childNode)); } // Sort the file list nodes so that they are in the right order based on next/prev values. final LinkedHashMap<CSNodeWrapper, File> sortedMap = CSNodeSorter.sortMap(fileNodes); // Add the child nodes to the file list now that they are in the right order. final Iterator<Map.Entry<CSNodeWrapper, File>> iter = sortedMap.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<CSNodeWrapper, File> entry = iter.next(); files.add(entry.getValue()); } } return new FileList(CommonConstants.CS_FILE_TITLE, files); }
From source file:org.rti.zcore.dar.utils.InventoryUtils.java
/** * Populates stockReportMap with balances, losses, received, and onHand for each stock item * Provides report on stock by looping through itemMap. * LinkedHashMap is used to preserve the insertion order from the itemMap for display purposes. * @should populate Stock Report Maps//from www . j a va2 s.c om * @param conn * @param beginDate * @param endDate * @param siteId * @param itemMap * @throws ClassNotFoundException * @throws IOException * @throws ServletException * @throws SQLException * @throws ObjectNotFoundException */ //Method Changed By servetech Systems.........from Version 1.2e(Meshack) to 1.2f(Bolo) public static LinkedHashMap<String, StockReport> populateStockReportMaps(Connection conn, Date beginDate, Date endDate, int siteId, LinkedHashMap<Long, Item> itemMap) throws ClassNotFoundException, IOException, ServletException, SQLException, ObjectNotFoundException { String sql; LinkedHashMap<String, StockReport> stockReportMap = new LinkedHashMap<String, StockReport>(); System.out.println("Obtained all the stockReportMap"); Set<Entry<Long, Item>> itemSet = itemMap.entrySet(); for (Entry<Long, Item> entry : itemSet) { //for (DropdownItem dropdownItem : list) { //Long itemId = Long.valueOf(dropdownItem.getDropdownId()); //Map.Entry entry = (Map.Entry) iterator.next(); Long itemId = entry.getKey(); Item item = entry.getValue(); String code = item.getCode().trim().replace(" ", "_"); //Long itemId = item.getId(); System.out.println("Item Id " + itemId + " is for Item " + item.getName()); balanceBF = getbalanceBroughtFore(conn, itemId, beginDate); received = getReceivedDrugs(conn, itemId, beginDate, endDate); dispensed = getDispesed(conn, itemId, beginDate, endDate); loss = getLost(conn, itemId, beginDate, endDate); ; posAd = getPosAdjust(conn, itemId, beginDate, endDate); ; negAd = getNegAdjust(conn, itemId, beginDate, endDate); ; balanceCF = getCurrentBalance(); setExpired(conn, itemId); // keep the report easy-to-read - not a bunch of zeros. if (loss == 0) { loss = null; } if (received == 0) { received = null; } if (balanceBF == 0) { balanceBF = null; } if (balanceCF == 0) { if (balanceCF != null) { balanceCF = 0; } else { balanceCF = null; } } if (negAd == 0) { negAd = null; } if (posAd == 0) { posAd = null; } if (dispensed == 0) { dispensed = null; } if (balanceCF == 0) { balanceCF = null; } if (outDays == 0) { outDays = null; } if (quantity_for_resupply == 0) { quantity_for_resupply = null; } StockReport itemStockReport = new StockReport(); itemStockReport.setId(itemId); itemStockReport.setName(item.getName()); itemStockReport.setUnits(item.getUnit()); itemStockReport.setItem_group_id(item.getItem_group_id()); itemStockReport.setBalanceBF(balanceBF); itemStockReport.setLosses(loss); itemStockReport.setReceived(received); itemStockReport.setTotalDispensed(dispensed); itemStockReport.setNegAdjustments(negAd); itemStockReport.setPosAdjustments(posAd); itemStockReport.setDaysOutOfStock(outDays); itemStockReport.setQuantity6MonthsExpired(quantity_expired); itemStockReport.setExpiryDate(expiry_date); itemStockReport.setBalanceCF(balanceCF); itemStockReport.setQuantityRequiredResupply(quantity_for_resupply); stockReportMap.put("item" + code, itemStockReport); //log.debug("item" + code + ": " + itemStockReport.getReceived()); } return stockReportMap; }