List of usage examples for java.util TreeSet toArray
Object[] toArray();
From source file:dhbw.ka.mwi.businesshorizon2.ui.process.period.timeline.TimelinePresenter.java
/** * Methode zum Aufruf aus der View. Ruft die Folgemethode auf. */// ww w.j av a 2s .com public void addFuturePeriod() { // Anzahl der Perioden wird im Projekt angepasst // muss passieren, bevor das Event gefeuert wird projectProxy.getSelectedProject().setPeriodsToForecast_deterministic( projectProxy.getSelectedProject().getPeriodsToForecast_deterministic() + 1); projectProxy.getSelectedProject().setDeterministicPeriods(futurePeriods); addFuturePeriods(1, projectProxy.getSelectedProject().getProjectInputType().getDeterministicInput()); eventBus.fireEvent(new ShowPeriodViewEvent()); // andere Periode anzeigen // TODO try { TreeSet set = projectProxy.getSelectedProject().getDeterministicPeriods().getPeriods(); int laenge = set.toArray().length; Period t; t = (Period) set.toArray()[laenge - 1]; periodClicked(t); } catch (Exception e) { logger.debug("Fehler beim anzeigen der neuesten Periode"); } }
From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java
/** * Test CRUD./* w w w. ja v a 2 s. com*/ */ @Test public void testCRUD() { // Create final TreeSet<String> tags = new TreeSet<>(); tags.add("java"); tags.add("coding"); final String ID = clientAuth.createLink("http://fabien.vauchelles.com/", "Blog de Fabien Vauchelles n", "Du coooodde rahhh::!!!!! #", tags, false); // Create check assertTrue("ID should be assigned", ID != null && !ID.isEmpty()); List<ShaarliLink> links = clientUnauth.searchAll(1); assertEquals("Only 1 links should be created", 1, links.size()); ShaarliLink link = links.get(0); assertEquals("IDs must be the same", ID, link.getID()); assertEquals("URLs must be the same", "http://fabien.vauchelles.com/", link.getUrl()); assertEquals("Titles must be the same", "Blog de Fabien Vauchelles n", link.getTitle()); assertEquals("Descriptions must be the same", "Du coooodde rahhh::!!!!! #", link.getDescription()); assertFalse("Link must not be restricted", link.isRestricted()); assertArrayEquals("Tags must be the same", tags.toArray(), link.getTags().toArray()); // Modify final TreeSet<String> tags2 = new TreeSet<>(); tags2.add("codding"); tags2.add("blogging"); clientAuth.createOrUpdateLink(ID, "http://ma.nouvelle.url.com/", "Nouveau titre", "Nouvelle description", tags2, true); // Modify check links = clientUnauth.searchAll(1); assertEquals("Link must have disappear from public view", 0, links.size()); links = clientAuth.searchAll(1); assertEquals("A modification shouldn't create another link", 1, links.size()); link = links.get(0); assertEquals("IDs must be the same", ID, link.getID()); assertEquals("URIs must be the same", "http://ma.nouvelle.url.com/", link.getUrl()); assertEquals("Titles must be the same", "Nouveau titre", link.getTitle()); assertEquals("Descriptions must be the same", "Nouvelle description", link.getDescription()); assertTrue("Link must be private", link.isRestricted()); assertArrayEquals("Tags must be the same", tags2.toArray(), link.getTags().toArray()); // Delete clientAuth.delete(ID); assertEquals("Link shouldn't exist here", 0, clientAuth.getLinksCount()); }
From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java
/** * Test search all.//from w w w . j ava 2 s .com */ @Test public void testSearchAll() { // Create DateTime t = new DateTime(); for (int i = 0; i < 10; i++) { final TreeSet<String> tags = new TreeSet<>(); tags.add("tagfix"); tags.add("tag" + i); clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/" + i, "Blog de Fabien Vauchelles n" + i, "du java quoi! #" + i, tags, false); t = t.plusSeconds(1); } // Check assertEquals("10 links should have been created", 10, clientAuth.getLinksCount()); clientUnauth.setLinksByPage(3); int num = 9; final Iterator<ShaarliLink> it = clientUnauth.searchAllIterator(); while (it.hasNext()) { final ShaarliLink link = it.next(); assertEquals("URLs must be the same", "http://fabien.vauchelles.com/" + num, link.getUrl()); assertEquals("Titles must be the same", "Blog de Fabien Vauchelles n" + num, link.getTitle()); assertEquals("Descriptions must be the same", "du java quoi! #" + num, link.getDescription()); assertFalse("Link must be public", link.isRestricted()); final TreeSet<String> tags = new TreeSet<>(); tags.add("tagfix"); tags.add("tag" + num); assertArrayEquals("Tags must be the same", tags.toArray(), link.getTags().toArray()); --num; } }
From source file:com.vaushell.shaarlijavaapi.ShaarliClientTest.java
/** * Test search all reverse.// w ww .jav a 2s .c om */ @Test public void testSearchAllReverse() { // Create DateTime t = new DateTime(); for (int i = 0; i < 10; i++) { final TreeSet<String> tags = new TreeSet<>(); tags.add("tagfix"); tags.add("tag" + i); clientAuth.createOrUpdateLink(t, "http://fabien.vauchelles.com/" + i, "Blog de Fabien Vauchelles n" + i, "du java quoi! #" + i, tags, false); t = t.plusSeconds(1); } // Check assertEquals("10 links should have been created", 10, clientAuth.getLinksCount()); clientUnauth.setLinksByPage(3); int num = 0; final Iterator<ShaarliLink> it = clientUnauth.searchAllReverseIterator(); while (it.hasNext()) { final ShaarliLink link = it.next(); assertEquals("URLs must be the same", "http://fabien.vauchelles.com/" + num, link.getUrl()); assertEquals("Titles must be the same", "Blog de Fabien Vauchelles n" + num, link.getTitle()); assertEquals("Descriptions must be the same", "du java quoi! #" + num, link.getDescription()); assertFalse("Link must be public", link.isRestricted()); final TreeSet<String> tags = new TreeSet<>(); tags.add("tagfix"); tags.add("tag" + num); assertArrayEquals("Tags must be the same", tags.toArray(), link.getTags().toArray()); ++num; } }
From source file:com.collabnet.ccf.pi.qc.v90.QCHandler.java
/** * Orders the values of the incoming HashMap according to its keys. * /*from w ww . j a va 2 s. co m*/ * @param HashMap * This hashMap contains the transactionIds as values indexed by * their defectIds. * @return List<String> This list of strings is the ordering of the keys of * the incoming HashMaps, which are the defectIds, according to the * order of their transactionIds * */ public List<String> orderByLatestTransactionIds(Map<String, String> defectIdTransactionIdMap) { List<String> mapKeys = new ArrayList<String>(defectIdTransactionIdMap.keySet()); List<String> mapValues = new ArrayList<String>(defectIdTransactionIdMap.values()); defectIdTransactionIdMap.clear(); TreeSet<String> sortedSet = new TreeSet<String>(mapValues); Object[] sortedArray = sortedSet.toArray(); int size = sortedArray.length; for (int i = 0; i < size; i++) { defectIdTransactionIdMap.put(mapKeys.get(mapValues.indexOf(sortedArray[i])), (String) sortedArray[i]); } List<String> orderedDefectList = new ArrayList<String>(defectIdTransactionIdMap.keySet()); return orderedDefectList; }
From source file:dhbw.ka.mwi.businesshorizon2.ui.process.period.timeline.TimelinePresenter.java
/** * Zuknftige stochastische Perioden anlegen<br> * dabei wird bercksichtigt, dass bereits Perioden vorhanden sind.<br> * Diese werden zuerst ausgegeben und, sofern mehr ausgegeben werden sollen,<br> * neue Perioden hinzugefgt.<br>//from w w w .j a v a 2s. com * brige Perioden werden ggf gelscht * * @author Annika Weis */ private void addPastPeriods_vorhanden() { /* * Wenn bereits Perioden vorhanden sind: so viele anlegen, sonst so * viele, wie es der Benutzer vorgibt auf der Parameter-Maske */ logger.debug("past periods: " + projectProxy.getSelectedProject().getSpecifiedPastPeriods()); int i = 0; // bei Zeitreihenanalyse: ein Jahr mehr int weitere_perioden_past = 0; if (methode == "Zeitreihenanalyse") { weitere_perioden_past = -1; // Annika Weis 2014-05-03 } sumPastPeriods = 0; Period basisperiode = null; try { /* * Perioden mssen in umgekehrter Reihenfolge angegeben werden, * sonst ensteht etwas wie: 2012-2011-2010-2009-2008-2013 */ int laenge; TreeSet<Period> perioden = (TreeSet<Period>) projectProxy.getSelectedProject().getStochasticPeriods() .getPeriods(); // Lnge der vorhandenen Perioden laenge = perioden.size(); // nur so viele Perioden ausgeben, wie der Benutzer angegeben hat // bzw vorhanden sind laenge = Math.min(laenge, projectProxy.getSelectedProject().getSpecifiedPastPeriods() + weitere_perioden_past);// // wenn mehr Perioden vorhanden sind als gewnscht... if (perioden.size() > projectProxy.getSelectedProject().getSpecifiedPastPeriods() + weitere_perioden_past) { // ...dann nur die letzten gewnschten ausgeben laenge = perioden.size() - (projectProxy.getSelectedProject().getSpecifiedPastPeriods() + weitere_perioden_past) + 1; } else { // ...sonst alle ausgeben laenge = 0; } logger.debug("Lnge: " + laenge); /** * Perioden ausgeben: Anfangen bei der letzten (hchstes Jahr!) bis * zur gewnschten Lnge Ausgabe erfolgt rckwrts -2 wegen * Array-Index 0 UND Basisperiode abziehen */ for (int x = perioden.size() - 1; x >= 0; x--) { Period period = (Period) perioden.toArray()[x]; logger.debug(x + " - " + period.getYear()); if (x == perioden.size() - 1) { logger.debug("Basisperiode: " + period.getYear()); getView().addBasePeriod(period); basisperiode = period; pastPeriods.addPeriod(period); } else if (x < laenge - 2) { logger.debug("Lsche Jahr " + period.getYear()); pastPeriods.removePeriod(period); } else { logger.debug("Anlegen " + period.getYear()); getView().addPastPeriod(period); sumPastPeriods++; pastPeriods.addPeriod(period); } } projectProxy.getSelectedProject().setStochasticPeriods(pastPeriods); periodClicked(basisperiode); } catch (Exception e) { logger.debug("Fehler: " + e.getMessage()); e.printStackTrace(); } // wenn nicht genug Perioden angelegt wurden wie vom Benutzer angegeben logger.debug(sumPastPeriods + " | " + projectProxy.getSelectedProject().getSpecifiedPastPeriods()); if (sumPastPeriods == 0) { create_base(); } if (sumPastPeriods < projectProxy.getSelectedProject().getSpecifiedPastPeriods() + weitere_perioden_past) { logger.debug("Manuell Perioden anlegen"); addPastPeriods(projectProxy.getSelectedProject().getSpecifiedPastPeriods() + weitere_perioden_past - sumPastPeriods, stochasticInput); } logger.debug("Periodenanzahl: " + sumPastPeriods); return; }
From source file:com.peterbochs.instrument.InstrumentPanel.java
public void update2DChart() { // jfcMemory.getCategoryPlot().setDataset(createMemoryDataset()); jfcMemory.getXYPlot().setDataset(createDataset()); MyXYBlockRenderer renderer = (MyXYBlockRenderer) jfcMemory.getXYPlot().getRenderer(); int largest = findLargest( Data.getChartData(CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem()))); if (largest == 0) { largest = 1;// w ww . ja v a2s. c o m } LookupPaintScale paintScale = new LookupPaintScale(0, largest, background); if (largest > 1) { // int mean = // medianWithoutZero(Data.getChartData(CommonLib.convertFilesize((String) // jFromComboBox.getSelectedItem()), // CommonLib.convertFilesize((String) jToComboBox // .getSelectedItem()))); int m[] = Data.getChartData(CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem())); TreeSet<Integer> data = new TreeSet<Integer>(); for (int x = 0; x < m.length; x++) { if (m[x] > 0) { data.add(m[x]); } } // paintScale.add(0, Color.white); ArrayList<Color> allColors = allColors(); Object iData[] = data.toArray(); paintScale.add(1, allColors.get(0)); for (int x = 1; x < iData.length - 1; x++) { paintScale.add((int) (Integer) iData[x], allColors.get(allColors.size() / iData.length * x)); } paintScale.add((int) (Integer) iData[iData.length - 1], allColors.get(allColors.size() - 1)); } renderer.setPaintScale(paintScale); renderer.setBaseToolTipGenerator(new MyXYToolTipGenerator()); jfcMemory.getXYPlot().setForegroundAlpha(1f); jZoomOutAutoRangeButtonActionPerformed(null); }