List of usage examples for java.util LinkedHashMap clear
public void clear()
From source file:org.fusesource.meshkeeper.distribution.MopPluginResolver.java
private synchronized MOPRepository getMopRepository() { if (MOP_REPO == null) { MOP_REPO = new MOPRepository(); if (System.getProperty(MOPRepository.MOP_BASE) == null && System.getProperty(MOPRepository.MOP_REPO_CONFIG_PROP) == null) { LOG.warn("Neither: " + MOPRepository.MOP_BASE + " or " + MOPRepository.MOP_REPO_CONFIG_PROP + " are set. Will use default repos"); }//from www . ja v a 2 s. c o m // The plexus container is created on demand /w the context classloader. // Lets load it now, so we can properly set it's classloader. ClassLoader original = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(MOPRepository.class.getClassLoader()); MOP_REPO.getContainer(); } finally { Thread.currentThread().setContextClassLoader(original); } LinkedHashMap<String, String> repositories = MOP_REPO.getRemoteRepositories(); repositories.clear(); //Add in configured repos: repositories.putAll(MOP_REPO.getConfiguredRepositories()); //Add in meshkeeper repos: repositories.put("fusesource-nexus-releases", "http://repo.fusesource.com/nexus/content/repositories/releases"); repositories.put("fusesource-nexus-snapshots", "http://repo.fusesource.com/nexus/content/repositories/snapshots"); MOP_REPO.setIncludeOptional(true); } return MOP_REPO; }
From source file:org.neo4j.gis.spatial.OsmAnalysisTest.java
public void testAnalysis2(String osm, int years, int days) throws IOException { SpatialDatabaseService spatial = new SpatialDatabaseService(graphDb()); OSMLayer layer = (OSMLayer) spatial.getLayer(osm); OSMDataset dataset = (OSMDataset) layer.getDataset(); Map<String, User> userIndex = new HashMap<String, User>(); long latestTimestamp = 0L; long firstTimestamp = Long.MAX_VALUE; try (Transaction tx = spatial.getDatabase().beginTx()) { for (Node cNode : dataset.getAllChangesetNodes()) { long timestamp = (Long) cNode.getProperty("timestamp", 0L); Node userNode = dataset.getUser(cNode); String name = (String) userNode.getProperty("name"); User user = userIndex.get(name); if (user == null) { user = new User(userNode.getId(), name); userIndex.put(name, user); }/*from ww w .jav a 2 s. c om*/ user.addChangeset(cNode, timestamp); if (latestTimestamp < timestamp) latestTimestamp = timestamp; if (firstTimestamp > timestamp) firstTimestamp = timestamp; } tx.success(); } SortedSet<User> topTen = getTopTen(userIndex); Date latest = new Date(latestTimestamp); Calendar time = Calendar.getInstance(); time.setTime(latest); int slidesPerYear = 360 / days; int slideCount = slidesPerYear * years; long msPerSlide = days * 24 * 3600000; int timeWindow = 15; StringBuffer userQuery = new StringBuffer(); int user_rank = 1; for (User user : topTen) { if (userQuery.length() > 0) userQuery.append(" or "); userQuery.append("user = '" + user.name + "'"); user_rank++; } LinkedHashMap<DynamicLayerConfig, Long> slides = new LinkedHashMap<DynamicLayerConfig, Long>(); for (int i = -timeWindow; i < slideCount; i++) { long timestamp = latestTimestamp - i * msPerSlide; long minTime = timestamp; long maxTime = timestamp + 15 * msPerSlide; time.setTimeInMillis(timestamp); Date date = new Date(timestamp); System.out.println("Preparing slides for " + date); String name = osm + "-" + date; DynamicLayerConfig config = layer.addLayerConfig(name, Constants.GTYPE_GEOMETRY, "timestamp > " + minTime + " and timestamp < " + maxTime + " and (" + userQuery + ")"); System.out.println("Added dynamic layer '" + config.getName() + "' with CQL: " + config.getQuery()); slides.put(config, timestamp); } DynamicLayerConfig config = layer.addLayerConfig(osm + "-top-ten", Constants.GTYPE_GEOMETRY, userQuery.toString()); System.out.println("Added dynamic layer '" + config.getName() + "' with CQL: " + config.getQuery()); slides.clear(); slides.put(config, 0L); StyledImageExporter imageExporter = new StyledImageExporter(graphDb()); String exportDir = "target/export/" + osm + "/analysis"; imageExporter.setExportDir(exportDir); imageExporter.setZoom(2.0); imageExporter.setOffset(-0.2, 0.25); imageExporter.setSize(1280, 800); imageExporter.setStyleFiles(new String[] { "sld/background.sld", "sld/rank.sld" }); String[] layerPropertyNames = new String[] { "name", "timestamp", "user", "days", "user_rank" }; StringBuffer userParams = new StringBuffer(); user_rank = 1; for (User user : topTen) { if (userParams.length() > 0) userParams.append(","); userParams.append(user.name).append(":").append(user_rank); user_rank++; } boolean checkedOne = false; for (DynamicLayerConfig layerToExport : slides.keySet()) { layerToExport.setExtraPropertyNames(layerPropertyNames); layerToExport.getPropertyMappingManager().addPropertyMapper("timestamp", "days", "Days", Long.toString(slides.get(layerToExport))); layerToExport.getPropertyMappingManager().addPropertyMapper("user", "user_rank", "Map", userParams.toString()); if (!checkedOne) { int i = 0; System.out.println("Checking layer '" + layerToExport + "' in detail"); try (Transaction tx = db.beginTx()) { SearchRecords records = layerToExport.getIndex().search(new SearchAll()); for (SpatialRecord record : records) { System.out.println("Got record " + i + ": " + record); for (String name : record.getPropertyNames()) { System.out.println("\t" + name + ":\t" + record.getProperty(name)); checkedOne = true; } if (i++ > 10) break; } tx.success(); } } imageExporter.saveLayerImage(new String[] { osm, layerToExport.getName() }, new File(layerToExport.getName() + ".png")); //break; } }
From source file:org.nuxeo.ecm.platform.ui.web.directory.ChainSelectListboxComponent.java
/** * Reload listbox values based on previous selections in the chain. (functionality moved from ChainSelect) *///from www. ja v a2 s. c o m public LinkedHashMap<String, DirectorySelectItem> rebuildOptions() { index = getIndex(); Map<String, Serializable> filter = new HashMap<String, Serializable>(); Boolean displayObsolete = getBooleanProperty("displayObsoleteEntries", Boolean.FALSE); if (!displayObsolete) { filter.put("obsolete", 0); } String directoryName = getDirectoryName(); String defaultRootKey = getChain().getDefaultRootKey(); if (index == 0) { if (directoryName != null) { if (DirectoryHelper.instance().hasParentColumn(directoryName)) { filter.put("parent", defaultRootKey); } } else { filter.put("parent", defaultRootKey); } } else { boolean qualifiedParentKeys = getChain().isQualifiedParentKeys(); String keySeparator = getChain().getKeySeparator(); Selection sel = getChain().getSelections()[0]; String parentValue = sel.getParentKey(index, qualifiedParentKeys, keySeparator); if (parentValue == null) { // use default parent key parentValue = defaultRootKey; } filter.put("parent", parentValue); } VocabularyEntryList directoryValues = getDirectoryValues(); List<DirectorySelectItem> list; if (directoryName != null) { list = DirectoryHelper.instance().getSelectItems(directoryName, filter); } else { list = DirectoryHelper.getSelectItems(directoryValues, filter); } for (DirectorySelectItem item : list) { String id = (String) item.getValue(); String label = item.getLabel(); String translatedLabel = label; Boolean localize = getBooleanProperty("localize", Boolean.FALSE); if (localize) { translatedLabel = translate(label); } item.setLocalizedLabel(translatedLabel); String displayedLabel = translatedLabel; Boolean displayIdAndLabel = getBooleanProperty("displayIdAndLabel", Boolean.FALSE); if (displayIdAndLabel) { displayedLabel = id + displayIdAndLabelSeparator + label; } item.setDisplayedLabel(displayedLabel); } String ordering = getStringProperty("ordering", ""); if (ordering != null && !"".equals(ordering)) { Collections.sort(list, new DirectorySelectItemComparator(ordering)); } LinkedHashMap<String, DirectorySelectItem> options = new LinkedHashMap<String, DirectorySelectItem>(); options.clear(); for (DirectorySelectItem item : list) { options.put((String) item.getValue(), item); } return options; }
From source file:org.openmrs.module.chica.DynamicFormAccess.java
/** * Save the results of the fields marked as "Export Field". * /* w w w. j a v a2 s. c o m*/ * @param formInstance FormInstance object containing the relevant form information. * @param locationTagId The location tag identifier. * @param encounterId The encounter identifier associated with the form. * @param patient The patient the form belongs to. * @param formFieldMap Map from the HTTP request that contains the field name to values. * @param parameterHandler The parameterHandler used for rule execution. */ public void saveExportElements(FormInstance formInstance, Integer locationTagId, Integer encounterId, Patient patient, Map<String, String[]> formFieldMap, ParameterHandler parameterHandler) { HashMap<String, Field> fieldMap = new HashMap<String, Field>(); FormService formService = Context.getFormService(); Form form = formService.getForm(formInstance.getFormId()); LinkedHashMap<FormField, String> formFieldToValue = new LinkedHashMap<FormField, String>(); FieldType exportType = getFieldType("Export Field"); List<FieldType> fieldTypes = new ArrayList<FieldType>(); fieldTypes.add(exportType); List<FormField> formFields = Context.getService(ChirdlUtilBackportsService.class).getFormFields(form, fieldTypes, false); List<Integer> fieldIds = new ArrayList<Integer>(); for (FormField formField : formFields) { fieldIds.add(formField.getField().getFieldId()); } Iterator<FormField> formFieldIterator = formFields.iterator(); while (formFieldIterator.hasNext()) { FormField formField = formFieldIterator.next(); org.openmrs.Field field = formField.getField(); String fieldName = field.getName(); if (!formFieldMap.containsKey(fieldName)) { continue; } Field valueField = new Field(fieldName); fieldMap.put(fieldName, valueField); String[] valueObj = formFieldMap.get(fieldName); if (valueObj == null || valueObj.length == 0) { formFieldToValue.put(formField, null); continue; } String value = valueObj[0]; formFieldToValue.put(formField, value); valueField.setValue(value); } consume(formInstance, patient, locationTagId, encounterId, fieldMap, formFieldToValue, parameterHandler, form); Context.getService(ChicaService.class).saveAnswers(fieldMap, formInstance, encounterId, patient, formFieldToValue.keySet()); fieldMap.clear(); formFieldToValue.clear(); }
From source file:org.openo.nfvo.emsdriver.collector.TaskThread.java
private boolean processCMXml(File tempfile, String nename, String type) { String csvpath = localPath + nename + "/" + type + "/"; File csvpathfile = new File(csvpath); if (!csvpathfile.exists()) { csvpathfile.mkdirs();/*from w w w. ja va2 s .c o m*/ } String csvFileName = nename + dateFormat.format(new Date()) + System.nanoTime(); String csvpathAndFileName = csvpath + csvFileName + ".csv"; BufferedOutputStream bos = null; FileOutputStream fos = null; try { fos = new FileOutputStream(csvpathAndFileName, false); bos = new BufferedOutputStream(fos, 10240); } catch (FileNotFoundException e1) { log.error("FileNotFoundException " + StringUtil.getStackTrace(e1)); } boolean FieldNameFlag = false; boolean FieldValueFlag = false; //line num int countNum = 0; String xmlPathAndFileName = null; String localName = null; String endLocalName = null; String rmUID = null; int index = -1; ArrayList<String> names = new ArrayList<String>();// colname LinkedHashMap<String, String> nameAndValue = new LinkedHashMap<String, String>(); FileInputStream fis = null; InputStreamReader isr = null; XMLStreamReader reader = null; try { fis = new FileInputStream(tempfile); isr = new InputStreamReader(fis, Constant.ENCODING_UTF8); XMLInputFactory fac = XMLInputFactory.newInstance(); reader = fac.createXMLStreamReader(isr); int event = -1; boolean setcolum = true; while (reader.hasNext()) { try { event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: localName = reader.getLocalName(); if ("FieldName".equalsIgnoreCase(localName)) { FieldNameFlag = true; } if (FieldNameFlag) { if ("N".equalsIgnoreCase(localName)) { String colName = reader.getElementText().trim(); names.add(colName); } } if ("FieldValue".equalsIgnoreCase(localName)) { FieldValueFlag = true; } if (FieldValueFlag) { if (setcolum) { xmlPathAndFileName = this.setColumnNames(nename, names, type); setcolum = false; } if ("Object".equalsIgnoreCase(localName)) { int ac = reader.getAttributeCount(); for (int i = 0; i < ac; i++) { if ("rmUID".equalsIgnoreCase(reader.getAttributeLocalName(i))) { rmUID = reader.getAttributeValue(i).trim(); } } nameAndValue.put("rmUID", rmUID); } if ("V".equalsIgnoreCase(localName)) { index = Integer.parseInt(reader.getAttributeValue(0)) - 1; String currentName = names.get(index); String v = reader.getElementText().trim(); nameAndValue.put(currentName, v); } } break; case XMLStreamConstants.CHARACTERS: break; case XMLStreamConstants.END_ELEMENT: endLocalName = reader.getLocalName(); if ("FieldName".equalsIgnoreCase(endLocalName)) { FieldNameFlag = false; } if ("FieldValue".equalsIgnoreCase(endLocalName)) { FieldValueFlag = false; } if ("Object".equalsIgnoreCase(endLocalName)) { countNum++; this.appendLine(nameAndValue, bos); nameAndValue.clear(); } break; } } catch (Exception e) { log.error("" + StringUtil.getStackTrace(e)); event = reader.next(); } } if (bos != null) { bos.close(); bos = null; } if (fos != null) { fos.close(); fos = null; } String[] fileKeys = this.createZipFile(csvpathAndFileName, xmlPathAndFileName, nename); //ftp store Properties ftpPro = configurationInterface.getProperties(); String ip = ftpPro.getProperty("ftp_ip"); String port = ftpPro.getProperty("ftp_port"); String ftp_user = ftpPro.getProperty("ftp_user"); String ftp_password = ftpPro.getProperty("ftp_password"); String ftp_passive = ftpPro.getProperty("ftp_passive"); String ftp_type = ftpPro.getProperty("ftp_type"); String remoteFile = ftpPro.getProperty("ftp_remote_path"); this.ftpStore(fileKeys, ip, port, ftp_user, ftp_password, ftp_passive, ftp_type, remoteFile); //create Message String message = this.createMessage(fileKeys[1], ftp_user, ftp_password, ip, port, countNum, nename); //set message this.setMessage(message); } catch (Exception e) { log.error("" + StringUtil.getStackTrace(e)); return false; } finally { try { if (reader != null) { reader.close(); } if (isr != null) { isr.close(); } if (fis != null) { fis.close(); } if (bos != null) { bos.close(); } if (fos != null) { fos.close(); } } catch (Exception e) { log.error(e); } } return true; }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.xpath.XPathTableModel.java
public XPathTableModel(final ResourceData xmlResource, final ResourceManager resourceManager, final String xPathExpression, final DataRow parameters, final int maxRowsToProcess) throws ReportDataFactoryException { try {/*w w w . j av a 2 s . c om*/ columnTypes = new ArrayList<Class>(); final XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setXPathVariableResolver(new InternalXPathVariableResolver(parameters)); // load metadata (number of rows, row names, row types) final String nodeValue = computeColDeclaration(xmlResource, resourceManager, xPath); if (nodeValue != null) { final StringTokenizer stringTokenizer = new StringTokenizer(nodeValue, ","); while (stringTokenizer.hasMoreTokens()) { final String className = stringTokenizer.nextToken(); if (SUPPORTED_TYPES.containsKey(className)) { columnTypes.add(SUPPORTED_TYPES.get(className)); } else { columnTypes.add(String.class); } } } if (maxRowsToProcess == -1) { dataLimit = Integer.MAX_VALUE; } else { this.dataLimit = Math.min(1, maxRowsToProcess); } backend = new TypedTableModel(); final LinkedHashMap<String, String> results = new LinkedHashMap<String, String>(); // try to find all valid column names // visit all entries and add the names as we find them final NodeList rows = evaluateNodeList(xPath, xPathExpression, xmlResource, resourceManager); for (int r = 0; r < rows.getLength(); r++) { // Get the next value from the result sequence final Node rowValue = rows.item(r); final short nodeType = rowValue.getNodeType(); // Print this value if (nodeType == Node.ELEMENT_NODE) { // explodes into columns .. if (processNode(rowValue, results, backend) == false) { return; } } else { final String columnName = rowValue.getNodeValue(); results.put(columnName, rowValue.toString()); if (addRow(results, backend) == false) { return; } results.clear(); } // System.out.println("NodeType: " + nodeType + "\n" + value.toString()); } } catch (Exception e) { throw new ReportDataFactoryException("Failed to query XPath datasource", e); } }
From source file:org.romaframework.aspect.view.form.FormViewer.java
public void sync(Screen iScreen) { LinkedHashMap<String, Object> queuedForms = (LinkedHashMap<String, Object>) Roma.session() .getProperty("formQueue"); if (queuedForms != null) { for (Map.Entry<String, Object> entry : queuedForms.entrySet()) { Roma.view().show(entry.getValue(), entry.getKey(), iScreen, null); }//from www . j a va 2 s . c om queuedForms.clear(); Roma.session().setProperty("formQueue", null); } }
From source file:org.spout.api.chat.ChatArguments.java
/** * Splits this ChatArguments instance into sections * * @param type How these arguments are to be split into sections * @return The split sections/*from www .j a v a2s .c o m*/ */ public List<ChatSection> toSections(SplitType type) { List<ChatSection> sections = new ArrayList<ChatSection>(); StringBuilder currentWord = new StringBuilder(); LinkedHashMap<Integer, List<ChatStyle>> map; switch (type) { case WORD: map = new LinkedHashMap<Integer, List<ChatStyle>>(); int curIndex = 0; for (Object obj : getExpandedPlaceholders()) { if (obj instanceof ChatStyle) { ChatStyle style = (ChatStyle) obj; List<ChatStyle> list = map.get(curIndex); if (list == null) { list = new ArrayList<ChatStyle>(); map.put(curIndex, list); } ChatSectionUtils.removeConflicting(list, style); list.add(style); } else { String val = String.valueOf(obj); for (int i = 0; i < val.length(); ++i) { int codePoint = val.codePointAt(i); if (Character.isWhitespace(codePoint)) { sections.add(new ChatSectionImpl(type, new LinkedHashMap<Integer, List<ChatStyle>>(map), currentWord.toString())); curIndex = 0; currentWord = new StringBuilder(); if (map.size() > 0) { final List<ChatStyle> previousStyles = map.containsKey(-1) ? new ArrayList<ChatStyle>(map.get(-1)) : new ArrayList<ChatStyle>(); for (Map.Entry<Integer, List<ChatStyle>> entry : map.entrySet()) { if (entry.getKey() != -1) { for (ChatStyle style : entry.getValue()) { ChatSectionUtils.removeConflicting(previousStyles, style); previousStyles.add(style); } } } map.clear(); map.put(-1, previousStyles); } } else { currentWord.append(val.substring(i, i + 1)); curIndex++; } } } } if (currentWord.length() > 0) { sections.add(new ChatSectionImpl(type, map, currentWord.toString())); } break; case STYLE_CHANGE: StringBuilder curSection = new StringBuilder(); List<ChatStyle> activeStyles = new ArrayList<ChatStyle>(3); for (Object obj : getExpandedPlaceholders()) { if (obj instanceof ChatStyle) { ChatStyle style = (ChatStyle) obj; ChatSectionUtils.removeConflicting(activeStyles, style); activeStyles.add(style); map = new LinkedHashMap<Integer, List<ChatStyle>>(); map.put(-1, new ArrayList<ChatStyle>(activeStyles)); sections.add(new ChatSectionImpl(type, map, curSection.toString())); curSection = new StringBuilder(); } else { curSection.append(obj); } } break; case ALL: return Collections.<ChatSection>singletonList( new ChatSectionImpl(getSplitType(), getActiveStyles(), getPlainString())); default: throw new IllegalArgumentException("Unknown SplitOption " + type + "!"); } return sections; }