List of usage examples for java.util LinkedHashMap size
int size();
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>(); System.out.println(lHashMap.size()); lHashMap.put("1", "One"); lHashMap.put("2", "Two"); lHashMap.put("3", "Three"); System.out.println(lHashMap.size()); Object obj = lHashMap.remove("2"); System.out.println(lHashMap.size()); }
From source file:Main.java
public static void main(String[] args) { LinkedHashMap<String, String> lHashMap = new LinkedHashMap<String, String>(); lHashMap.put("1", "One"); lHashMap.put("2", "Two"); lHashMap.put("3", "Three"); lHashMap.clear();/*from ww w .java 2s .c o m*/ System.out.println(lHashMap.size()); }
From source file:org.deegree.tools.feature.gml.MappingShortener.java
public static void main(String[] args) throws FileNotFoundException, IOException { Options options = initOptions();/*from ww w . java 2 s. c o m*/ // for the moment, using the CLI API there is no way to respond to a help argument; see // https://issues.apache.org/jira/browse/CLI-179 if (args.length == 0 || (args.length > 0 && (args[0].contains("help") || args[0].contains("?")))) { printHelp(options); } try { new PosixParser().parse(options, args); String inputFileName = options.getOption(OPT_INPUT_FILE).getValue(); String rulesFileName = options.getOption(OPT_RULES_FILE).getValue(); LinkedHashMap<String, String> rules = new LinkedHashMap<String, String>(); BufferedReader reader = new BufferedReader(new FileReader(rulesFileName)); String line = null; while ((line = reader.readLine()) != null) { line = line.trim(); int indexOfDelim = line.indexOf('='); if (indexOfDelim != -1) { String from = line.substring(0, indexOfDelim); String to = line.substring(indexOfDelim + 1, line.length()); rules.put(from, to); } } System.out.println("Loaded " + rules.size() + " rule(s) from " + rulesFileName); reader = new BufferedReader(new FileReader(inputFileName)); line = null; int maxLen = 0; String maxLenString = ""; while ((line = reader.readLine()) != null) { String shortened = applyRules(line.toLowerCase(), rules); System.out.println(line + " -> " + shortened); if (shortened.length() > maxLen) { maxLen = shortened.length(); maxLenString = shortened; } } System.err.println("MaxLen: " + maxLen + ", string: " + maxLenString); } catch (ParseException exp) { System.err.println(Messages.getMessage("TOOL_COMMANDLINE_ERROR", exp.getMessage())); // printHelp( options ); } }
From source file:Main.java
/** * For a list of Map find the entry that best matches the fieldsByPriority Ordered Map; null field values in a Map * in mapList match against any value but do not contribute to maximal match score, otherwise value for each field * in fieldsByPriority must match for it to be a candidate. *///from ww w .j av a 2s . co m public static Map<String, Object> findMaximalMatch(List<Map<String, Object>> mapList, LinkedHashMap<String, Object> fieldsByPriority) { int numFields = fieldsByPriority.size(); String[] fieldNames = new String[numFields]; Object[] fieldValues = new Object[numFields]; int index = 0; for (Map.Entry<String, Object> entry : fieldsByPriority.entrySet()) { fieldNames[index] = entry.getKey(); fieldValues[index] = entry.getValue(); index++; } int highScore = -1; Map<String, Object> highMap = null; for (Map<String, Object> curMap : mapList) { int curScore = 0; boolean skipMap = false; for (int i = 0; i < numFields; i++) { String curField = fieldNames[i]; Object compareValue = fieldValues[i]; // if curMap value is null skip field (null value in Map means allow any match value Object curValue = curMap.get(curField); if (curValue == null) continue; // if not equal skip Map if (!curValue.equals(compareValue)) { skipMap = true; break; } // add to score based on index (lower index higher score), also add numFields so more fields matched weights higher curScore += (numFields - i) + numFields; } if (skipMap) continue; // have a higher score? if (curScore > highScore) { highScore = curScore; highMap = curMap; } } return highMap; }
From source file:Main.java
public static <K, V> LinkedHashMap<K, V> headMap(LinkedHashMap<K, V> map, int endIndex, boolean inclusive) { int index = endIndex; if (inclusive) { index++;// w w w. ja v a 2 s.c o m } if ((map == null) || (map.size() == 0) || (map.size() < index) || (endIndex < 0)) { return new LinkedHashMap<K, V>(0); } LinkedHashMap<K, V> subMap = new LinkedHashMap<K, V>(index + 1); int i = 0; for (Map.Entry<K, V> entry : map.entrySet()) { if (i < index) { subMap.put(entry.getKey(), entry.getValue()); } i++; } return subMap; }
From source file:com.mycomm.dao.mydao.base.MyDaoSupport.java
/** * order by?//from www .j ava2 s . c o m * * @param orderby * @return */ protected static String buildOrderby(LinkedHashMap<String, String> orderby) { StringBuffer orderbyql = new StringBuffer(""); if (orderby != null && orderby.size() > 0) { orderbyql.append(" order by "); for (String key : orderby.keySet()) { orderbyql.append("o.").append(key).append(" ").append(orderby.get(key)).append(","); } orderbyql.deleteCharAt(orderbyql.length() - 1); } return orderbyql.toString(); }
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 ww w . j a va 2 s .com*/ * @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); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.java
public static String getIndividualProfileUrl(Individual individual, VitroRequest vreq) { WebappDaoFactory wadf = vreq.getWebappDaoFactory(); String profileUrl = null;//from ww w . jav a2 s. com try { String localName = individual.getLocalName(); String namespace = individual.getNamespace(); String defaultNamespace = wadf.getDefaultNamespace(); if (defaultNamespace.equals(namespace)) { profileUrl = getUrl(Route.DISPLAY.path() + "/" + localName); } else { if (wadf.getApplicationDao().isExternallyLinkedNamespace(namespace)) { log.debug("Found externally linked namespace " + namespace); profileUrl = namespace + localName; } else { ParamMap params = new ParamMap("uri", individual.getURI()); profileUrl = getUrl(Route.INDIVIDUAL.path(), params); } } } catch (Exception e) { log.warn(e); return null; } if (profileUrl != null) { LinkedHashMap<String, String> specialParams = getModelParams(vreq); if (specialParams.size() != 0) { profileUrl = addParams(profileUrl, new ParamMap(specialParams)); } } return profileUrl; }
From source file:dm_p2.DBSCAN.java
public static void normalize(LinkedHashMap<Integer, List<Double>> lhm) { Double[][] mydata = new Double[lhm.size()][lhm.get(1).size()]; Double[] min = new Double[lhm.get(1).size()]; Double[] max = new Double[lhm.get(1).size()]; for (int i = 1; i <= lhm.size(); i++) { List<Double> eachrow = lhm.get(i); for (int k = 0; k < eachrow.size(); k++) { mydata[i - 1][k] = eachrow.get(k); }//from w w w .j a va 2s . c om } for (int i = 0; i < lhm.get(1).size(); i++) { min[i] = 1000.0; max[i] = -1000.0; for (int k = 0; k < lhm.size(); k++) { if (mydata[k][i] < min[i]) { min[i] = mydata[k][i]; } if (mydata[k][i] > max[i]) { max[i] = mydata[k][i]; } } } for (int i = 1; i <= lhm.size(); i++) { for (int k = 0; k < lhm.get(1).size(); k++) { mydata[i - 1][k] = (mydata[i - 1][k] - min[k]) / (max[k] - min[k]); } } for (int i = 1; i <= lhm.size(); i++) { gene g = new gene(); ArrayList<Double> expval = new ArrayList<Double>(); for (int k = 0; k < lhm.get(1).size(); k++) { expval.add(mydata[i - 1][k]); //mydata[i-1][k]=(mydata[i-1][k]-min[k])/(max[k]-min[k]); } g.add(i, expval); linkedHashMap.put(i, expval); genelist.add(g); } }
From source file:ca.sfu.federation.utils.IContextUtils.java
/** * Get the list of independant elements. * @return List of elements // w w w.j av a 2 s. c om */ public static List<INamed> getIndependantElements(List<INamed> Elements) { ArrayList<INamed> independant = new ArrayList<INamed>(); // get list of elements Iterator<INamed> e = Elements.iterator(); while (e.hasNext()) { INamed named = e.next(); // if the object can have dependancies if (named instanceof IGraphable) { IGraphable graphobject = (IGraphable) named; LinkedHashMap dep = (LinkedHashMap) graphobject.getDependancies(); // if the elements has no dependancies, then it is an independant elements if (dep.size() == 0) { independant.add(named); } } } // return results return independant; }