List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:org.alfresco.web.forms.xforms.SchemaUtil.java
private static void buildTypeTree(final XSTypeDefinition type, final TreeSet<XSTypeDefinition> descendents, final TreeMap<String, TreeSet<XSTypeDefinition>> typeTree) { if (type == null) { return;/* www . j a v a 2s . c o m*/ } if (LOGGER.isDebugEnabled()) LOGGER.debug("buildTypeTree(" + type.getName() + ", " + descendents.size() + " descendents)"); if (descendents.size() > 0) { TreeSet<XSTypeDefinition> compatibleTypes = typeTree.get(type.getName()); if (compatibleTypes == null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("no compatible types found for " + type.getName() + ", creating a new set"); compatibleTypes = new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER); typeTree.put(type.getName(), compatibleTypes); } if (LOGGER.isDebugEnabled()) LOGGER.debug("adding " + descendents.size() + " descendents to " + type.getName()); compatibleTypes.addAll(descendents); } final XSTypeDefinition parentType = type.getBaseType(); if (parentType == null || type.getTypeCategory() != parentType.getTypeCategory()) { return; } if (type != parentType && parentType.getName() != null && !parentType.getName().equals("anyType")) { TreeSet<XSTypeDefinition> newDescendents = typeTree.get(parentType.getName()); if (newDescendents == null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("type tree doesn't contain " + parentType.getName() + ", creating a new descendant set"); newDescendents = new TreeSet<XSTypeDefinition>(TYPE_EXTENSION_SORTER); } if (LOGGER.isDebugEnabled()) LOGGER.debug("adding " + descendents.size() + " descendants to existing " + newDescendents.size() + " descendants of " + parentType.getName()); newDescendents.addAll(descendents); //extension (we only add it to "newDescendants" because we don't want //to have a type descendant to itself, but to consider it for the parent if (type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { final XSComplexTypeDefinition complexType = (XSComplexTypeDefinition) type; if (complexType.getDerivationMethod() == XSConstants.DERIVATION_EXTENSION && !complexType.getAbstract() && !descendents.contains(type)) { if (LOGGER.isDebugEnabled()) LOGGER.debug("adding " + type.getName() + " to existing " + newDescendents.size() + " descendents of " + parentType.getName()); newDescendents.add(type); } } //note: extensions are impossible on simpleTypes ! SchemaUtil.buildTypeTree(parentType, newDescendents, typeTree); } }
From source file:com.niki.normalizer.Metaphone.java
public static int DamerauLevenshteinDistance(String source, String target) { int m = source.length(); int n = target.length(); int[][] H = new int[m + 2][n + 2]; int INF = m + n; H[0][0] = INF;//from www . j ava 2 s .c o m for (int i = 0; i <= m; i++) { H[i + 1][1] = i; H[i + 1][0] = INF; } for (int j = 0; j <= n; j++) { H[1][j + 1] = j; H[0][j + 1] = INF; } TreeMap<Character, Integer> sd = new TreeMap<Character, Integer>(); for (int iter = 0; iter < (source + target).length(); iter++) { if (!sd.containsKey((source + target).charAt(iter))) { sd.put((source + target).charAt(iter), 0); } } for (int i = 1; i <= m; i++) { int DB = 0; for (int j = 1; j <= n; j++) { int i1 = sd.get(target.charAt(j - 1)); int j1 = DB; if (source.charAt(i - 1) == target.charAt(j - 1)) { H[i + 1][j + 1] = H[i][j]; DB = j; } else { H[i + 1][j + 1] = Math.min(H[i][j], Math.min(H[i + 1][j], H[i][j + 1])) + 1; } H[i + 1][j + 1] = Math.min(H[i + 1][j + 1], H[i1][j1] + (i - i1 - 1) + 1 + (j - j1 - 1)); } sd.put(source.charAt(i - 1), i); } return H[m + 1][n + 1]; }
From source file:module.entities.NameFinder.DB.java
public static void insertDemocracitConsultationMinister(TreeMap<Integer, String> consultationCountersign, TreeMap<Integer, String> consultationCounterrole) throws SQLException { try {//from w w w .ja v a 2s . c om String sql = "INSERT INTO consultations_ner " + "(id,countersigned_name, countersigned_position) VALUES " + "(?,?,?)"; PreparedStatement prepStatement = connection.prepareStatement(sql); for (int consId : consultationCountersign.keySet()) { prepStatement.setInt(1, consId); prepStatement.setString(2, consultationCountersign.get(consId)); if (consultationCounterrole.get(consId) != null) { prepStatement.setString(3, consultationCounterrole.get(consId)); } else { prepStatement.setString(3, ""); } prepStatement.addBatch(); } prepStatement.executeBatch(); prepStatement.close(); } catch (BatchUpdateException ex) { // ex.printStackTrace(); System.out.println(ex.getNextException()); } }
From source file:org.etudes.util.HtmlHelper.java
/** * Make the elements in alpha order, no internal spacing, all ; terminated * /*from ww w . j ava 2 s . co m*/ * @param value * @return */ public static String canonicalStyleAttribute(String value) { // break on ";" String[] parts = StringUtil.split(value, ";"); // collect style and value elements for alpha rendering TreeMap<String, String> elements = new TreeMap<String, String>(); for (String part : parts) { // break on first ":" String[] lr = StringUtil.split(part, ":"); if (lr.length == 2) { elements.put(lr[0].trim(), lr[1].trim()); } } // reform the value StringBuilder newValue = new StringBuilder(); for (String key : elements.keySet()) { String setting = elements.get(key); newValue.append(key); newValue.append(":"); newValue.append(setting); newValue.append(";"); } return newValue.toString(); }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step12GolDataExporter.java
/** * Exporting final data//from w w w.j a va2s . c om * * @param inputDir input directory with xml files * @param outputDir output directory * @throws Exception exception */ public static void exportGoldDataSimple(File inputDir, File outputDir) throws Exception { // iterate over query containers for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); SimpleSingleQueryResultContainer outputContainer = new SimpleSingleQueryResultContainer(); outputContainer.query = queryResultContainer.query; outputContainer.queryID = queryResultContainer.qID; for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) { if (rankedResult.plainText != null && !rankedResult.plainText.isEmpty()) { // first, get all the sentence IDs byte[] bytes = new BASE64Decoder() .decodeBuffer(new ByteArrayInputStream(rankedResult.originalXmi.getBytes())); JCas jCas = JCasFactory.createJCas(); XmiCasDeserializer.deserialize(new ByteArrayInputStream(bytes), jCas.getCas()); // for each sentence, we'll collect all its annotations TreeMap<Integer, Sentence> sentencesAndRelevanceAnnotations = collectSentenceIDs(jCas); // prepare output container SimpleSingleDocumentQueryResultContainer singleOutputDocument = new SimpleSingleDocumentQueryResultContainer(); singleOutputDocument.clueWebID = rankedResult.clueWebID; if (rankedResult.goldEstimatedLabels != null && !rankedResult.goldEstimatedLabels.isEmpty()) { for (QueryResultContainer.SingleSentenceRelevanceVote sentenceRelevanceVote : rankedResult.goldEstimatedLabels) { String sentenceIDString = sentenceRelevanceVote.sentenceID; Integer sentenceIDInt = Integer.valueOf(sentenceIDString); String value = sentenceRelevanceVote.relevant; Sentence sentence = sentencesAndRelevanceAnnotations.get(sentenceIDInt); ExportedSentence s = new ExportedSentence(); s.content = sentence.getCoveredText(); s.relevant = Boolean.valueOf(value); // add to the list singleOutputDocument.sentences.add(s); } outputContainer.documents.add(singleOutputDocument); } // save String xml = toXML(outputContainer); File outputFile = new File(outputDir, outputContainer.queryID + ".xml"); FileUtils.writeStringToFile(outputFile, xml, "utf-8"); } } } }
From source file:io.apiman.tools.i18n.TemplateScanner.java
/** * Scan the given html template using jsoup and find all strings that require translation. This is * done by finding all elements with a "apiman-i18n-key" attribute. * @param file/*from w w w . j a va 2s.co m*/ * @param strings * @throws IOException */ private static void scanFile(File file, TreeMap<String, String> strings) throws IOException { Document doc = Jsoup.parse(file, "UTF-8"); // First, scan for elements with the 'apiman-i18n-key' attribute. These require translating. Elements elements = doc.select("*[apiman-i18n-key]"); for (Element element : elements) { String i18nKey = element.attr("apiman-i18n-key"); boolean isNecessary = false; // Process the element text (if the element has no children) if (strings.containsKey(i18nKey)) { if (hasNoChildren(element)) { isNecessary = true; String elementVal = element.text(); if (elementVal.trim().length() > 0 && !elementVal.contains("{{")) { String currentValue = strings.get(i18nKey); if (!currentValue.equals(elementVal)) { throw new IOException("Duplicate i18n key found with different default values. Key=" + i18nKey + " Value1=" + elementVal + " Value2=" + currentValue); } } } } else { if (hasNoChildren(element)) { String elementVal = element.text(); if (elementVal.trim().length() > 0 && !elementVal.contains("{{")) { isNecessary = true; strings.put(i18nKey, elementVal); } } } // Process the translatable attributes for (String tattr : TRANSLATABLE_ATTRIBUTES) { if (element.hasAttr(tattr)) { String attrValue = element.attr(tattr); if (attrValue.contains("{{")) { continue; } String attrI18nKey = i18nKey + '.' + tattr; String currentAttrValue = strings.get(attrI18nKey); if (currentAttrValue == null) { isNecessary = true; strings.put(attrI18nKey, attrValue); } else if (!currentAttrValue.equals(attrValue)) { throw new IOException( "Duplicate i18n key found with different default values (for attribute '" + tattr + "'). Key=" + attrI18nKey + " Value1=" + attrValue + " Value2=" + currentAttrValue); } else { isNecessary = true; } } } if (!isNecessary) { throw new IOException("Detected an unnecessary apiman-i18n-key attribute in file '" + file.getName() + "' on element: " + element); } } // Next, scan all elements to see if the element *should* be marked for translation elements = doc.select("*"); for (Element element : elements) { if (element.hasAttr("apiman-i18n-key") || element.hasAttr("apiman-i18n-skip")) { continue; } if (hasNoChildren(element)) { String value = element.text(); if (value != null && value.trim().length() > 0) { if (!value.contains("{{")) { throw new IOException("Found an element in '" + file.getName() + "' that should be translated: " + element); } } } } // Next scan elements with a translatable attribute and fail if any of those elements // are missing the apiman-i18n-key attribute. for (String tattr : TRANSLATABLE_ATTRIBUTES) { elements = doc.select("*[" + tattr + "]"); for (Element element : elements) { if (element.hasAttr("apiman-i18n-key") || element.hasAttr("apiman-i18n-skip") || element.attr(tattr).contains("{{")) { continue; } else { throw new IOException("In template '" + file.getName() + "', found an element with a '" + tattr + "' attribute but missing 'apiman-i18n-key': " + element); } } } }
From source file:io.cloudslang.web.services.FlowsServiceImpl.java
@Override public FlowVo getFlow(String id, String classpath) { TreeMap<String, FlowVo> flows = getFlows(classpath); return flows.get(id); }
From source file:Main.java
public static Window getOwnerForChildWindow() { Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); if (w != null) { return w; }//w w w.j a va2s. c o m w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); if (w != null) { return w; } /* * Priority level1 * modal dialog: +200 * non-modal dialog: +100 * frame: +0 * * Priority level2 * no owned windows: +10 */ TreeMap<Integer, Window> prioMap = new TreeMap<Integer, Window>(); for (Window cand : Window.getWindows()) { if (cand == null) { continue; } if (!cand.isVisible()) { continue; } if (!cand.isShowing()) { continue; } int prio = 0; Window[] children = cand.getOwnedWindows(); if (children == null || children.length == 0) { prio += 10; } if (cand instanceof Dialog) { Dialog dlg = (Dialog) cand; if (dlg.isModal()) { prio += 200; } else { prio += 100; } prioMap.put(prio, cand); } else if (cand instanceof Frame) { if (!prioMap.containsKey(prio)) { prioMap.put(prio, cand); } } } if (prioMap.size() > 0) { return prioMap.get(prioMap.lastKey()); } //last line of defense if (prioMap.size() == 0) { for (Window cand : Window.getWindows()) { if (cand == null) { continue; } if (cand.isVisible()) { return cand; } } } return null; }
From source file:org.rhwlab.ace3d.SegmentationLinePlot.java
public void setTree(BHCTree tree) { XYSeriesCollection collect = new XYSeriesCollection(); XYSeries series = new XYSeries(""); collect.addSeries(series);/*from w ww .j av a 2 s . c o m*/ TreeMap<Integer, TreeSet<NucleusLogNode>> map = tree.allTreeCuts(500); for (Integer i : map.keySet()) { TreeSet<NucleusLogNode> nodes = map.get(i); double lnP = nodes.first().getLogPosterior(); series.add((double) i, Math.exp(lnP)); } int t = tree.getTime(); int nu = tree.getNu(); JFreeChart chart = ChartFactory.createXYLineChart( String.format("Time=%d,nu=%d,alpha=%e", tree.getTime(), tree.getNu(), tree.getAlpha()), "Index", "Probability", collect, PlotOrientation.VERTICAL, false, true, true); XYPlot plot = (XYPlot) chart.getPlot(); ChartPanel panel = new ChartPanel(chart); this.add(panel); }
From source file:com.sangupta.jerry.oauth.OAuthUtils.java
/** * Read all oauth params from the given map of parameters. * /* www .ja va 2 s . c o m*/ * @param params * @param signature * @return */ private static String getAllOAuthParams(TreeMap<String, String> params) { StringBuilder builder = new StringBuilder(); boolean first = true; for (String key : params.keySet()) { if (!key.startsWith("oauth_")) { continue; } if (!first) { builder.append(','); } else { first = false; } builder.append(key); builder.append("=\""); builder.append(UriUtils.encodeURIComponent(params.get(key), true)); builder.append('"'); } return builder.toString(); }