List of usage examples for java.util TreeSet add
public boolean add(E e)
From source file:gdsc.smlm.results.TraceManager.java
/** * @return The traces that have been found using {@link #traceMolecules(double, int)} *///from w ww . ja va 2s .com public Trace[] getTraces() { // No tracing yet performed or no thresholds if (totalTraces == localisations.length) { if (filterActivationFrames) { ArrayList<Trace> traces = new ArrayList<Trace>(); for (int index = 0; index < totalTraces; index++) { PeakResult peakResult = results.getResults().get(localisations[index].id); if (!outsideActivationWindow(peakResult.peak)) traces.add(new Trace(peakResult)); } return traces.toArray(new Trace[traces.size()]); } else { Trace[] traces = new Trace[localisations.length]; for (int index = 0; index < traces.length; index++) traces[index] = new Trace(results.getResults().get(localisations[index].id)); return traces; } } if (tracker != null) tracker.progress(0); // Build the list of traces Trace[] traces = new Trace[getTotalTraces()]; int n = 0; //for (int index = 0; index < localisations.length; index++) // if (localisations[index].trace == 0) // System.out.printf("error @ %d\n", index); // Since the trace numbers are allocated by processing the spots in frames, each frame can have // trace number out-of-order. This occurs if re-allocation has been performed, // e.g. [1,2,2,1,3] => [1,2,5,4,3] when spots in group 1 are reallocated before spots in group 2. TreeSet<Integer> processedTraces = new TreeSet<Integer>(); for (int index = 0; index < localisations.length; index++) { if (tracker != null && index % 256 == 0) tracker.progress(index, localisations.length); final int traceId = localisations[index].trace; if (processedTraces.contains(traceId)) continue; processedTraces.add(traceId); if (filterActivationFrames && outsideActivationWindow(localisations[index].t)) continue; PeakResult peakResult = results.getResults().get(localisations[index].id); Trace nextTrace = new Trace(peakResult); final int tLimit = maxT[traceId]; // Check if the trace has later frames if (tLimit > localisations[index].t) { for (int j = index + 1; j < localisations.length; j++) { if (localisations[j].t > tLimit) { //for (; j < localisations.length; j++) // if (localisations[j].trace == traceId) // System.out.printf("missed %d\n", j); break; } if (localisations[j].trace == traceId) nextTrace.add(results.getResults().get(localisations[j].id)); } } //// DEBUG: Check the trace does not contain two localisations from the same time frame. //// This should be handled by the findAlternativeForerunner code. //int[] time = new int[nextTrace.size()]; //int count = 0; //for (PeakResult p : nextTrace.getPoints()) //{ // for (int i = 0; i < count; i++) // if (time[i] == p.peak) // System.out.println("Trace contains multiple localisations from the same frame"); // time[count++] = p.peak; //} traces[n++] = nextTrace; } if (tracker != null) tracker.progress(1.0); return traces; }
From source file:net.spfbl.core.Analise.java
public static TreeSet<String> getIPv4Set(String hostname) { TreeSet<String> ipv4Set = new TreeSet<String>(); try {//w w w .ja va 2 s .com Attributes attributesA = Server.getAttributesDNS(hostname, new String[] { "A" }); if (attributesA != null) { Enumeration enumerationA = attributesA.getAll(); while (enumerationA.hasMoreElements()) { Attribute attributeA = (Attribute) enumerationA.nextElement(); NamingEnumeration enumeration = attributeA.getAll(); while (enumeration.hasMoreElements()) { String address = (String) enumeration.next(); if (SubnetIPv4.isValidIPv4(address)) { address = SubnetIPv4.normalizeIPv4(address); ipv4Set.add(address); } } } } } catch (NameNotFoundException ex) { return null; } catch (NamingException ex) { // Ignore. } return ipv4Set; }
From source file:biz.wolschon.fileformats.gnucash.jwsdpimpl.GnucashFileWritingImpl.java
/** * * @return a read-only collection of all accounts *//*from ww w . j a v a 2 s . c om*/ @SuppressWarnings("unchecked") public Collection<GnucashWritableAccount> getWritableAccounts() { TreeSet<GnucashWritableAccount> retval = new TreeSet(); for (GnucashAccount account : getAccounts()) { retval.add((GnucashWritableAccount) account); } return retval; }
From source file:net.spfbl.core.Analise.java
public static TreeSet<String> getIPSet(String hostname) { TreeSet<String> ipSet = new TreeSet<String>(); try {/*ww w. j av a 2s . com*/ Attributes attributesA = Server.getAttributesDNS(hostname, new String[] { "A" }); if (attributesA != null) { Enumeration enumerationA = attributesA.getAll(); while (enumerationA.hasMoreElements()) { Attribute attributeA = (Attribute) enumerationA.nextElement(); NamingEnumeration enumeration = attributeA.getAll(); while (enumeration.hasMoreElements()) { String address = (String) enumeration.next(); if (SubnetIPv4.isValidIPv4(address)) { address = SubnetIPv4.normalizeIPv4(address); ipSet.add(address); } } } } Attributes attributesAAAA = Server.getAttributesDNS(hostname, new String[] { "AAAA" }); if (attributesAAAA != null) { Enumeration enumerationAAAA = attributesAAAA.getAll(); while (enumerationAAAA.hasMoreElements()) { Attribute attributeAAAA = (Attribute) enumerationAAAA.nextElement(); NamingEnumeration enumeration = attributeAAAA.getAll(); while (enumeration.hasMoreElements()) { String address = (String) enumeration.next(); if (SubnetIPv6.isValidIPv6(address)) { address = SubnetIPv6.normalizeIPv6(address); ipSet.add(address); } } } } } catch (NameNotFoundException ex) { return null; } catch (NamingException ex) { // Ignore. } return ipSet; }
From source file:com.hichinaschool.flashcards.anki.CardEditor.java
private void actualizeTagDialog(StyledDialog ad) { TreeSet<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); for (String tag : mCol.getTags().all()) { tags.add(tag); }// ww w .j a v a 2 s . com tags.addAll(selectedTags); int len = tags.size(); allTags = new String[len]; boolean[] checked = new boolean[len]; int i = 0; for (String t : tags) { allTags[i++] = t; if (selectedTags.contains(t)) { checked[i - 1] = true; } } ad.setMultiChoiceItems(allTags, checked, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { String tag = allTags[which]; if (selectedTags.contains(tag)) { // Log.i(AnkiDroidApp.TAG, "unchecked tag: " + tag); selectedTags.remove(tag); } else { // Log.i(AnkiDroidApp.TAG, "checked tag: " + tag); selectedTags.add(tag); } } }); }
From source file:net.spfbl.core.Analise.java
public static TreeSet<String> getIPv6Set(String hostname) { TreeSet<String> ipv6Set = new TreeSet<String>(); try {/*from w w w. j av a 2 s . c o m*/ Attributes attributesAAAA = Server.getAttributesDNS(hostname, new String[] { "AAAA" }); if (attributesAAAA != null) { Enumeration enumerationAAAA = attributesAAAA.getAll(); while (enumerationAAAA.hasMoreElements()) { Attribute attributeAAAA = (Attribute) enumerationAAAA.nextElement(); NamingEnumeration enumeration = attributeAAAA.getAll(); while (enumeration.hasMoreElements()) { String address = (String) enumeration.next(); if (SubnetIPv6.isValidIPv6(address)) { address = SubnetIPv6.normalizeIPv6(address); ipv6Set.add(address); } } } } } catch (NameNotFoundException ex) { return null; } catch (NamingException ex) { // Ignore. } return ipv6Set; }
From source file:net.spfbl.core.Peer.java
public TreeSet<Peer> getSendSet() { TreeSet<Peer> peerSet = new TreeSet<Peer>(); for (Peer peer : getSet()) { if (!peer.equals(this)) { switch (peer.getSendStatus()) { case BLOCK: case ALWAYS: case REPASS: peerSet.add(peer); break; }//from w w w .j av a 2s .co m } } return peerSet; }
From source file:com.jaspersoft.jasperserver.test.ReportSchedulingTestTestNG.java
private void testListJobs(long jobId_01, long jobId_02, String userName) { // test Mail Notification ReportJobModel criteria = new ReportJobModel(); ReportJobMailNotificationModel mailNotificationModel = new ReportJobMailNotificationModel(); mailNotificationModel.setSubject("updated subject"); criteria.setMailNotificationModel(mailNotificationModel); ArrayList<Long> expectedJob01 = new ArrayList<Long>(); expectedJob01.add(jobId_01);//from www .jav a 2 s .c om compareResult(criteria, expectedJob01); // test base report job criteria = new ReportJobModel(); criteria.setLabel("foo"); compareResult(criteria, expectedJob01); // test output format criteria = new ReportJobModel(); Set<Byte> outputFormats = new HashSet<Byte>(); outputFormats.add(ReportJob.OUTPUT_FORMAT_PDF); criteria.setOutputFormatsSet(outputFormats); ArrayList<Long> expectedJobBOTH = new ArrayList<Long>(); expectedJobBOTH.add(jobId_01); expectedJobBOTH.add(jobId_02); compareResult(criteria, expectedJobBOTH); // test user name criteria = new ReportJobModel(); criteria.setUsername(userName); compareResult(criteria, expectedJobBOTH); // test trigger criteria = new ReportJobModel(); ReportJobCalendarTriggerModel reportJobCalendarTriggerModel = new ReportJobCalendarTriggerModel(); TreeSet months = new TreeSet(); months.add(new Byte((byte) 1)); months.add(new Byte((byte) 2)); months.add(new Byte((byte) 3)); reportJobCalendarTriggerModel.setMonths(months); criteria.setTriggerModel(reportJobCalendarTriggerModel); ArrayList<Long> expectedJob02 = new ArrayList<Long>(); expectedJob02.add(jobId_02); compareResult(criteria, expectedJob02); // test data source criteria = new ReportJobModel(); ReportJobSourceModel reportJobSourceModel = new ReportJobSourceModel(); reportJobSourceModel.setReportUnitURI("/test/reportURI"); criteria.setSourceModel(reportJobSourceModel); compareResult(criteria, expectedJob01); // test repository destination criteria = new ReportJobModel(); ReportJobRepositoryDestinationModel reportJobRepositoryDestinationModel = new ReportJobRepositoryDestinationModel(); reportJobRepositoryDestinationModel.setSequentialFilenames(false); criteria.setContentRepositoryDestinationModel(reportJobRepositoryDestinationModel); compareResult(criteria, expectedJob02); // test ftp info criteria = new ReportJobModel(); reportJobRepositoryDestinationModel = new ReportJobRepositoryDestinationModel(); FTPInfoModel ftpInfoModel = new FTPInfoModel(); ftpInfoModel.setUserName("JohnSmith"); reportJobRepositoryDestinationModel.setOutputFTPInfoModel(ftpInfoModel); criteria.setContentRepositoryDestinationModel(reportJobRepositoryDestinationModel); compareResult(criteria, expectedJob02); // should return none criteria.setMailNotificationModel(mailNotificationModel); compareResult(criteria, new ArrayList<Long>()); // text email criteria = new ReportJobModel(); mailNotificationModel = new ReportJobMailNotificationModel(); ArrayList<String> toAddress = new ArrayList<String>(); toAddress.add("peter@pan.com"); mailNotificationModel.setToAddresses(toAddress); criteria.setMailNotificationModel(mailNotificationModel); compareResult(criteria, expectedJob02); }
From source file:edu.umd.cs.submitServer.filters.RegisterStudentsFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; if (!request.getMethod().equals("POST")) { throw new ServletException("Only POST accepted"); }//from ww w . jav a2 s. com Connection conn = null; BufferedReader reader = null; FileItem fileItem = null; TreeSet<StudentRegistration> registeredStudents = new TreeSet<StudentRegistration>(); List<String> errors = new ArrayList<String>(); try { conn = getConnection(); // MultipartRequestFilter is required MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST); Course course = (Course) request.getAttribute("course"); // open the uploaded file fileItem = multipartRequest.getFileItem(); reader = new BufferedReader(new InputStreamReader(fileItem.getInputStream())); int lineNumber = 1; while (true) { String line = reader.readLine(); if (line == null) break; lineNumber++; // hard-coded skip of first two lines for Maryland-specific // format if (line.startsWith("Last,First,UID,section,ClassAcct,DirectoryID")) continue; if (line.startsWith(",,,,,")) { if (line.equals(",,,,,")) continue; String ldap = line.substring(5); Student student = Student.lookupByLoginName(ldap, conn); if (student != null) { StudentRegistration sr = StudentForUpload.registerStudent(course, student, "", ldap, null, conn); registeredStudents.add(sr); } else errors.add("Did not find " + ldap); continue; } if (line.startsWith("#")) continue; // skip blank lines if (line.trim().equals("")) continue; try { StudentForUpload s = new StudentForUpload(line, delimiter); Student student = s.lookupOrInsert(conn); StudentRegistration sr = StudentForUpload.registerStudent(course, student, s.section, s.classAccount, null, conn); registeredStudents.add(sr); } catch (IllegalStateException e) { errors.add(e.getMessage()); ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request, "error while registering " + line, null, e); } catch (Exception e1) { errors.add("Problem processing line: '" + line + "' at line number: " + lineNumber); ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request, "error while registering " + line, null, e1); } } } catch (SQLException e) { throw new ServletException(e); } finally { releaseConnection(conn); if (reader != null) reader.close(); if (fileItem != null) fileItem.delete(); } request.setAttribute("registeredStudents", registeredStudents); request.setAttribute("errors", errors); chain.doFilter(request, response); }
From source file:edu.ucla.stat.SOCR.analyses.gui.AnovaTwoWay.java
protected void doGraph() { graphPanel.removeAll();//from w w w . j a v a 2s . c o m // 1. Box plot of data: yData vs. xData (where xData is categorical) JPanel innerPanel = new JPanel(); JScrollPane graphPane = new JScrollPane(innerPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); graphPanel.add(graphPane); innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS)); graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS)); String[][] xNameData = new String[seriesCount][categoryCount]; // xNameData: category names. //////System.out.println("xNameData = "+xNameData.length); for (int i = 0; i < seriesCount; i++) { for (int j = 0; j < categoryCount; j++) { xNameData[i][j] = categoryName[j]; //////System.out.println("xNameData = " + xNameData[i][j]); } } /* the parameters to be passed are: 1.boxPlotTitle, xAxisLabel, YAxisLabel. 2. serieCount, categoryCount 3. seriesname (e.g. sex, race, etc) 4. category's name (e.g. height, weight, etc)--xData 5. yValue(double), */ ChartPanel chartPanel = null; double xDataDouble[] = null; TreeSet<String> treeSet = new TreeSet<String>(); String groupLegend = ""; boolean groupHasChar = false; // 1. scatter plot of data: yData vs. xData try { for (int i = xDataArray.length - 1; i >= 0; i--) { xData = xDataArray[i]; xDataDouble = new double[xData.length]; try { for (int j = 0; j < xData.length; j++) { xDataDouble[j] = (new Double(xData[j])).doubleValue(); } } catch (Exception e) { for (int j = 0; j < xData.length; j++) { treeSet.add((String) xData[j]); } groupHasChar = true; } Iterator iterator = treeSet.iterator(); int groupIndex = 1; String groupName = null; while (iterator.hasNext()) { groupName = (String) iterator.next(); //xDataDouble[groupIndex-1] = groupIndex; groupLegend += ("\t" + groupName + "=" + groupIndex + " "); for (int j = 0; j < xData.length; j++) { if (xData[j].equalsIgnoreCase(groupName)) { // xData[i] is a String. xDataDouble[j] = (double) groupIndex; } } groupIndex++; } independentHeader = independentHeaderArray[i]; //JFreeChart scatterChart = chartFactory.getLineChart("Scatter Plot of " + dependentHeader + " vs. " + independentHeader, independentHeader, dependentHeader, xDataDouble, yData);//getChart(title, xlabel, ylabel, xdata,ydata) JFreeChart scatterChart = chartFactory.getQQChart( "Scatter Plot of " + dependentHeader + " vs. " + independentHeader, independentHeader, dependentHeader, "Residuals ", xDataDouble, yData, " " + groupLegend, 0, 0, ""); ////System.out.println("doGraph dependentHeader = " + dependentHeader); ////System.out.println("doGraph independentHeader = " + independentHeader); chartPanel = new ChartPanel(scatterChart, false); chartPanel.setPreferredSize(new Dimension(plotWidth, plotHeight)); innerPanel.add(chartPanel); if (groupHasChar) { groupLegend = "Group Names for " + independentHeaderArray[i] + ": " + groupLegend; /*JLabel legendLabel1 = new JLabel(groupLegend); legendLabel1.setBackground(Color.WHITE); JPanel labelPanel1 = new JPanel(); labelPanel1.add(legendLabel1, BorderLayout.NORTH); innerPanel.add(labelPanel1); */ } groupLegend = ""; treeSet = new TreeSet<String>(); } } catch (Exception e) { ////System.out.println("doGraph Scatter Exception = " + e); } groupHasChar = false; // 2. residual on fit plot: residuals vs. predicted //JFreeChart rfChart = chartFactory.getLineChart("Residual on Fit Plot", "Predicted", "Residuals", predicted, residuals, "Other Stuff"); JFreeChart rfChart = chartFactory.getQQChart("Residual on Fit Plot", "Predicted " + dependentHeader, "Residuals", "Residuals ", predicted, residuals, "At Residual = 0", 0, 0, ""); for (int i = 0; i < predicted.length; i++) { //System.out.println("predicted["+i+"] = " + predicted[i] + ". residuals["+i+"] = " + residuals[i]); } chartPanel = new ChartPanel(rfChart, false); chartPanel.setPreferredSize(new Dimension(plotWidth, plotHeight)); innerPanel.add(chartPanel); // 3. residual on fit plot: residuals vs. xData xDataDouble = new double[xData.length]; groupLegend = ""; boolean useStringLegent = false; treeSet = new TreeSet<String>(); try { for (int i = xDataArray.length - 1; i >= 0; i--) { xData = xDataArray[i]; xDataDouble = new double[xData.length]; try { for (int j = 0; j < xData.length; j++) { xDataDouble[j] = (new Double(xData[j])).doubleValue(); } } catch (Exception e) { for (int j = 0; j < xData.length; j++) { treeSet.add((String) xData[j]); } groupHasChar = true; } Iterator<String> iterator = treeSet.iterator(); int groupIndex = 1; String groupName = null; while (iterator.hasNext()) { groupName = (String) iterator.next(); //xDataDouble[groupIndex-1] = groupIndex; groupLegend += ("\t" + groupName + "=" + groupIndex + " "); for (int j = 0; j < xData.length; j++) { if (xData[j].equalsIgnoreCase(groupName)) { // xData[i] is a String. xDataDouble[j] = (double) groupIndex; } } groupIndex++; } independentHeader = independentHeaderArray[i]; //JFreeChart scatterChart = chartFactory.getLineChart("Residual on Covariate Plot, Residual vs. " + independentHeaderArray[i], independentHeaderArray[i], dependentHeader, xDataDouble, residuals, "Other Stuff 2");//getChart(title, xlabel, ylabel, xdata,ydata) JFreeChart scatterChart = chartFactory.getQQChart( "Residual on Covariate Plot: Variable = " + independentHeaderArray[i], independentHeaderArray[i], "Residuals", "Residual ", xDataDouble, residuals, " " + groupLegend, 0, 0, "noline"); chartPanel = new ChartPanel(scatterChart, false); chartPanel.setPreferredSize(new Dimension(plotWidth, plotHeight)); innerPanel.add(chartPanel); if (groupHasChar) { groupLegend = "Group Names for " + independentHeaderArray[i] + ": " + groupLegend; /* JLabel legendLabel2 = new JLabel(groupLegend); legendLabel2.setBackground(Color.WHITE); JPanel labelPanel2 = new JPanel(); labelPanel2.add(legendLabel2, BorderLayout.NORTH); innerPanel.add(labelPanel2); */ } groupLegend = ""; treeSet = new TreeSet<String>(); } } catch (Exception e) { ////System.out.println("doGraph Residuals Exception = " + e); } // 4. Normal QQ plot: need residuals and standardized normal scores //JFreeChart qqChart = chartFactory.getLineChart("Residual Normal QQ Plot", "Theoretical Quantiles", "Standardized Residuals", sortedStandardizedNormalQuantiles, sortedStandardizedResiduals); JFreeChart qqChart = chartFactory.getQQChart("Residual Normal QQ Plot", "Theoretical Quantiles", "Standardized Residuals", "Standardized Residual Value ", sortedStandardizedNormalQuantiles, sortedStandardizedResiduals, "At Standardized Residual = 0", 0, 1, "noshape"); //JFreeChart qqChart = chartFactory.getLineChart("Residual Normal QQ Plot", "Theoretical Quantiles", "Standardized Residuals", sortedStandardizedNormalQuantiles, sortedStandardizedResiduals); //JFreeChart qqChart = chartFactory.getLineChart("Residual Normal QQ Plot", "Theoretical Quantiles", "Standardized Residuals", sortedStandardizedNormalQuantiles, sortedStandardizedResiduals, "noline"); chartPanel = new ChartPanel(qqChart, false); chartPanel.setPreferredSize(new Dimension(plotWidth, plotHeight)); innerPanel.add(chartPanel); graphPanel.validate(); }