Example usage for java.util SortedSet add

List of usage examples for java.util SortedSet add

Introduction

In this page you can find the example usage for java.util SortedSet add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:org.stockwatcher.data.cassandra.WatchListDAOImpl.java

@Override
public SortedSet<WatchListItem> getWatchListItems(StatementOptions options, UUID id) {
    if (id == null) {
        throw new IllegalArgumentException("id argument is null");
    }//  w ww . j a  v  a  2  s.  com

    // We assume that the watchlist id is valid
    SortedSet<WatchListItem> items = new TreeSet<WatchListItem>();
    try {
        BoundStatement bs = selectWatchListItems.bind();
        bs.setUUID("watchlist_id", id);
        for (Row row : execute(bs, options)) {
            items.add(WatchListHelper.createWatchListItem(row,
                    stockDAO.getStockBySymbol(options, row.getString("stock_symbol"))));
        }
    } catch (DriverException e) {
        throw new DAOException(e);
    }
    return items;
}

From source file:act.installer.HMDBParser.java

protected SortedSet<File> findHMDBFilesInDirectory(File dir) throws IOException {
    // Sort for consistency + sanity.
    SortedSet<File> results = new TreeSet<>((a, b) -> a.getName().compareTo(b.getName()));
    for (File file : dir.listFiles()) { // Do our own filtering so we can log rejects, of which we expect very few.
        if (HMDB_FILE_REGEX.matcher(file.getName()).matches()) {
            results.add(file);
        } else {//w  w  w  . jav  a 2s . c  o  m
            LOGGER.warn("Found non-conforming HMDB file in directory %s: %s", dir.getAbsolutePath(),
                    file.getName());
        }
    }
    return results;
}

From source file:net.sf.jabref.gui.ContentSelectorDialog2.java

/**
 * Set the contents of the field selector list.
 *
 *///from  ww w .j  av a2 s.  c  o  m
private void setupFieldSelector() {
    fieldListModel.clear();
    SortedSet<String> contents = new TreeSet<>();
    for (String s : metaData) {
        if (s.startsWith(MetaData.SELECTOR_META_PREFIX)) {
            contents.add(s.substring(MetaData.SELECTOR_META_PREFIX.length()));
        }
    }
    if (contents.isEmpty()) {
        // if nothing was added, put the default fields (as described in the help)
        fieldListModel.addElement(FieldName.AUTHOR);
        fieldListModel.addElement(FieldName.JOURNAL);
        fieldListModel.addElement(FieldName.KEYWORDS);
        fieldListModel.addElement(FieldName.PUBLISHER);
    } else {
        for (String s : contents) {
            fieldListModel.addElement(s);
        }
    }

    if (currentField == null) {
        // if dialog is created for the whole database,
        // select the first field to avoid confusions in GUI usage
        fieldList.setSelectedIndex(0);
    } else {
        // a specific field has been chosen at the constructor
        // select this field
        int i = fieldListModel.indexOf(currentField);
        if (i != -1) {
            // field has been found in list, select it
            fieldList.setSelectedIndex(i);
        }
    }
}

From source file:gr.cti.android.experimentation.controller.BaseController.java

protected SortedSet<RankingEntry> getRankingList(final String after, final int experimentId) {

    final SortedSet<RankingEntry> list = new TreeSet<>((o1, o2) -> (int) (o2.getCount() - o1.getCount()));
    final Iterable<Smartphone> phones = smartphoneRepository.findAll();

    if (after.isEmpty()) {
        for (final Smartphone phone : phones) {
            if (experimentId == 0) {
                long count = resultRepository.countByDeviceId(phone.getId());
                if (count > 0) {
                    list.add(new RankingEntry(phone.getId(), count));
                }/*from   w  w  w  .  j a va  2  s .c  o m*/
            } else {
                long count = resultRepository.countByDeviceIdAndExperimentId(phone.getId(), experimentId);
                if (count > 0) {
                    list.add(new RankingEntry(phone.getId(), count));
                }
            }
        }
    } else {
        try {
            final Date afterMillis;
            if (after.contains("T")) {
                afterMillis = dfTime.parse(after);
            } else {
                afterMillis = dfDay.parse(after);
            }
            for (final Smartphone phone : phones) {
                if (experimentId == 0) {
                    long count = resultRepository.countByDeviceIdAndTimestampAfter(phone.getId(),
                            afterMillis.getTime());
                    if (count > 0) {
                        list.add(new RankingEntry(phone.getId(), count));
                    }
                } else {
                    long count = resultRepository.countByDeviceIdAndExperimentIdAndTimestampAfter(phone.getId(),
                            experimentId, afterMillis.getTime());
                    if (count > 0) {
                        list.add(new RankingEntry(phone.getId(), count));
                    }
                }
            }
        } catch (ParseException e) {
            return null;
        }
    }
    return list;
}

