List of usage examples for java.util TreeMap entrySet
EntrySet entrySet
To view the source code for java.util TreeMap entrySet.
Click Source Link
From source file:org.jszip.pseudo.io.PseudoFileSystem.java
public PseudoFile[] listChildren(PseudoFile dir, PseudoFileFilter filter) { TreeMap<String, Layer> names = new TreeMap<String, Layer>(); final String path = dir.getAbsolutePath(this); for (int i = layers.length - 1; i >= 0; i--) { for (String name : layers[i].listChildren(path)) { names.put(name, layers[i]);/*from ww w .j a va 2s . co m*/ } } List<PseudoFile> result = new ArrayList<PseudoFile>(names.size()); for (Map.Entry<String, Layer> entry : names.entrySet()) { if (filter.accept(entry.getKey())) { result.add(entry.getValue().makeChild(this, dir, entry.getKey())); } } return result.toArray(new PseudoFile[result.size()]); }
From source file:com.ngdata.hbaseindexer.mr.HBaseIndexerMapper.java
@Override protected void setup(Context context) throws IOException, InterruptedException { super.setup(context); Utils.getLogConfigFile(context.getConfiguration()); if (LOG.isTraceEnabled()) { LOG.trace("CWD is {}", new File(".").getCanonicalPath()); TreeMap map = new TreeMap(); for (Map.Entry<String, String> entry : context.getConfiguration()) { map.put(entry.getKey(), entry.getValue()); }// w w w . j av a 2 s . c o m LOG.trace("Mapper configuration:\n{}", Joiner.on("\n").join(map.entrySet())); } String indexName = context.getConfiguration().get(INDEX_NAME_CONF_KEY); String indexerComponentFactory = context.getConfiguration().get(INDEX_COMPONENT_FACTORY_KEY); String indexConfiguration = context.getConfiguration().get(INDEX_CONFIGURATION_CONF_KEY); String tableName = context.getConfiguration().get(TABLE_NAME_CONF_KEY); if (indexName == null) { throw new IllegalStateException("No configuration value supplied for " + INDEX_NAME_CONF_KEY); } if (indexConfiguration == null) { throw new IllegalStateException("No configuration value supplied for " + INDEX_CONFIGURATION_CONF_KEY); } if (tableName == null) { throw new IllegalStateException("No configuration value supplied for " + TABLE_NAME_CONF_KEY); } Map<String, String> indexConnectionParams = getIndexConnectionParams(context.getConfiguration()); IndexerComponentFactory factory = IndexerComponentFactoryUtil.getComponentFactory(indexerComponentFactory, new ByteArrayInputStream(indexConfiguration.getBytes(Charsets.UTF_8)), indexConnectionParams); IndexerConf indexerConf = factory.createIndexerConf(); String morphlineFile = context.getConfiguration().get(MorphlineResultToSolrMapper.MORPHLINE_FILE_PARAM); Map<String, String> params = indexerConf.getGlobalParams(); if (morphlineFile != null) { params.put(MorphlineResultToSolrMapper.MORPHLINE_FILE_PARAM, morphlineFile); } String morphlineId = context.getConfiguration().get(MorphlineResultToSolrMapper.MORPHLINE_ID_PARAM); if (morphlineId != null) { params.put(MorphlineResultToSolrMapper.MORPHLINE_ID_PARAM, morphlineId); } for (Map.Entry<String, String> entry : context.getConfiguration()) { if (entry.getKey().startsWith(MorphlineResultToSolrMapper.MORPHLINE_VARIABLE_PARAM + ".")) { params.put(entry.getKey(), entry.getValue()); } if (entry.getKey().startsWith(MorphlineResultToSolrMapper.MORPHLINE_FIELD_PARAM + ".")) { params.put(entry.getKey(), entry.getValue()); } } ResultToSolrMapper mapper = factory.createMapper(indexName); // TODO This would be better-placed in the top-level job setup -- however, there isn't currently any // infrastructure to handle converting an in-memory model into XML (we can only interpret an // XML doc into the internal model), so we need to do this here for now if (indexerConf.getRowReadMode() != RowReadMode.NEVER) { LOG.warn("Changing row read mode from " + indexerConf.getRowReadMode() + " to " + RowReadMode.NEVER); indexerConf = new IndexerConfBuilder(indexerConf).rowReadMode(RowReadMode.NEVER).build(); } indexerConf.setGlobalParams(params); try { indexer = createIndexer(indexName, context, indexerConf, tableName, mapper, indexConnectionParams); } catch (SharderException e) { throw new RuntimeException(e); } }
From source file:org.dllearner.algorithms.probabilistic.structure.unife.leap.AbstractLEAP.java
protected void printTimings(long totalTimeMills, long celaTimeMills, TreeMap<String, Long> timeMap) { logger.info("Main: " + totalTimeMills + " ms"); logger.info("CELOE: " + celaTimeMills + " ms"); long timeOther = totalTimeMills - celaTimeMills; for (Entry<String, Long> time : timeMap.entrySet()) { String names[] = time.getKey().split("\\."); if (names.length == 1) { timeOther -= time.getValue(); // logger.info(timeMap.subMap(names[0], names[0] + Character.MAX_VALUE).toString()); }/*from w ww . j a v a 2 s . com*/ String output = StringUtils.repeat("\t", names.length - 1); output += names[names.length - 1] + ": " + time.getValue() + " ms"; logger.info(output); } // logger.info("EDGE: " + (timeMap.get("EM") + timeMap.get("Bundle")) + " ms"); // logger.info("\tBundle: " + timeMap.get("Bundle") + " ms"); // logger.info("\tEM: " + timeMap.get("EM") + " ms"); // long timeOther = totalTimeMills - celaTimeMills - (timeMap.get("EM") + timeMap.get("Bundle")); logger.info("Other: " + timeOther + " ms"); logger.info("Program client: execution successfully terminated"); }
From source file:checkdb.CheckDb.java
private void makeChanPointerTable(String ifoSubsys) throws SQLException { cidx.streamByName(ifoSubsys + "%"); ChanIndexInfo cii;//from w ww . j av a2 s . co m // one pass through the ChannelIndex table to set the Index ID in our in memory Map while ((cii = cidx.streamNext()) != null) { int indexID = cii.getIndexID(); TreeMap<String, ChanStat> serverList = chanstats.get(cii.getName()); if (serverList == null) { System.err.println("Channel in db not found in list: " + cii.getName()); } else { for (Entry<String, ChanStat> ent : serverList.entrySet()) { ent.getValue().setIndexID(indexID); } } } // another pass through the in memory Map to write out the pointer for (Entry<String, TreeMap<String, ChanStat>> csl : chanstats.entrySet()) { String cname = csl.getKey(); TreeMap<String, ChanStat> serverList = csl.getValue(); for (Entry<String, ChanStat> ent : serverList.entrySet()) { ArrayList<ChanPointer> chanPointerList = ent.getValue().getChanPointerList(); for (ChanPointer chp : chanPointerList) { cpt.insertNewBulk(chp); } } } cpt.insertNewBulk(null); }
From source file:gda.jython.commands.ScannableCommands.java
/** * The pos command. Reports the current position of a scannable or moves one or more scannables concurrently. * //from ww w .j a v a 2s. c o m * @param args * @return String reporting final positions * @throws Exception * - any exception within this method */ public static String pos(Object... args) throws Exception { if (args.length == 1) { if (args[0] == null) {// example: pos None, Jython command: pos([None]) throw new Exception( "Usage: pos [ScannableName] - returns the position of all Scannables [or the given scannable]"); } else if (args[0] instanceof IScannableGroup) { return ScannableUtils.prettyPrintScannableGroup((IScannableGroup) args[0]); } else if (args[0] instanceof ScannableBase) {// example: pos pseudoDeviceName, Jython command: // pos([pseudoDeviceName]) return ((ScannableBase) args[0]).__str__().toString(); } return args[0].toString(); } else if (args.length >= 2) {// example pos pseudoDeviceName newPosition, Jython command: // pos([pseudoDeviceName, newPosition] // identify scannables and the positions to move them to Scannable[] scannableList = new Scannable[args.length / 2]; HashMap<Scannable, Object> positionMap = new HashMap<Scannable, Object>(); int j = 0; for (int i = 0; i < args.length; i += 2) { if (args[i] instanceof Scannable) { scannableList[j] = (Scannable) args[i]; positionMap.put((Scannable) args[i], args[i + 1]); j++; } } // Check positions valid for (Scannable scannable : scannableList) { Object target = positionMap.get(scannable); if (!(scannable instanceof Detector)) { raiseDeviceExceptionIfPositionNotValid(scannable, target); } } try { // Group by level TreeMap<Integer, List<Scannable>> scannablesByLevel = new TreeMap<Integer, List<Scannable>>(); for (Scannable scn : scannableList) { Integer level = scn.getLevel(); if (!scannablesByLevel.containsKey(level)) { scannablesByLevel.put(level, new ArrayList<Scannable>()); } scannablesByLevel.get(level).add(scn); } // Move scannables of the same level concurrently String output = "Move completed: "; // KLUDGE for (Entry<Integer, List<Scannable>> currentLevelScannables : scannablesByLevel.entrySet()) { for (Scannable scn1 : currentLevelScannables.getValue()) { scn1.atLevelStart(); } for (Scannable scn1 : currentLevelScannables.getValue()) { scn1.atLevelMoveStart(); } // asynchronousMoveTo() for (Scannable scn1 : currentLevelScannables.getValue()) { if (scn1 instanceof DetectorSnapper) { Double collectionTime = PositionConvertorFunctions.toDouble(positionMap.get(scn1)); ((DetectorSnapper) scn1).prepareForAcquisition(collectionTime); ((DetectorSnapper) scn1).acquire(); } else if (scn1 instanceof Detector) { Double collectionTime = PositionConvertorFunctions.toDouble(positionMap.get(scn1)); ((Detector) scn1).setCollectionTime(collectionTime); ((Detector) scn1).prepareForCollection(); ((Detector) scn1).collectData(); } else { scn1.asynchronousMoveTo(positionMap.get(scn1)); } } // **isBusy()** // Wait for all moves to complete. If there is a problem with one, then stop the Scannables // which may still be moving (those that have not yet been waited for), and _then_ throw the // exception. Exception exceptionCaughtWhileWaitingOnIsBusy = null; for (Scannable scn1 : currentLevelScannables.getValue()) { if (exceptionCaughtWhileWaitingOnIsBusy == null) { // normal behaviour try { scn1.waitWhileBusy(); } catch (Exception e) { logger.error("Exception occured while waiting for " + scn1.getName() + " to complete move: ", e.getMessage()); // cause future passes through the loop to stop Scannables exceptionCaughtWhileWaitingOnIsBusy = e; } } else { // stop any motors that may be still moving try { logger.info("Stopping " + scn1.getName() + " due to problem moving previous scannable."); scn1.stop(); } catch (DeviceException e) { logger.error("Caught exception while stopping " + scn1.getName() + ": " + e.getMessage()); } } } if (exceptionCaughtWhileWaitingOnIsBusy != null) { throw exceptionCaughtWhileWaitingOnIsBusy; } for (Scannable scn1 : currentLevelScannables.getValue()) { scn1.atLevelEnd(); } } if (scannableList.length > 1) { output += "\n"; } // return position for (Scannable scn3 : scannableList) { output += ScannableUtils.getFormattedCurrentPosition(scn3) + "\n"; } return output.trim(); } catch (Exception e) { // Call the atCommandFailure() hooks for (Scannable scn : scannableList) { scn.atCommandFailure(); } throw e; } } return ""; }
From source file:org.yccheok.jstock.gui.portfolio.AutoDividendJDialog.java
/** * Creates new form AutoDividendJDialog//from w w w.ja va 2 s . c om */ public AutoDividendJDialog(java.awt.Frame parent, boolean modal, Map<Code, List<Dividend>> dividends) { super(parent, modal); initComponents(); JPanel panel = new JPanel(); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); TreeMap<Code, List<Dividend>> treeMap = new TreeMap<Code, List<Dividend>>(new Comparator<Code>() { @Override public int compare(Code o1, Code o2) { return o1.toString().compareTo(o2.toString()); } }); treeMap.putAll(dividends); for (Map.Entry<Code, List<Dividend>> entry : treeMap.entrySet()) { AutoDividendJPanel autoDividendJPanel = new AutoDividendJPanel(this, entry.getValue()); autoDividendJPanels.add(autoDividendJPanel); panel.add(autoDividendJPanel); panel.add(Box.createRigidArea(new Dimension(0, 5))); } this.jScrollPane1.setViewportView(panel); updateTotalLabel(); }
From source file:org.opencms.workplace.tools.content.CmsElementChangeLocaleDialog.java
/** * returns the selector widget options to build a template selector widget.<p> * //from w w w .j av a 2 s . c om * @return the selector widget options to build a template selector widget */ public List getTemplateConfigOptions() { List result = new ArrayList(); result.add( new CmsSelectWidgetOption("", true, key(Messages.GUI_CHANGEELEMENTLOCALE_DIALOG_TEMPLATE_ALL_0))); TreeMap templates = null; try { // get all available templates templates = CmsNewResourceXmlPage.getTemplates(getCms(), null); } catch (CmsException e) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(e); } } if (templates != null) { // templates found, create option and value lists Iterator i = templates.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); String key = (String) entry.getKey(); String path = (String) entry.getValue(); result.add(new CmsSelectWidgetOption(path, false, key)); } } return result; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.ClusterCentroidsMain.java
public static TreeMap<Integer, Vector> computeClusterCentroids(String inputVectorsPath, String clusterOutputPath) throws IOException { TreeMap<Integer, Vector> result = new TreeMap<>(); Map<Integer, Integer> counts = new TreeMap<>(); // input for cluto File inputVectors = new File(inputVectorsPath); // resulting clusters File clutoClustersOutput = new File(clusterOutputPath); LineIterator clustersIterator = IOUtils.lineIterator(new FileInputStream(clutoClustersOutput), "utf-8"); LineIterator vectorsIterator = IOUtils.lineIterator(new FileInputStream(inputVectors), "utf-8"); // skip first line (number of clusters and vector size vectorsIterator.next();/*from ww w. j a v a 2 s .c o m*/ while (clustersIterator.hasNext()) { String clusterString = clustersIterator.next(); String vectorString = vectorsIterator.next(); int clusterNumber = Integer.valueOf(clusterString); // now parse the vector DenseVector vector = ClusteringUtils.parseVector(vectorString); // if there is no resulting vector for the particular cluster, add this one if (!result.containsKey(clusterNumber)) { result.put(clusterNumber, vector); } else { // otherwise add this one to the previous one result.put(clusterNumber, result.get(clusterNumber).add(vector)); } // and update counts if (!counts.containsKey(clusterNumber)) { counts.put(clusterNumber, 0); } counts.put(clusterNumber, counts.get(clusterNumber) + 1); } // now compute average for each vector for (Map.Entry<Integer, Vector> entry : result.entrySet()) { // cluster number int clusterNumber = entry.getKey(); // get counts int count = counts.get(clusterNumber); // divide by count of vectors for each cluster (averaging) for (VectorEntry vectorEntry : entry.getValue()) { vectorEntry.set(vectorEntry.get() / (double) count); } } return result; }
From source file:ANNFileDetect.EncogTestClass.java
private void drawchart(TreeMap<Double, Integer> ht, String file, int minima) throws IOException { DefaultCategoryDataset ds = new DefaultCategoryDataset(); //XYDataset xy = new XYDataset(); /*//from ww w .j a v a 2 s. c o m * Enumeration<Double> e = ht.keys(); while (e.hasMoreElements()) { * Double tmp = e.nextElement(); //ds.addValue(ht.get(tmp), "Times", * tmp); if (ht.get(tmp) > 100) ds.addValue(ht.get(tmp), "Times", tmp); * } */ for (Map.Entry<Double, Integer> entry : ht.entrySet()) { //ds.addValue(ht.get(tmp), "Times", tmp); if (entry.getValue() > minima) { ds.addValue(entry.getValue(), "Times", entry.getKey()); } } /* * while (e.hasMoreElements()) { Double tmp = e.nextElement(); * //ds.addValue(ht.get(tmp), "Times", tmp); if (ht.get(tmp) > 100) * ds.addValue(ht.get(tmp), "Times", tmp); } */ JFreeChart chart = ChartFactory.createBarChart(file, "quantity", "value", ds, PlotOrientation.VERTICAL, true, true, false); //JFreeChart chart = ChartFactory.createScatterPlot(file, "quantity", "value",ds, PlotOrientation.VERTICAL, true, true, false); String dlt = "/"; String[] tmpfl = file.split(dlt); String crp = tmpfl[tmpfl.length - 1]; String[] actfl = crp.split("\\."); ChartUtilities.saveChartAsJPEG(new File("/tmp/charts/" + actfl[1].toUpperCase() + actfl[0]), chart, 6000, 1200); files++; }
From source file:com.hichinaschool.flashcards.anki.DeckOptions.java
/** * Get the number of (non-dynamic) subdecks for the current deck *//*w w w . ja v a 2s . c o m*/ private int getSubdeckCount() { try { int count = 0; long did = mDeck.getLong("id"); TreeMap<String, Long> children = mCol.getDecks().children(did); for (Map.Entry<String, Long> entry : children.entrySet()) { JSONObject child = mCol.getDecks().get(entry.getValue()); if (child.getInt("dyn") == 1) { continue; } count++; } return count; } catch (JSONException e) { throw new RuntimeException(e); } }