List of usage examples for java.util TreeMap clear
public void clear()
From source file:Main.java
public static void main(String[] args) { TreeMap<String, String> treeMap = new TreeMap<String, String>(); treeMap.put("1", "One"); treeMap.put("2", "Two"); treeMap.put("3", "Three"); treeMap.clear(); System.out.println(treeMap.size()); }
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); // populating tree map treemap.put(2, "two"); treemap.put(1, "one"); treemap.put(3, "three"); treemap.put(6, "six"); treemap.put(5, "from java2s.com"); System.out.println("Entries in the Map: " + treemap); // clearing the map System.out.println("Clearing the Map"); treemap.clear(); System.out.println("Entries in the Map: " + treemap); }
From source file:cit360.sandbox.BackEndMenu.java
public static void ticketPrices() { TreeMap ageGroup = new TreeMap(); // Add some ageGroup. ageGroup.put("Adult", 8.75); ageGroup.put("Child", 5.50); ageGroup.put("Senior Citizen", 5.25); ageGroup.put("Military Veteran", 5.00); // Iterate over all ageGroup, using the keySet method. for (Object key : ageGroup.keySet()) System.out.println(key + " - $" + ageGroup.get(key)); System.out.println();/* ww w . j av a 2 s .c om*/ System.out.println("Highest key: " + ageGroup.lastKey()); System.out.println("Lowest key: " + ageGroup.firstKey()); System.out.println("\nPrinting all values: "); for (Object val : ageGroup.values()) System.out.println("$" + val); System.out.println(); // Clear all values. ageGroup.clear(); // Equals to zero. System.out.println("After clear operation, size: " + ageGroup.size()); }
From source file:com.example.HDHTAppTest.java
@Test public void test() throws Exception { File file = new File("target/hds2"); FileUtils.deleteDirectory(file);/*w ww .ja v a 2s . c o m*/ LocalMode lma = LocalMode.newInstance(); Configuration conf = new Configuration(false); conf.set("dt.operator.Store.fileStore.basePath", file.toURI().toString()); //conf.set("dt.operator.Store.flushSize", "0"); conf.set("dt.operator.Store.flushIntervalCount", "1"); conf.set("dt.operator.Store.partitionCount", "2"); lma.prepareDAG(new HDHTAppTest(), conf); LocalMode.Controller lc = lma.getController(); //lc.setHeartbeatMonitoringEnabled(false); lc.runAsync(); long tms = System.currentTimeMillis(); File f0 = new File(file, "0/0-0"); File f1 = new File(file, "1/1-0"); File wal0 = new File(file, "0/_WAL-0"); File wal1 = new File(file, "1/_WAL-0"); while (System.currentTimeMillis() - tms < 30000) { if (f0.exists() && f1.exists()) break; Thread.sleep(100); } lc.shutdown(); Assert.assertTrue("exists " + f0, f0.exists() && f0.isFile()); Assert.assertTrue("exists " + f1, f1.exists() && f1.isFile()); Assert.assertTrue("exists " + wal0, wal0.exists() && wal0.exists()); Assert.assertTrue("exists " + wal1, wal1.exists() && wal1.exists()); HDHTFileAccessFSImpl fs = new TFileImpl.DTFileImpl(); fs.setBasePath(file.toURI().toString()); fs.init(); TreeMap<Slice, byte[]> data = new TreeMap<Slice, byte[]>(new HDHTReader.DefaultKeyComparator()); fs.getReader(0, "0-0").readFully(data); Assert.assertArrayEquals("read key=" + new String(KEY0), DATA0.getBytes(), data.get(new Slice(KEY0))); data.clear(); fs.getReader(1, "1-0").readFully(data); Assert.assertArrayEquals("read key=" + new String(KEY1), DATA1.getBytes(), data.get(new Slice(KEY1))); fs.close(); }
From source file:cc.slda.DisplayTopic.java
@SuppressWarnings("unchecked") public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(Settings.HELP_OPTION, false, "print the help message"); options.addOption(OptionBuilder.withArgName(Settings.PATH_INDICATOR).hasArg() .withDescription("input beta file").create(Settings.INPUT_OPTION)); options.addOption(OptionBuilder.withArgName(Settings.PATH_INDICATOR).hasArg() .withDescription("term index file").create(ParseCorpus.INDEX)); options.addOption(OptionBuilder.withArgName(Settings.INTEGER_INDICATOR).hasArg() .withDescription("display top terms only (default - 10)").create(TOP_DISPLAY_OPTION)); String betaString = null;//from w w w . j a v a 2s. c o m String indexString = null; int topDisplay = TOP_DISPLAY; CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); try { CommandLine line = parser.parse(options, args); if (line.hasOption(Settings.HELP_OPTION)) { formatter.printHelp(ParseCorpus.class.getName(), options); System.exit(0); } if (line.hasOption(Settings.INPUT_OPTION)) { betaString = line.getOptionValue(Settings.INPUT_OPTION); } else { throw new ParseException("Parsing failed due to " + Settings.INPUT_OPTION + " not initialized..."); } if (line.hasOption(ParseCorpus.INDEX)) { indexString = line.getOptionValue(ParseCorpus.INDEX); } else { throw new ParseException("Parsing failed due to " + ParseCorpus.INDEX + " not initialized..."); } if (line.hasOption(TOP_DISPLAY_OPTION)) { topDisplay = Integer.parseInt(line.getOptionValue(TOP_DISPLAY_OPTION)); } } catch (ParseException pe) { System.err.println(pe.getMessage()); formatter.printHelp(ParseCorpus.class.getName(), options); System.exit(0); } catch (NumberFormatException nfe) { System.err.println(nfe.getMessage()); System.exit(0); } JobConf conf = new JobConf(DisplayTopic.class); FileSystem fs = FileSystem.get(conf); Path indexPath = new Path(indexString); Preconditions.checkArgument(fs.exists(indexPath) && fs.isFile(indexPath), "Invalid index path..."); Path betaPath = new Path(betaString); Preconditions.checkArgument(fs.exists(betaPath) && fs.isFile(betaPath), "Invalid beta path..."); SequenceFile.Reader sequenceFileReader = null; try { IntWritable intWritable = new IntWritable(); Text text = new Text(); Map<Integer, String> termIndex = new HashMap<Integer, String>(); sequenceFileReader = new SequenceFile.Reader(fs, indexPath, conf); while (sequenceFileReader.next(intWritable, text)) { termIndex.put(intWritable.get(), text.toString()); } PairOfIntFloat pairOfIntFloat = new PairOfIntFloat(); // HMapIFW hmap = new HMapIFW(); HMapIDW hmap = new HMapIDW(); TreeMap<Double, Integer> treeMap = new TreeMap<Double, Integer>(); sequenceFileReader = new SequenceFile.Reader(fs, betaPath, conf); while (sequenceFileReader.next(pairOfIntFloat, hmap)) { treeMap.clear(); System.out.println("=============================="); System.out.println( "Top ranked " + topDisplay + " terms for Topic " + pairOfIntFloat.getLeftElement()); System.out.println("=============================="); Iterator<Integer> itr1 = hmap.keySet().iterator(); int temp1 = 0; while (itr1.hasNext()) { temp1 = itr1.next(); treeMap.put(-hmap.get(temp1), temp1); if (treeMap.size() > topDisplay) { treeMap.remove(treeMap.lastKey()); } } Iterator<Double> itr2 = treeMap.keySet().iterator(); double temp2 = 0; while (itr2.hasNext()) { temp2 = itr2.next(); if (termIndex.containsKey(treeMap.get(temp2))) { System.out.println(termIndex.get(treeMap.get(temp2)) + "\t\t" + -temp2); } else { System.out.println("How embarrassing! Term index not found..."); } } } } finally { IOUtils.closeStream(sequenceFileReader); } return 0; }
From source file:com.datatorrent.contrib.hdht.HDHTAppTest.java
@Test public void test() throws Exception { File file = new File("target/hds2"); FileUtils.deleteDirectory(file);/*from ww w. j a va2s . co m*/ LocalMode lma = LocalMode.newInstance(); Configuration conf = new Configuration(false); conf.set("dt.operator.Store.fileStore.basePath", file.toURI().toString()); //conf.set("dt.operator.Store.flushSize", "0"); conf.set("dt.operator.Store.flushIntervalCount", "1"); conf.set("dt.operator.Store.partitionCount", "2"); conf.set("dt.operator.Store.numberOfBuckets", "2"); lma.prepareDAG(new HDHTAppTest(), conf); LocalMode.Controller lc = lma.getController(); //lc.setHeartbeatMonitoringEnabled(false); lc.runAsync(); long tms = System.currentTimeMillis(); File f0 = new File(file, "0/0-0"); File f1 = new File(file, "1/1-0"); File wal0 = new File(file, "/WAL/2/_WAL-0"); File wal1 = new File(file, "/WAL/3/_WAL-0"); while (System.currentTimeMillis() - tms < 30000) { if (f0.exists() && f1.exists()) { break; } Thread.sleep(100); } lc.shutdown(); Assert.assertTrue("exists " + f0, f0.exists() && f0.isFile()); Assert.assertTrue("exists " + f1, f1.exists() && f1.isFile()); Assert.assertTrue("exists " + wal0, wal0.exists() && wal0.exists()); Assert.assertTrue("exists " + wal1, wal1.exists() && wal1.exists()); FileAccessFSImpl fs = new MockFileAccess(); fs.setBasePath(file.toURI().toString()); fs.init(); TreeMap<Slice, Slice> data = new TreeMap<Slice, Slice>(new HDHTWriterTest.SequenceComparator()); fs.getReader(0, "0-0").readFully(data); Assert.assertArrayEquals("read key=" + new String(KEY0), DATA0.getBytes(), data.get(new Slice(KEY0)).toByteArray()); data.clear(); fs.getReader(1, "1-0").readFully(data); Assert.assertArrayEquals("read key=" + new String(KEY1), DATA1.getBytes(), data.get(new Slice(KEY1)).toByteArray()); fs.close(); }
From source file:com.datatorrent.contrib.hdht.HDHTBenchmarkTest.java
public void test() throws Exception { File file = new File(testInfo.getDir()); FileUtils.deleteDirectory(file);// www .jav a 2s. c o m LocalMode lma = LocalMode.newInstance(); Configuration conf = new Configuration(false); conf.set("dt.operator.Store.fileStore.basePath", file.toURI().toString()); //conf.set("dt.operator.Store.flushSize", "0"); conf.set("dt.operator.Store.flushIntervalCount", "1"); conf.set("dt.operator.Generator.attr.PARTITIONER", "com.datatorrent.lib.partitioner.StatelessPartitioner:2"); lma.prepareDAG(new HDHTAppTest(), conf); LocalMode.Controller lc = lma.getController(); lc.setHeartbeatMonitoringEnabled(false); lc.runAsync(); long tms = System.currentTimeMillis(); File f0 = new File(file, "0/0-0"); File f1 = new File(file, "1/1-0"); File wal0 = new File(file, "0/_WAL-0"); File wal1 = new File(file, "1/_WAL-0"); while (System.currentTimeMillis() - tms < 30000) { if (f0.exists() && f1.exists()) { break; } Thread.sleep(100); } lc.shutdown(); Assert.assertTrue("exists " + f0, f0.exists() && f0.isFile()); Assert.assertTrue("exists " + f1, f1.exists() && f1.isFile()); Assert.assertTrue("exists " + wal0, wal0.exists() && wal0.exists()); Assert.assertTrue("exists " + wal1, wal1.exists() && wal1.exists()); FileAccessFSImpl fs = new MockFileAccess(); fs.setBasePath(file.toURI().toString()); fs.init(); TreeMap<Slice, Slice> data = new TreeMap<>(new HDHTWriterTest.SequenceComparator()); fs.getReader(0, "0-0").readFully(data); Assert.assertFalse(data.isEmpty()); data.clear(); fs.getReader(1, "1-0").readFully(data); Assert.assertFalse(data.isEmpty()); fs.close(); }
From source file:practica4.Bet365.java
@Override public Partido[] parser(String url) throws FileNotFoundException, MalformedURLException, IOException { ArrayList<Partido> resultado = new ArrayList<>(); HashMap<String, Partido> partidos = new HashMap<>(); TreeMap<String, String> claves = new TreeMap<>(); File file = new File("cache365"); if (!file.exists()) { FileUtils.copyURLToFile(new URL(url), file); }//from w w w .ja v a 2 s . co m String contents = FileUtils.readFileToString(file); //String[] pageParts = contents.split("\\<h3\\>"); String[] pageParts = contents.split("\\|"); for (String line : pageParts) { String lineParts[] = line.split(";"); claves.clear(); for (String part : lineParts) { if (part.length() < 3) continue; String key = part.substring(0, 2); String value = part.substring(3); claves.put(key, value); } if (claves.containsKey("FI")) { // tenemos un partido String idPartido = claves.get("FI"); if (claves.containsKey("NA")) { // informacion general (nombre, fecha) Partido partido = new Partido(); String nombresStr = claves.get("NA"); //byte[] bytes = nombresStr.getBytes("LATIN1"); //nombresStr = new String(bytes, "UTF-8"); String nombres[] = nombresStr.split(" v "); String fecha = claves.get("BC"); partido.equipo1 = nombres[0].trim(); partido.equipo2 = nombres[1].trim(); partido.fecha = Calendar.getInstance(); partido.casa = "Bet365"; int year = Integer.parseInt(fecha.substring(0, 4)); int month = Integer.parseInt(fecha.substring(4, 6)) - 1; int day = Integer.parseInt(fecha.substring(6, 8)); int hour = Integer.parseInt(fecha.substring(8, 10)); int minutes = Integer.parseInt(fecha.substring(10, 12)); partido.fecha.set(year, month, day, hour, minutes); partido.costeVictoria1 = -1; partido.costeVictoria2 = -1; partido.costeEmpate = -1; partidos.put(idPartido, partido); } else { String fraccion[] = claves.get("OD").split("/"); Partido partido = partidos.get(idPartido); double valor = 1.0 + Double.parseDouble(fraccion[0]) / Double.parseDouble(fraccion[1]); valor = Math.round(valor * 100.0) / 100.0; if (partido.costeVictoria1 == -1) { partido.costeVictoria1 = valor; } else if (partido.costeEmpate == -1) { partido.costeEmpate = valor; } else if (partido.costeVictoria2 == -1) { partido.costeVictoria2 = valor; resultado.add(partido); System.out.printf("%s %f %f %f %s\n", partido.equipo1, partido.costeVictoria1, partido.costeEmpate, partido.costeVictoria2, partido.equipo2); } } } } return resultado.toArray(new Partido[partidos.size()]); }
From source file:com.chinamobile.bcbsp.comm.CombinerTool.java
/** combine the message queues. * @param outgoingQueue/*from w w w .ja v a 2 s . c om*/ */ private ConcurrentLinkedQueue<IMessage> combine(ConcurrentLinkedQueue<IMessage> outgoingQueue) { // Map of outgoing queues indexed by destination vertex ID. TreeMap<String, ConcurrentLinkedQueue<IMessage>> outgoingQueues = new TreeMap<String, ConcurrentLinkedQueue<IMessage>>(); ConcurrentLinkedQueue<IMessage> tempQueue = null; IMessage tempMessage = null; // Traverse the outgoing queue and put the messages with the same // dstVertexID into the same queue in the tree map. Iterator<IMessage> iter = outgoingQueue.iterator(); String dstVertexID = null; /**The result queue for return.*/ ConcurrentLinkedQueue<IMessage> resultQueue = new ConcurrentLinkedQueue<IMessage>(); while (iter.hasNext()) { tempMessage = iter.next(); dstVertexID = tempMessage.getDstVertexID(); tempQueue = outgoingQueues.get(dstVertexID); if (tempQueue == null) { tempQueue = new ConcurrentLinkedQueue<IMessage>(); } tempQueue.add(tempMessage); outgoingQueues.put(dstVertexID, tempQueue); } // Do combine operation for each of the outgoing queues. for (Entry<String, ConcurrentLinkedQueue<IMessage>> entry : outgoingQueues.entrySet()) { tempQueue = entry.getValue(); tempMessage = (IMessage) this.combiner.combine(tempQueue.iterator()); resultQueue.add(tempMessage); } outgoingQueue.clear(); outgoingQueues.clear(); return resultQueue; }
From source file:edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniquesReducer.java
private double[] computeCorrelationTechniques(ArrayList<TreeMap<Integer, Float>>[] timeSeries, int index1, int index2, boolean temporalPermutation) { double[] values = { 0.0, 0.0, 0.0 }; TreeMap<Integer, Float> map1 = timeSeries[index1].get(dataset1Key); TreeMap<Integer, Float> map2 = timeSeries[index2].get(dataset2Key); ArrayList<Double> array1 = new ArrayList<Double>(); ArrayList<Double> array2 = new ArrayList<Double>(); for (int temp : map1.keySet()) { if (map2.containsKey(temp)) { array1.add((double) map1.get(temp)); array2.add((double) map2.get(temp)); }//ww w. j a v a 2 s . c o m } double[] completeTempArray1 = new double[map1.keySet().size()]; int index = 0; for (int temp : map1.keySet()) { completeTempArray1[index] = map1.get(temp); index++; } double[] completeTempArray2 = new double[map2.keySet().size()]; index = 0; for (int temp : map2.keySet()) { completeTempArray2[index] = map2.get(temp); index++; } map1.clear(); map2.clear(); if (array1.size() < 2) return null; // Pearson's Correlation double[] tempDoubleArray1 = new double[array1.size()]; double[] tempDoubleArray2 = new double[array2.size()]; int indexD1 = (temporalPermutation) ? new Random().nextInt(array1.size()) : 0; int indexD2 = (temporalPermutation) ? new Random().nextInt(array2.size()) : 0; for (int i = 0; i < array1.size(); i++) { int j = (indexD1 + i) % array1.size(); int k = (indexD2 + i) % array2.size(); tempDoubleArray1[i] = array1.get(j); tempDoubleArray2[i] = array2.get(k); } array1 = null; array2 = null; PearsonsCorrelation pearsonsCorr = new PearsonsCorrelation(); values[0] = pearsonsCorr.correlation(tempDoubleArray1, tempDoubleArray2); // Mutual Information try { values[1] = getMIScore(tempDoubleArray1, tempDoubleArray2); } catch (Exception e) { e.printStackTrace(); /*String data1 = ""; for (double d : tempDoubleArray1) data1 += d + ", "; String data2 = ""; for (double d : tempDoubleArray2) data2 += d + ", "; System.out.println(data1); System.out.println(data2);*/ System.exit(-1); } tempDoubleArray1 = null; tempDoubleArray2 = null; // DTW double[] completeTempDoubleArray1 = new double[completeTempArray1.length]; double[] completeTempDoubleArray2 = new double[completeTempArray2.length]; if (temporalPermutation) { indexD1 = new Random().nextInt(completeTempArray1.length); for (int i = 0; i < completeTempArray1.length; i++) { int j = (indexD1 + i) % completeTempArray1.length; completeTempDoubleArray1[i] = completeTempArray1[j]; } indexD2 = new Random().nextInt(completeTempArray2.length); for (int i = 0; i < completeTempArray2.length; i++) { int j = (indexD2 + i) % completeTempArray2.length; completeTempDoubleArray2[i] = completeTempArray2[j]; } } else { System.arraycopy(completeTempArray1, 0, completeTempDoubleArray1, 0, completeTempArray1.length); System.arraycopy(completeTempArray2, 0, completeTempDoubleArray2, 0, completeTempArray2.length); } completeTempArray1 = null; completeTempArray2 = null; completeTempDoubleArray1 = normalize(completeTempDoubleArray1); completeTempDoubleArray2 = normalize(completeTempDoubleArray2); values[2] = getDTWScore(completeTempDoubleArray1, completeTempDoubleArray2); return values; }