From source file:gaffer.accumulostore.utils.ByteArrayEscapeUtilsTest.java

@Test
public void testOrdering() {
    // Generate some keys with row key formed from random bytes, and add to ordered set
    final SortedSet<Key> original = new TreeSet<>();
    for (int i = 0; i < 100000; i++) {
        final int length = RandomUtils.nextInt(100) + 1;
        final byte[] b = new byte[length];
        for (int j = 0; j < b.length; j++) {
            b[j] = (byte) RandomUtils.nextInt();
        }//www.ja v  a2s .  c  o  m
        final Key key = new Key(b, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES,
                AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
        original.add(key);
    }
    // Loop through set, check that ordering is preserved after escaping
    final Iterator<Key> it = original.iterator();
    Key first = it.next();
    Key second = it.next();
    while (true) {
        assertTrue(first.compareTo(second) < 0);
        final Key escapedFirst = new Key(ByteArrayEscapeUtils.escape(first.getRowData().getBackingArray()),
                AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES,
                AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
        final Key escapedSecond = new Key(ByteArrayEscapeUtils.escape(second.getRowData().getBackingArray()),
                AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES,
                AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
        assertTrue(escapedFirst.compareTo(escapedSecond) < 0);
        first = second;
        if (it.hasNext()) {
            second = it.next();
        } else {
            break;
        }
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.student.RegistrationDA.java

public ActionForward viewAttends(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) {// www.ja va  2 s . c  o m
    RenderUtils.invalidateViewState();

    final Registration registration = getAndSetRegistration(request);
    request.setAttribute("registration", registration);

    if (registration != null) {
        final SortedMap<ExecutionSemester, SortedSet<Attends>> attendsMap = new TreeMap<ExecutionSemester, SortedSet<Attends>>();
        for (final Attends attends : registration.getAssociatedAttendsSet()) {
            final ExecutionSemester executionSemester = attends.getExecutionPeriod();
            SortedSet<Attends> attendsSet = attendsMap.get(executionSemester);
            if (attendsSet == null) {
                attendsSet = new TreeSet<Attends>(Attends.ATTENDS_COMPARATOR);
                attendsMap.put(executionSemester, attendsSet);
            }
            attendsSet.add(attends);
        }
        request.setAttribute("attendsMap", attendsMap);
    }

    return mapping.findForward("viewAttends");
}

From source file:com.espertech.esper.filter.TestDoubleRangeComparator.java

public void testComparator() {
    SortedSet<DoubleRange> sorted = new TreeSet<DoubleRange>(new DoubleRangeComparator());

    final double[][] TEST_SET = { { 10, 20 }, // 4
            { 10, 15 }, // 2
            { 10, 25 }, // 5
            { 5, 20 }, // 0
            { 5, 25 }, // 1
            { 15, 20 }, // 6
            { 10, 16 } }; // 3

    final int[] EXPECTED_INDEX = { 3, 4, 1, 6, 0, 2, 5 };

    // Sort// w  w  w  . j a  va2s  .  c o m
    DoubleRange ranges[] = new DoubleRange[TEST_SET.length];
    for (int i = 0; i < TEST_SET.length; i++) {
        ranges[i] = new DoubleRange(TEST_SET[i][0], TEST_SET[i][1]);
        sorted.add(ranges[i]);
    }

    // Check results
    int count = 0;
    for (Iterator<DoubleRange> i = sorted.iterator(); i.hasNext();) {
        DoubleRange range = i.next();
        int indexExpected = EXPECTED_INDEX[count];
        DoubleRange expected = ranges[indexExpected];

        log.debug(".testComparator count=" + count + " range=" + range + " expected=" + expected);

        assertEquals(range, expected);
        count++;
    }
    assertEquals(count, TEST_SET.length);
}

From source file:io.fabric8.maven.plugin.mojo.internal.HelmIndexMojo.java

protected void generateHTML(File outputHtmlFile, Map<String, ChartInfo> charts) throws MojoExecutionException {
    Map<String, SortedSet<ChartInfo>> chartMap = new TreeMap<>();
    for (ChartInfo chartInfo : charts.values()) {
        String key = chartInfo.getName();
        SortedSet<ChartInfo> set = chartMap.get(key);
        if (set == null) {
            set = new TreeSet<>(createChartComparator());
            chartMap.put(key, set);//from w w  w .j av  a2 s  . c om
        }
        set.add(chartInfo);
    }
    try (PrintWriter writer = new PrintWriter(new FileWriter(outputHtmlFile))) {
        writer.println("<html>");
        writer.println("<head>");
        writer.println(getHtmlFileContentOrDefault(headHtmlFile, "<link href='style.css' rel=stylesheet>\n"
                + "<link href='custom.css' rel=stylesheet>\n" + "<title>" + helmTitle + "</title>\n"));
        writer.println("</head>");
        writer.println("<body>");

        writer.println(getHtmlFileContentOrDefault(introductionHtmlFile, "<h1>" + helmTitle + "</h1>"));

        writer.println("<table class='table table-striped table-hover'>");
        writer.println("  <hhead>");
        writer.println("    <tr>");
        writer.println("      <th>Chart</th>");
        writer.println("      <th>Versions</th>");
        writer.println("    </tr>");
        writer.println("  </hhead>");
        writer.println("  <tbody>");
        for (Map.Entry<String, SortedSet<ChartInfo>> entry : chartMap.entrySet()) {
            String key = entry.getKey();
            SortedSet<ChartInfo> set = entry.getValue();
            if (!set.isEmpty()) {
                ChartInfo first = set.first();
                HelmMojo.Chart firstChartfile = first.getChartfile();
                if (firstChartfile == null) {
                    continue;
                }
                String chartDescription = getDescription(firstChartfile);
                writer.println("    <tr>");
                writer.println("      <td title='" + chartDescription + "'>");
                String iconHtml = "";
                String iconUrl = findIconURL(first, set);
                if (Strings.isNotBlank(iconUrl)) {
                    iconHtml = "<img class='logo' src='" + iconUrl + "'>";
                }
                writer.println("        " + iconHtml + "<span class='chart-name'>" + key + "</span>");
                writer.println("      </td>");
                writer.println("      <td class='versions'>");
                for (ChartInfo chartInfo : set) {
                    HelmMojo.Chart chartfile = chartInfo.getChartfile();
                    if (chartfile == null) {
                        continue;
                    }
                    String description = getDescription(chartfile);
                    String version = chartfile.getVersion();
                    String href = chartInfo.firstUrl();
                    writer.println(
                            "        <a href='" + href + "' title='" + description + "'>" + version + "</a>");
                }
                writer.println("      </td>");
                writer.println("    </tr>");
            }
        }
        writer.println("  </tbody>");
        writer.println("  </table>");
        writer.println(getHtmlFileContentOrDefault(footerHtmlFile, ""));
        writer.println("</body>");
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to write to " + outputHtmlFile + ". " + e, e);
    }
}

From source file:org.stockwatcher.data.cassandra.WatchListDAOImpl.java

@Override
public SortedSet<String> getWatchListStockSymbols(StatementOptions options, UUID id) {
    if (id == null) {
        throw new IllegalArgumentException("id argument is null");
    }/*from  w  w  w  .j av a  2 s  .  c o m*/

    // We assume that the watchlist id is valid
    SortedSet<String> stocks = new TreeSet<String>();
    try {
        Statement statement = select().column("stock_symbol").from("WatchListItem")
                .where(eq("watchlist_id", id));
        for (Row row : execute(statement, options)) {
            stocks.add(row.getString("stock_symbol"));
        }
    } catch (DriverException e) {
        throw new DAOException(e);
    }
    return stocks;
}

From source file:gov.nih.nci.cabig.caaers.domain.ResearchStaff.java

/**
 * The earliest start date of this research staff.
 *
 * @return the active date//from w w w  . j a  v  a2  s.  c o  m
 */
@Transient
public Date getActiveDate() {
    SortedSet<Date> dates = new TreeSet<Date>();
    for (SiteResearchStaff srs : this.getSiteResearchStaffs()) {
        Date activeDate = srs.getActiveDate();
        if (activeDate != null)
            dates.add(activeDate);
    }
    if (dates.size() > 0)
        return dates.first();
    else
        return null;
}