List of usage examples for java.util TreeMap toString
public String toString()
From source file:ws.project.languagebasedlexiconanalisys.LexiconProcessor.java
public void computeTimeSeries() throws FileNotFoundException, IOException, org.json.simple.parser.ParseException { Map<String, HashSet<String>> terms = new HashMap(); String[] days;//w ww. j a v a2s. c o m JSONParser parser = new JSONParser(); JSONObject data = (JSONObject) parser.parse(new FileReader("data.json")); JSONArray array = (JSONArray) data.get("data"); days = new String[array.size()]; for (int i = 0; i < array.size(); i++) { JSONObject o = (JSONObject) array.get(i); String[] v = retrieveTermVector((String) o.get("index")); days[i] = (String) o.get("index"); for (String t : v) { if (!terms.containsKey(t)) { terms.put(t, new HashSet()); terms.get(t).add((String) o.get("index")); } else { terms.get(t).add((String) o.get("index")); } } } TreeMap<String, HashSet<String>> sorted = constructSortedMap(terms); //Arrays.sort(days); System.out.println(sorted.toString()); writeTimeSeries(sorted, days); }
From source file:de.csdev.ebus.command.datatypes.EBusAbstractType.java
@Override public IEBusType<T> getInstance(Map<String, Object> properties) { // use default instance if no properties are set if (properties == null || properties.isEmpty()) { return this; }/*from ww w .java2 s .c o m*/ // Sort all members to have a reliable key TreeMap<String, Object> sortedMap = new TreeMap<String, Object>(properties); String instanceKey = sortedMap.toString(); EBusAbstractType<T> instance = otherInstances.get(instanceKey); if (instance == null) { // create a new instance instance = createNewInstance(); // apply all properties for (Entry<String, Object> entry : properties.entrySet()) { setInstanceProperty(instance, entry.getKey(), entry.getValue()); } // store as shared instance otherInstances.put(instanceKey, instance); } return instance; }
From source file:com.clustercontrol.collect.action.RecordDataWriter.java
/** * /*from www .j a va 2 s.c o m*/ * * @param targetFacilityId * @param headerFlag * @param archiveFlag * @param folderName */ public RecordDataWriter(TreeMap<String, String> managerFacilityIdNameMap, Integer summaryType, List<CollectKeyInfoPK> targetCollectKeyInfoList, TreeMap<String, List<String>> targetManagerFacilityMap, boolean headerFlag, String filePath, String defaultDateStr) { super(); this.m_managerFacilityIdNameMap = managerFacilityIdNameMap; this.m_summaryType = summaryType; this.m_targetCollectKeyInfoList = targetCollectKeyInfoList; this.m_targetManagerFacilityMap = targetManagerFacilityMap; this.headerFlag = headerFlag; File f = new File(filePath); this.fileName = f.getName(); this.fileDir = f.getParent(); this.defaultDateStr = defaultDateStr; m_log.debug("RecordDataWriter() " + "managerFacilityIdNameMap = " + managerFacilityIdNameMap.toString() + ", summaryType = " + summaryType + ", targetManagerFacilityMap = " + targetManagerFacilityMap.toString() + ", headerFlag = " + headerFlag + ", fileOath = " + filePath + ", fileName = " + fileName + ", fileDir = " + fileDir + ", defaultDateStr = " + defaultDateStr); // ?() dlMaxWait = ClusterControlPlugin.getDefault().getPreferenceStore() .getInt(PerformancePreferencePage.P_DL_MAX_WAIT); waitCount = dlMaxWait * 60 * 1000 / waitSleep; m_log.debug("RecordDataWriter() " + "dlMaxWait = " + dlMaxWait + ", waitCount = " + waitCount); }
From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java
/** * @param candidateEval/*from w w w. ja va 2 s .c o m*/ * @param e2n * @return */ @Override public Double predictNumSubs(double candidateEval, TreeMap<Double, Double> e2n, CustomerInfo customer, int timeslot) { // tree map guarantees that keys are unique // so we are suppose to be able to run LWR // if there are at least 3 entries (even 2) // LWR, run n-fold cross validation with different bandwidth double min = e2n.firstKey(); double max = e2n.lastKey(); ArrayRealVector xVec = createNormalizedXVector(e2n.keySet(), min, max); ArrayRealVector yVec = createYVector(e2n.values()); double bestTau = Double.MAX_VALUE; double bestMSE = Double.MAX_VALUE; ArrayList<Double> candidateTaus = new ArrayList<Double>(); //candidateTaus.add(0.025 * SQUEEZE); candidateTaus.add(0.05);// * SQUEEZE); candidateTaus.add(0.1);// * SQUEEZE); candidateTaus.add(0.2);// * SQUEEZE); candidateTaus.add(0.3);// * SQUEEZE); candidateTaus.add(0.4);// * SQUEEZE); candidateTaus.add(0.5);// * SQUEEZE); candidateTaus.add(0.6);// * SQUEEZE); candidateTaus.add(0.7);// * SQUEEZE); candidateTaus.add(0.8);// * SQUEEZE); candidateTaus.add(0.9);// * SQUEEZE); candidateTaus.add(1.0);// * SQUEEZE); for (Double tau : candidateTaus) { Double mse = CrossValidationError(tau, xVec, yVec); if (null == mse) { log.error(" cp cross-validation failed, return null"); return null; } if (mse < bestMSE) { bestMSE = mse; bestTau = tau; } } log.info(" cp LWR bestTau " + bestTau); double x0 = candidateEval; Double prediction = LWRPredict(xVec, yVec, normalizeX(x0, min, max), bestTau); if (null == prediction) { log.error("LWR passed CV but cannot predict on new point. falling back to interpolateOrNN()"); log.error("e2n: " + e2n.toString()); log.error("candidateEval " + candidateEval); return null; } // cast to int, and cannot be negative return Math.max(0, (double) (int) (double) prediction); }
From source file:org.ecocean.MarkedIndividual.java
public void setDynamicProperty(String name, String value) { name = name.replaceAll(";", "_").trim().replaceAll("%20", " "); value = value.replaceAll(";", "_").trim(); if (dynamicProperties == null) { dynamicProperties = name + "=" + value + ";"; } else {//from www . j a v a 2 s . co m //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); tm.put(token.substring(0, equalPlace), token.substring(equalPlace + 1)); } if (tm.containsKey(name)) { tm.remove(name); tm.put(name, value); //now let's recreate the dynamicProperties String String newProps = tm.toString(); int stringSize = newProps.length(); dynamicProperties = newProps.substring(1, (stringSize - 1)).replaceAll(", ", ";") + ";"; } else { dynamicProperties = dynamicProperties + name + "=" + value + ";"; } } }
From source file:org.mahasen.node.MahasenPropertyPastContent.java
/** * @param id//from ww w. j a va 2 s. com * @param existingContent * @return * @throws PastException */ @Override public PastContent checkInsert(rice.p2p.commonapi.Id id, PastContent existingContent) throws PastException { if (existingContent != null) { if (((MahasenPropertyPastContent) existingContent).getTreeType() .equals(MahasenConstants.STRING_PROPERTY_TREE) && this.treeType.endsWith(MahasenConstants.STRING_PROPERTY_TREE)) { TreeMap<String, Vector<Id>> existingTree = ((MahasenPropertyPastContent) existingContent) .getPropertyTree(); log.debug("EXISTING TREE " + existingTree); log.debug("NEW TREE " + stringPropertyTree); if (existingTree != null && stringPropertyTree != null) { Iterator keys = stringPropertyTree.keySet().iterator(); while (keys.hasNext()) { String propertyValue = keys.next().toString(); log.debug("property value " + propertyValue); if (existingTree.containsKey(propertyValue)) { log.debug("existing tree contains the property value " + propertyValue); log.debug("get node for existing property value " + existingTree.get(propertyValue)); log.debug("node is to delete " + (this.isToDelete)); // this will update the Id vector for the existing property value in the exsisting TreeMap node if (!this.isToDelete) { log.debug("adding resource id to " + propertyValue); if (!existingTree.get(propertyValue) .contains(stringPropertyTree.get(propertyValue).get(0))) { existingTree.get(propertyValue) .add(stringPropertyTree.get(propertyValue).get(0)); } } else { if (existingTree.get(propertyValue) .contains(stringPropertyTree.get(propertyValue).get(0))) { log.debug("removing resource id from " + propertyValue); boolean removed = existingTree.get(propertyValue) .remove(stringPropertyTree.get(propertyValue).get(0)); log.debug("deleted " + removed); if (existingTree.get(propertyValue).size() == 0) { existingTree.remove(propertyValue); } } } } else { log.debug("existing tree does not contain the property value " + propertyValue); // this will add the new property value and the resource id to the TreeMap existingTree.put(propertyValue, stringPropertyTree.get(propertyValue)); } log.debug("Tree after modifications " + existingTree.toString()); } } } else if (((MahasenPropertyPastContent) existingContent).getTreeType() .equals(MahasenConstants.INTEGER_PROPERTY_TREE) && this.treeType.equals(MahasenConstants.INTEGER_PROPERTY_TREE)) { TreeMap<Integer, Vector<Id>> existingTree = ((MahasenPropertyPastContent) existingContent) .getPropertyTree(); log.debug("EXISTING TREE " + existingTree); log.debug("NEW TREE " + intPropertyTree); //for(String propertyValue:propertyTree.keySet()) { if (existingTree != null && intPropertyTree != null) { Iterator keys = intPropertyTree.keySet().iterator(); while (keys.hasNext()) { Integer propertyValue = Integer.valueOf(keys.next().toString()); log.debug("property value " + propertyValue); if (existingTree.containsKey(propertyValue)) { log.debug("existing tree contains the property value " + propertyValue); log.debug("get node for existing property value " + existingTree.get(propertyValue)); log.debug("node is to delete " + (this.isToDelete)); // this will update the Id vector for the existing property value in the exsisting TreeMap node if (!this.isToDelete) { if (!existingTree.get(propertyValue) .contains(intPropertyTree.get(propertyValue).get(0))) { existingTree.get(propertyValue).add(intPropertyTree.get(propertyValue).get(0)); } } else { if (existingTree.get(propertyValue) .contains(intPropertyTree.get(propertyValue).get(0))) { existingTree.get(propertyValue) .remove(intPropertyTree.get(propertyValue).get(0)); if (existingTree.get(propertyValue).size() == 0) { existingTree.remove(propertyValue); } } } } else { log.debug("existing tree does not contain the property value " + propertyValue); // this will add the new property value and the resource id to the TreeMap existingTree.put(propertyValue, intPropertyTree.get(propertyValue)); } log.debug("Existing PropertyTree" + existingTree.toString()); } } } return existingContent; } else { log.debug("===== crate a new property tree===="); log.debug("Existing PropertyTree" + this.treeType); return this; } }
From source file:org.ecocean.Encounter.java
public void removeDynamicProperty(String name) { name = name.replaceAll(";", "_").trim().replaceAll("%20", " "); if (dynamicProperties != null) { //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); tm.put(token.substring(0, (equalPlace)), token.substring(equalPlace + 1)); }//from w ww .j a v a 2 s. c o m if (tm.containsKey(name)) { tm.remove(name); //now let's recreate the dynamicProperties String String newProps = tm.toString(); int stringSize = newProps.length(); dynamicProperties = newProps.substring(1, (stringSize - 1)).replaceAll(", ", ";") + ";"; } } }
From source file:org.ecocean.Encounter.java
public void setDynamicProperty(String name, String value) { name = name.replaceAll(";", "_").trim().replaceAll("%20", " "); value = value.replaceAll(";", "_").trim(); if (dynamicProperties == null) { dynamicProperties = name + "=" + value + ";"; } else {/*w w w .j a va2s. c o m*/ //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); try { tm.put(token.substring(0, equalPlace), token.substring(equalPlace + 1)); } catch (java.lang.StringIndexOutOfBoundsException soe) { //this is a badly formatted pair that should be ignored } } if (tm.containsKey(name)) { tm.remove(name); tm.put(name, value); //now let's recreate the dynamicProperties String String newProps = tm.toString(); int stringSize = newProps.length(); dynamicProperties = newProps.substring(1, (stringSize - 1)).replaceAll(", ", ";") + ";"; } else { dynamicProperties = dynamicProperties + name + "=" + value + ";"; } } }
From source file:edu.hawaii.soest.kilonalu.adam.AdamSource.java
/** * A method that processes the data ByteBuffer passed in for the given IP * address of the ADAM sensor, parses the binary ADAM data, and flushes the * data to the DataTurbine given the sensor properties in the XMLConfiguration * passed in.// ww w. jav a 2 s. c o m * * @param datagramAddress - the IP address of the datagram of this packet of data * @param xmlConfig - the XMLConfiguration object containing the list of * sensor properties * @param sampleBuffer - the binary data sample as a ByteBuffer */ protected boolean process(String datagramAddress, XMLConfiguration xmlConfig, ByteBuffer sampleBuffer) { logger.debug("AdamSource.process() called."); // do not execute the stream if there is no connection if (!isConnected()) return false; boolean failed = false; try { // add channels of data that will be pushed to the server. // Each sample will be sent to the Data Turbine as an rbnb frame. Information // on each channel is found in the XMLConfiguration file (sensors.properties.xml) // and the AdamParser object (to get the actual voltages for each ADAM channel) ChannelMap rbnbChannelMap = new ChannelMap(); // used to flush channels ChannelMap registerChannelMap = new ChannelMap(); // used to register channels int channelIndex = 0; this.adamParser = new AdamParser(sampleBuffer); logger.debug("\n" + "channelZero : " + this.adamParser.getChannelZero() + "\n" + "channelOne : " + this.adamParser.getChannelOne() + "\n" + "channelTwo : " + this.adamParser.getChannelTwo() + "\n" + "channelThree : " + this.adamParser.getChannelThree() + "\n" + "channelFour : " + this.adamParser.getChannelFour() + "\n" + "channelFive : " + this.adamParser.getChannelFive() + "\n" + "channelSix : " + this.adamParser.getChannelSix() + "\n" + "channelSeven : " + this.adamParser.getChannelSeven() + "\n" + "channelAverage : " + this.adamParser.getChannelAverage() + "\n" + "channelZeroMax : " + this.adamParser.getChannelZeroMax() + "\n" + "channelOneMax : " + this.adamParser.getChannelOneMax() + "\n" + "channelTwoMax : " + this.adamParser.getChannelTwoMax() + "\n" + "channelThreeMax : " + this.adamParser.getChannelThreeMax() + "\n" + "channelFourMax : " + this.adamParser.getChannelFourMax() + "\n" + "channelFiveMax : " + this.adamParser.getChannelFiveMax() + "\n" + "channelSixMax : " + this.adamParser.getChannelSixMax() + "\n" + "channelSevenMax : " + this.adamParser.getChannelSevenMax() + "\n" + "channelAverageMax : " + this.adamParser.getChannelAverageMax() + "\n" + "channelZeroMin : " + this.adamParser.getChannelZeroMin() + "\n" + "channelOneMin : " + this.adamParser.getChannelOneMin() + "\n" + "channelTwoMin : " + this.adamParser.getChannelTwoMin() + "\n" + "channelThreeMin : " + this.adamParser.getChannelThreeMin() + "\n" + "channelFourMin : " + this.adamParser.getChannelFourMin() + "\n" + "channelFiveMin : " + this.adamParser.getChannelFiveMin() + "\n" + "channelSixMin : " + this.adamParser.getChannelSixMin() + "\n" + "channelSevenMin : " + this.adamParser.getChannelSevenMin() + "\n" + "channelAverageMin : " + this.adamParser.getChannelAverageMin() + "\n" ); // create a TreeMap to hold the voltageChannel and its associated // RBNB ChannelMap channel string. When the RBNB ChannelMap is // populated, this TreeMap will be consulted TreeMap<Integer, String> voltageChannelTreeMap = new TreeMap<Integer, String>(); // create a character string to store characters from the voltage values StringBuilder decimalASCIISampleData = new StringBuilder(); // Create a list of sensors from the properties file, and iterate through // the list, matching the datagram IP address to the address in the // xml configuration file. If there is a match, find the correct voltage // channel to measurement mappings, create a corresponding RBNB channel // map, and flush the data to the DataTurbine. List sensorList = xmlConfig.getList("sensor.address"); // declare the properties that will be pulled from the // sensor.properties.xml file String address = ""; String sourceName = ""; String description = ""; String type = ""; String cacheSize = ""; String archiveSize = ""; String archiveChannel = ""; String portNumber = ""; String voltageChannel = ""; String measurement = ""; // evaluate each sensor listed in the sensor.properties.xml file for (Iterator sIterator = sensorList.iterator(); sIterator.hasNext();) { // get each property value of the sensor int index = sensorList.indexOf(sIterator.next()); address = (String) xmlConfig.getProperty("sensor(" + index + ").address"); sourceName = (String) xmlConfig.getProperty("sensor(" + index + ").name"); description = (String) xmlConfig.getProperty("sensor(" + index + ").description"); type = (String) xmlConfig.getProperty("sensor(" + index + ").type"); logger.debug("Sensor details:" + "\n\t\t\t\t\t\t\t\t\t\taddress : " + address + "\n\t\t\t\t\t\t\t\t\t\tname : " + sourceName + "\n\t\t\t\t\t\t\t\t\t\tdescription : " + description + "\n\t\t\t\t\t\t\t\t\t\ttype : " + type); // move to the next sensor if this doesn't match the RBNB source name if (!sourceName.equals(getRBNBClientName())) { continue; } List portList = xmlConfig.getList("sensor(" + index + ").ports.port[@number]"); // get each port of the sensor, along with the port properties for (Iterator pIterator = portList.iterator(); pIterator.hasNext();) { int pindex = portList.indexOf(pIterator.next()); // get the port number value portNumber = (String) xmlConfig .getProperty("sensor(" + index + ").ports.port(" + pindex + ")[@number]"); logger.debug("\tport " + portNumber + " details:"); List measurementList = xmlConfig .getList("sensor(" + index + ").ports.port(" + pindex + ").measurement[@label]"); // get each measurement and voltageChannel for the given port for (Iterator mIterator = measurementList.iterator(); mIterator.hasNext();) { int mindex = measurementList.indexOf(mIterator.next()); // build the property paths into the config file String voltagePath = "sensor(" + index + ").ports.port(" + pindex + ").measurement(" + mindex + ").voltageChannel"; String measurementPath = "sensor(" + index + ").ports.port(" + pindex + ").measurement(" + mindex + ")[@label]"; // get the voltageChannel and measurement label values voltageChannel = (String) xmlConfig.getProperty(voltagePath); measurement = (String) xmlConfig.getProperty(measurementPath); logger.debug("\t\t" + "voltageChannel: " + voltageChannel + "\n\t\t\t\t\t\t\t\t\t\t\t" + "measurement label: " + measurement); // Match the datagram address with the address in the xmlConfig file if (datagramAddress.equals(address)) { // and only add channel data for this class instance RBNB Source name if (sourceName.equals(getRBNBClientName())) { // create an Integer out of the voltageChannel Integer voltageChannelInt = new Integer(voltageChannel); // build the RBNB channel path string String channelPath = "port" + "/" + portNumber + "/" + measurement; voltageChannelTreeMap.put(voltageChannelInt, channelPath); } else { logger.debug("\t\tSource names don't match: " + sourceName + " != " + getRBNBClientName()); } // end sourceName if() statement } else { logger.debug("\t\tNo IP address match. " + datagramAddress + " != " + address); } //end IP address if() statement } // end for each channel } // end for each port // now that we've found the correct sensor, exit the sensor loop break; } // end for each sensor // Build the RBNB channel map from the entries in the tree map // by doing a lookup of the ADAM voltage channel values based // on the voltage channel number in the treemap. Also add the voltages // to the DecimalASCIISampleData string (and then channel) for (Iterator vcIterator = voltageChannelTreeMap.keySet().iterator(); vcIterator.hasNext();) { int voltageChannelFromMap = ((Integer) vcIterator.next()).intValue(); String channelPathFromMap = voltageChannelTreeMap.get(voltageChannelFromMap); float voltageValue = -9999.0f; // look up the voltage value from the AdamParser object based // on the voltage channel set in the xmlConfig file (via the treemap) switch (voltageChannelFromMap) { case 0: voltageValue = this.adamParser.getChannelZero(); break; case 1: voltageValue = this.adamParser.getChannelOne(); break; case 2: voltageValue = this.adamParser.getChannelTwo(); break; case 3: voltageValue = this.adamParser.getChannelThree(); break; case 4: voltageValue = this.adamParser.getChannelFour(); break; case 5: voltageValue = this.adamParser.getChannelFive(); break; case 6: voltageValue = this.adamParser.getChannelSix(); break; case 7: voltageValue = this.adamParser.getChannelSeven(); break; } // now add the channel and the voltage value to the RBNB channel maps channelIndex = registerChannelMap.Add(channelPathFromMap); registerChannelMap.PutUserInfo(channelIndex, "units=volts"); registerChannelMap.PutUserInfo(channelIndex, "description=" + description); logger.debug("Voltage Channel Tree Map: " + voltageChannelTreeMap.toString()); // then the channel and voltage channelIndex = rbnbChannelMap.Add(channelPathFromMap); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat32(channelIndex, new float[] { voltageValue }); decimalASCIISampleData.append(String.format("%05.3f", (Object) voltageValue) + ", "); } // and only flush data for this class instance RBNB Source name if (sourceName.equals(getRBNBClientName()) && datagramAddress.equals(address)) { // add the timestamp to the rbnb channel map registerChannelMap.PutTimeAuto("server"); rbnbChannelMap.PutTimeAuto("server"); // then add a timestamp to the end of the ASCII version of the sample DATE_FORMAT.setTimeZone(TZ); String sampleDateAsString = DATE_FORMAT.format(new Date()).toString(); decimalASCIISampleData.append(sampleDateAsString); decimalASCIISampleData.append("\n"); // add the DecimalASCIISampleData channel to the channelMap channelIndex = registerChannelMap.Add(getRBNBChannelName()); channelIndex = rbnbChannelMap.Add(getRBNBChannelName()); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, decimalASCIISampleData.toString()); // Now register the RBNB channels, and flush the rbnbChannelMap to the // DataTurbine getSource().Register(registerChannelMap); getSource().Flush(rbnbChannelMap); logger.info(getRBNBClientName() + " Sample sent to the DataTurbine: " + decimalASCIISampleData.toString()); registerChannelMap.Clear(); rbnbChannelMap.Clear(); sampleBuffer.clear(); } else { logger.debug("\t\tSource names don't match: " + sourceName + " != " + getRBNBClientName()); registerChannelMap.Clear(); rbnbChannelMap.Clear(); sampleBuffer.clear(); } } catch (SAPIException sapie) { // In the event of an RBNB communication exception, log the exception, // and allow execute() to return false, which will prompt a retry. failed = true; sapie.printStackTrace(); return !failed; } return !failed; }