List of usage examples for java.util SortedMap put
V put(K key, V value);
From source file:com.aurel.track.admin.customize.localize.LocalizeBL.java
/** * Update the resources based on the properties * @param properties/*w w w . ja v a2s .c om*/ * @param strLocale * @param overwrite whether to overwrite the edited resources * @param withPrimaryKey whether the used to be BoxResources are imported or the ApplicationResources */ static synchronized void uploadResources(Properties properties, String strLocale, boolean overwrite, boolean withPrimaryKey, boolean initBoxResources) { List<TLocalizedResourcesBean> resourceBeans = getResourcesForLocale(strLocale, withPrimaryKey); SortedMap<String, List<TLocalizedResourcesBean>> existingLabels = new TreeMap<String, List<TLocalizedResourcesBean>>(); for (TLocalizedResourcesBean localizedResourcesBean : resourceBeans) { String key = localizedResourcesBean.getFieldName(); if (withPrimaryKey) { if (key.startsWith(LocalizationKeyPrefixes.FIELD_LABEL_KEY_PREFIX) || key.startsWith(LocalizationKeyPrefixes.FIELD_TOOLTIP_KEY_PREFIX)) { key += "."; } key = key + localizedResourcesBean.getPrimaryKeyValue(); } List<TLocalizedResourcesBean> localizedResources = existingLabels.get(key); if (localizedResources == null) { localizedResources = new LinkedList<TLocalizedResourcesBean>(); existingLabels.put(key, localizedResources); } localizedResources.add(localizedResourcesBean); } Enumeration propertyNames = properties.keys(); Connection connection = null; try { connection = Transaction.begin(); connection.setAutoCommit(false); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); String localizedText = LocalizeBL.correctString(properties.getProperty(key)); Integer primaryKey = null; String fieldName = null; if (withPrimaryKey) { int primaryKeyIndex = key.lastIndexOf("."); if (primaryKeyIndex != -1) { try { primaryKey = Integer.valueOf(key.substring(primaryKeyIndex + 1)); } catch (Exception e) { LOGGER.warn("The last part after . can't be converted to integer " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } fieldName = key.substring(0, primaryKeyIndex + 1); if (fieldName.startsWith(LocalizationKeyPrefixes.FIELD_LABEL_KEY_PREFIX) || fieldName.startsWith(LocalizationKeyPrefixes.FIELD_TOOLTIP_KEY_PREFIX)) { //do not have . at the end (legacy) fieldName = fieldName.substring(0, fieldName.length() - 1); } } } else { fieldName = key; } List<TLocalizedResourcesBean> localizedResources = existingLabels.get(key); if (localizedResources != null && localizedResources.size() > 1) { //remove all duplicates (as a consequence of previous erroneous imports) localizedResourcesDAO.deleteLocalizedResourcesForFieldNameAndKeyAndLocale(fieldName, primaryKey, strLocale); localizedResources = null; } if (localizedResources == null || localizedResources.isEmpty()) { //new resource TLocalizedResourcesBean localizedResourcesBean = new TLocalizedResourcesBean(); localizedResourcesBean.setFieldName(fieldName); localizedResourcesBean.setPrimaryKeyValue(primaryKey); localizedResourcesBean.setLocalizedText(localizedText); localizedResourcesBean.setLocale(strLocale); localizedResourcesDAO.insert(localizedResourcesBean); } else { //existing resource if (localizedResources.size() == 1) { TLocalizedResourcesBean localizedResourcesBean = localizedResources.get(0); if (EqualUtils.notEqual(localizedText, localizedResourcesBean .getLocalizedText()) /*&& locale.equals(localizedResourcesBean.getLocale())*/) { //text changed locally by the customer boolean textChanged = localizedResourcesBean.getTextChangedBool(); if ((textChanged == false && !initBoxResources) || (textChanged && overwrite)) { localizedResourcesBean.setLocalizedText(localizedText); localizedResourcesDAO.save(localizedResourcesBean); } } else { } } } } Transaction.commit(connection); if (!connection.isClosed()) { connection.close(); } } catch (Exception e) { LOGGER.error("Problem filling locales: " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); if (connection != null) { Transaction.safeRollback(connection); } } //delete the existing ones not found in the properties Locale locale; if (strLocale != null) { locale = LocaleHandler.getLocaleFromString(strLocale); } else { locale = Locale.getDefault(); } if (withPrimaryKey) { //not sure that all is needed but to be sure we do not miss imported localizations LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_ISSUETYPE, locale); LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_STATE, locale); LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_PRIORITY, locale); LookupContainer.resetLocalizedLookupMap(SystemFields.INTEGER_SEVERITY, locale); } ResourceBundle.clearCache(); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.significance.OutcomeSuccessMapReaderSequenceTokenCSVImpl.java
@Override public SortedMap<String, Boolean> readOutcomeSuccessMap(File file) { SortedMap<String, Boolean> result = new TreeMap<>(); List<String> lines; try {/*w ww.j av a 2 s .c o m*/ lines = FileUtils.readLines(file); } catch (IOException e) { throw new RuntimeException(e); } // first line is comment for (int i = 1; i < lines.size(); i++) { String line = lines.get(i); String[] split = line.split(","); String token = split[2]; String key = i + "_" + token; boolean res = split[0].equals(split[1]); result.put(key, res); } return result; }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbXMsgRspnHandler.CFGenKbXMsgRspnRuleTypeRecHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {/*from w ww . ja va 2s . c o m*/ // Common XML Attributes String attrId = null; String attrRevision = null; // RuleType Attributes String attrName = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RuleType"); CFGenKbXMsgRspnHandler xmsgRspnHandler = (CFGenKbXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFGenKbSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Name")) { if (attrName != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrId == null) || (attrId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Id"); } if (attrName == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Name"); } // Save named attributes to context CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext(); // Convert string attributes to native Java types short natId = Short.parseShort(attrId); String natName = attrName; int natRevision = Integer.parseInt(attrRevision); // Get the parent context CFLibXmlCoreContext parentContext = curContext.getPrevContext(); // Instantiate a buffer for the parsed information ICFGenKbRuleTypeObj obj = schemaObj.getRuleTypeTableObj().newInstance(); CFGenKbRuleTypeBuff dataBuff = obj.getRuleTypeBuff(); dataBuff.setRequiredId(natId); dataBuff.setRequiredName(natName); dataBuff.setRequiredRevision(natRevision); obj.copyBuffToPKey(); SortedMap<CFGenKbRuleTypePKey, ICFGenKbRuleTypeObj> sortedMap = (SortedMap<CFGenKbRuleTypePKey, ICFGenKbRuleTypeObj>) xmsgRspnHandler .getSortedMapOfObjects(); ICFGenKbRuleTypeObj realized = (ICFGenKbRuleTypeObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); if (sortedMap != null) { sortedMap.put(realized.getPKey(), realized); } } catch (RuntimeException e) { throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } catch (Error e) { throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } }
From source file:com.cloudera.flume.reporter.ReportEvent.java
/** * Defaults to printing data out as a bunch of html table cells. *///from ww w. j a v a2 s .c o m public void toHtml(Writer o) throws IOException { PrintWriter pw = new PrintWriter(o); pw.print("<table>"); pw.print("<tr>"); pw.print("<th>host</th>"); pw.print("<td>"); pw.print(getHost()); pw.println("</td>"); pw.print("</tr>"); // get the attributes, filter, sort and output them SortedMap<String, String> reportAttrs = new TreeMap<String, String>(); for (String attr : getAttrs().keySet()) { reportAttrs.put(attr, Attributes.toString(this, attr)); } for (Entry<String, Long> e : getAllLongMetrics().entrySet()) { reportAttrs.put(e.getKey(), e.getValue().toString()); } for (Entry<String, Double> e : getAllDoubleMetrics().entrySet()) { reportAttrs.put(e.getKey(), e.getValue().toString()); } for (Entry<String, String> e : getAllStringMetrics().entrySet()) { reportAttrs.put(e.getKey(), e.getValue()); } for (Entry<String, String> a : reportAttrs.entrySet()) { pw.println("<tr><th>" + a.getKey() + "</th>"); pw.print("<td>"); pw.print("<div class=\"" + a.getKey() + "\">"); pw.print(a.getValue()); pw.print("</div>"); pw.println("</td>"); pw.println("</tr>"); } pw.print("</table>"); }
From source file:net.sf.jtmt.summarizers.LuceneSummarizer.java
/** * Search index./*ww w . java 2 s . com*/ * * @param ramdir the ramdir * @param query the query * @return the string[] * @throws Exception the exception */ private String[] searchIndex(Directory ramdir, Query query) throws Exception { SortedMap<Integer, String> sentenceMap = new TreeMap<Integer, String>(); IndexSearcher searcher = new IndexSearcher(ramdir, true); TopDocs topDocs = searcher.search(query, numSentences); for (ScoreDoc scoreDoc : topDocs.scoreDocs) { int docId = scoreDoc.doc; Document doc = searcher.doc(docId); sentenceMap.put(scoreDoc.doc, StringUtils.chomp(doc.get("text"))); } searcher.close(); return sentenceMap.values().toArray(new String[0]); }
From source file:JTop.java
/** * Get the thread list with CPU consumption and the ThreadInfo for each thread * sorted by the CPU time./*from w ww. j a v a 2 s . co m*/ */ private List<Map.Entry<Long, ThreadInfo>> getThreadList() { // Get all threads and their ThreadInfo objects // with no stack trace long[] tids = tmbean.getAllThreadIds(); ThreadInfo[] tinfos = tmbean.getThreadInfo(tids); // build a map with key = CPU time and value = ThreadInfo SortedMap<Long, ThreadInfo> map = new TreeMap<Long, ThreadInfo>(); for (int i = 0; i < tids.length; i++) { long cpuTime = tmbean.getThreadCpuTime(tids[i]); // filter out threads that have been terminated if (cpuTime != -1 && tinfos[i] != null) { map.put(new Long(cpuTime), tinfos[i]); } } // build the thread list and sort it with CPU time // in decreasing order Set<Map.Entry<Long, ThreadInfo>> set = map.entrySet(); List<Map.Entry<Long, ThreadInfo>> list = new ArrayList<Map.Entry<Long, ThreadInfo>>(set); Collections.reverse(list); return list; }
From source file:com.aurel.track.fieldType.fieldChange.converter.CompositeSelectSetterConverter.java
/** * Convert the string to object value after load * @param value//from w w w . ja va 2s . c o m * @param setter * @return */ @Override public Object getActualValueFromStoredString(String value, Integer setter) { if (value == null || setter == null) { return null; } switch (setter.intValue()) { case FieldChangeSetters.SET_TO: SortedMap<Integer, Integer[]> actualValuesMap = new TreeMap<Integer, Integer[]>(); String[] partStringArr = value.split(PART_SPLITTER_STRING); if (partStringArr != null && partStringArr.length > 0) { for (int i = 0; i < partStringArr.length; i++) { String partString = partStringArr[i]; if (partString != null && !"".equals(partString)) { try { Integer partValue = Integer.valueOf(partString); actualValuesMap.put(Integer.valueOf(i + 1), new Integer[] { partValue }); } catch (Exception e) { LOGGER.warn("Converting the " + i + 1 + "th part " + partString + " to Integer failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } } return actualValuesMap; } return null; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgRspnHandler.CFAccXMsgRspnAuditActionRecHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {//from ww w . jav a 2 s .c o m // Common XML Attributes String attrId = null; String attrRevision = null; // AuditAction Attributes String attrAuditActionId = null; String attrDescription = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("AuditAction"); CFAccXMsgRspnHandler xmsgRspnHandler = (CFAccXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFAccSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("AuditActionId")) { if (attrAuditActionId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAuditActionId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Description")) { if (attrDescription != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDescription = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrAuditActionId == null) || (attrAuditActionId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "AuditActionId"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } // Save named attributes to context CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext(); // Convert string attributes to native Java types short natAuditActionId = Short.parseShort(attrAuditActionId); String natDescription = attrDescription; int natRevision = Integer.parseInt(attrRevision); // Get the parent context CFLibXmlCoreContext parentContext = curContext.getPrevContext(); // Instantiate a buffer for the parsed information ICFAccAuditActionObj obj = schemaObj.getAuditActionTableObj().newInstance(); CFAccAuditActionBuff dataBuff = obj.getAuditActionBuff(); dataBuff.setRequiredAuditActionId(natAuditActionId); dataBuff.setRequiredDescription(natDescription); dataBuff.setRequiredRevision(natRevision); obj.copyBuffToPKey(); SortedMap<CFAccAuditActionPKey, ICFAccAuditActionObj> sortedMap = (SortedMap<CFAccAuditActionPKey, ICFAccAuditActionObj>) xmsgRspnHandler .getSortedMapOfObjects(); ICFAccAuditActionObj realized = (ICFAccAuditActionObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); if (sortedMap != null) { sortedMap.put(realized.getPKey(), realized); } } catch (RuntimeException e) { throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } catch (Error e) { throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstXMsgRspnHandler.CFAstXMsgRspnAuditActionRecHandler.java
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try {// w ww. ja v a2 s .c om // Common XML Attributes String attrId = null; String attrRevision = null; // AuditAction Attributes String attrAuditActionId = null; String attrDescription = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("AuditAction"); CFAstXMsgRspnHandler xmsgRspnHandler = (CFAstXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFAstSchemaObj schemaObj = xmsgRspnHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("AuditActionId")) { if (attrAuditActionId != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrAuditActionId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Description")) { if (attrDescription != null) { throw CFLib.getDefaultExceptionFactory().newUniqueIndexViolationException(getClass(), S_ProcName, S_LocalName, attrLocalName); } attrDescription = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory().newUnrecognizedAttributeException(getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrAuditActionId == null) || (attrAuditActionId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "AuditActionId"); } if (attrDescription == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0, "Description"); } // Save named attributes to context CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext(); // Convert string attributes to native Java types short natAuditActionId = Short.parseShort(attrAuditActionId); String natDescription = attrDescription; int natRevision = Integer.parseInt(attrRevision); // Get the parent context CFLibXmlCoreContext parentContext = curContext.getPrevContext(); // Instantiate a buffer for the parsed information ICFAstAuditActionObj obj = schemaObj.getAuditActionTableObj().newInstance(); CFAstAuditActionBuff dataBuff = obj.getAuditActionBuff(); dataBuff.setRequiredAuditActionId(natAuditActionId); dataBuff.setRequiredDescription(natDescription); dataBuff.setRequiredRevision(natRevision); obj.copyBuffToPKey(); SortedMap<CFAstAuditActionPKey, ICFAstAuditActionObj> sortedMap = (SortedMap<CFAstAuditActionPKey, ICFAstAuditActionObj>) xmsgRspnHandler .getSortedMapOfObjects(); ICFAstAuditActionObj realized = (ICFAstAuditActionObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); if (sortedMap != null) { sortedMap.put(realized.getPKey(), realized); } } catch (RuntimeException e) { throw new RuntimeException("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } catch (Error e) { throw new Error("Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } }
From source file:org.shept.util.FtpFileCopy.java
/** * List the file directory as specified by the name filter and the path directory * The maps keys contain name and modification date for comparison * @throws IOException /* ww w . j a v a2 s.c o m*/ */ public SortedMap<FileNameDate, FTPFile> fileMapByNameAndDate(FTPClient ftp, String filePattern) throws IOException { SortedMap<FileNameDate, FTPFile> newFileMap = new TreeMap<FileNameDate, FTPFile>(); FTPFile[] files = ftp.listFiles(); for (FTPFile ftpFile : files) { if (acceptFile(ftpFile, filePattern)) { ftpFile.getTimestamp(); FileNameDate fk = new FileNameDate(ftpFile.getName(), ftpFile.getTimestamp().getTimeInMillis()); newFileMap.put(fk, ftpFile); } } return newFileMap; }