Example usage for java.util SortedSet size

List of usage examples for java.util SortedSet size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this set (its cardinality).

Usage

From source file:gov.nih.nci.cananolab.util.StringUtils.java

public static String sortJoin(Collection<String> strings, String delimiter) {
    SortedSet<SortableName> sortableNames = new TreeSet<SortableName>();
    for (String str : strings) {
        sortableNames.add(new SortableName(str));
    }/*  w ww  .  j av  a 2  s  . c  o m*/
    String joinedStr = "";
    if (sortableNames == null || sortableNames.isEmpty()) {
        return joinedStr;
    }
    StringBuilder sb = new StringBuilder();
    int i = 0;
    for (SortableName sortableName : sortableNames) {
        if (i < sortableNames.size() - 1) {
            if (!StringUtils.isEmpty(sortableName.getName()))
                // joinedStr += sortableName.getName() + delimiter;
                sb.append(sortableName.getName());
            sb.append(delimiter);
        } else {
            if (!StringUtils.isEmpty(sortableName.getName()))
                // joinedStr += sortableName.getName();
                sb.append(sortableName.getName());
        }
        i++;
    }
    joinedStr = sb.toString();
    return joinedStr;
}

From source file:org.apache.hadoop.hdfs.qjournal.client.TestQJMWithFaults.java

/**
 * Run through the creation of a log without any faults injected,
 * and count how many RPCs are made to each node. This sets the
 * bounds for the other test cases, so they can exhaustively explore
 * the space of potential failures.//from w  w w .  ja  va 2s  . c  o  m
 */
private static long determineMaxIpcNumber() throws Exception {
    Configuration conf = new Configuration();
    MiniJournalCluster cluster = new MiniJournalCluster.Builder(conf).build();
    QuorumJournalManager qjm = null;
    long ret;
    try {
        qjm = createInjectableQJM(cluster);
        qjm.format(FAKE_NSINFO);
        doWorkload(cluster, qjm);

        SortedSet<Integer> ipcCounts = Sets.newTreeSet();
        for (AsyncLogger l : qjm.getLoggerSetForTests().getLoggersForTests()) {
            InvocationCountingChannel ch = (InvocationCountingChannel) l;
            ch.waitForAllPendingCalls();
            ipcCounts.add(ch.getRpcCount());
        }

        // All of the loggers should have sent the same number of RPCs, since there
        // were no failures.
        assertEquals(1, ipcCounts.size());

        ret = ipcCounts.first();
        LOG.info("Max IPC count = " + ret);
    } finally {
        IOUtils.closeStream(qjm);
        cluster.shutdown();
    }
    return ret;
}

From source file:mas.MAS.java

public static void batchAuthors(SortedSet<Integer> author_ids, String csvFile, String jsonFile) {
    int start = 0;
    int limit = 200;
    String str = "";
    for (Integer id : author_ids) {
        if (start == author_ids.size()) {
            break;
        }/* w w  w. java2  s . com*/
        System.out.println("process author: " + id);
        str += "ID%20eq%20" + id + "%20or%20";
        if (start % limit == 0) {
            str = "(" + str.substring(0, str.length() - 8) + ")";
            getAuthors(0, str, csvFile, jsonFile);
            System.out.println("URL: " + str);
            str = "";
        }
        start++;
    }
}

From source file:com.vrem.wifianalyzer.wifi.band.WiFiChannelCountryGHZ2Test.java

private void validateChannels(SortedSet<Integer> expected, SortedSet<Integer> actual) {
    assertEquals(expected.size(), actual.size());
    assertTrue(actual.containsAll(expected));
}

From source file:com.spotify.heroic.filter.OrFilter.java

static Filter optimize(final SortedSet<Filter> filters) {
    final SortedSet<Filter> result = new TreeSet<>();

    for (final Filter f : filters) {
        if (f instanceof NotFilter) {
            // Optimize away expressions which are always true.
            // Example: foo = bar or !(foo = bar)

            if (filters.contains(((NotFilter) f).getFilter())) {
                return TrueFilter.get();
            }//ww w  .  ja v  a 2s.com
        } else if (f instanceof StartsWithFilter) {
            // Optimize away prefixes which encompass each other.
            // Example: foo ^ hello or foo ^ helloworld -> foo ^ hello

            if (FilterUtils.containsPrefixedWith(filters, (StartsWithFilter) f,
                    (inner, outer) -> FilterUtils.prefixedWith(outer.getValue(), inner.getValue()))) {
                continue;
            }
        }

        result.add(f);
    }

    if (result.isEmpty()) {
        return TrueFilter.get();
    }

    if (result.size() == 1) {
        return result.iterator().next();
    }

    return new OrFilter(ImmutableList.copyOf(result));
}

From source file:com.jdom.word.playdough.model.GamePackListModelTest.java

@Test
public void testListGamePacksDelegatesToResolver() {
    SortedSet<String> gamePacks = model.getAvailableGamePackFiles();
    assertEquals(2, gamePacks.size());
    assertTrue("Did not find the default game pack!", gamePacks.contains(UNLOCKED_GAME_PACK_NAME));
    assertTrue("Did not find the unlockable game pack!", gamePacks.contains(UNLOCKABLE_GAME_PACK_NAME));
}

From source file:com.comcast.viper.flume2storm.event.F2SEventFactory.java

/**
 * @param nbEvents/*from w ww  .  j a  v  a 2  s  .  c om*/
 *          The number of events to create
 * @return A {@link SortedSet} of randomly generated {@link F2SEvent}
 */
public SortedSet<F2SEvent> generateRandomEvents(int nbEvents) {
    final SortedSet<F2SEvent> result = new TreeSet<F2SEvent>(new F2SEventComparator());
    while (result.size() != nbEvents) {
        result.add(F2SEventFactory.getInstance().createRandomWithHeaders());
    }
    return result;
}

From source file:org.gwaspi.statistics.ChiSqrBoundaryCalculator.java

protected static void calculateChisqrBoundaryBySampling() throws IOException {

    FileWriter repFW = new FileWriter(boundaryPath);
    BufferedWriter repBW = new BufferedWriter(repFW);

    NetcdfFile ncfile = NetcdfFile.open(netCDFFile);
    List<Dimension> dims = ncfile.getDimensions();
    Dimension sizeDim = dims.get(0);
    Dimension simsDim = dims.get(1);

    String varName = "distributions";
    Variable distributions = ncfile.findVariable(varName);

    try {/*from  w  w  w.j  a va2s .c  o m*/
        for (int i = 0; i < pointsNb; i++) {
            //distributions(i:i:1, 0:simsNb:1)
            ArrayDouble.D2 rdDoubleArrayD2 = (ArrayDouble.D2) distributions
                    .read(i + ":" + i + ":1, 0:" + (simsDim.getLength() - 1) + ":1");
            ArrayDouble.D1 rdDoubleArrayD1 = (D1) rdDoubleArrayD2.reduce();

            SortedSet<Double> currentTS = new TreeSet<Double>();
            for (int j = 0; j < rdDoubleArrayD2.getSize(); j++) {
                currentTS.add(rdDoubleArrayD1.get(j));
            }

            double currentTot = 0;

            int loCount = 0;
            double low95 = 0;
            int topCount = 0;
            double top95 = 0;
            for (Double key : currentTS) {
                long lowLimit = Math.round(simNb * lowFrac) - 1;
                if (loCount == lowLimit) {
                    low95 = key;
                    loCount++;
                } else {
                    loCount++;
                }

                long uppLimit = Math.round(simNb * uppFrac) - 1;
                if (topCount == currentTS.size() - uppLimit) {
                    top95 = key;
                    topCount++;
                } else {
                    topCount++;
                }

                currentTot += key;
            }
            double avg = currentTot / simNb;

            StringBuilder sb = new StringBuilder();
            sb.append(top95);
            sb.append(",");
            sb.append(avg);
            sb.append(",");
            sb.append(low95);
            repBW.append(sb + "\n");
        }
    } catch (IOException ex) {
        log.error("Cannot read data", ex);
    } catch (InvalidRangeException ex) {
        log.error("Cannot read data", ex);
    }

    repBW.close();
    repFW.close();

    log.info("Confidence boundary created for {} points", N);
}

From source file:org.orbisgis.corejdbc.ReadTable.java

/**
 * Compute numeric stats of the specified table column using a limited input rows. Stats are not done in the sql side.
 * @param connection Available connection
 * @param tableName Table name/*from w  ww  .j  ava 2  s.  c  o m*/
 * @param columnName Column name
 * @param rowNum Row id
 * @param pm Progress monitor
 * @return An array of attributes {@link STATS}
 * @throws SQLException
 */
public static String[] computeStatsLocal(Connection connection, String tableName, String columnName,
        SortedSet<Integer> rowNum, ProgressMonitor pm) throws SQLException {
    String[] res = new String[STATS.values().length];
    SummaryStatistics stats = new SummaryStatistics();
    try (Statement st = connection.createStatement()) {
        // Cancel select
        PropertyChangeListener listener = EventHandler.create(PropertyChangeListener.class, st, "cancel");
        pm.addPropertyChangeListener(ProgressMonitor.PROP_CANCEL, listener);
        try (ResultSet rs = st.executeQuery(String.format("SELECT %s FROM %s", columnName, tableName))) {
            ProgressMonitor fetchProgress = pm.startTask(rowNum.size());
            while (rs.next() && !pm.isCancelled()) {
                if (rowNum.contains(rs.getRow())) {
                    stats.addValue(rs.getDouble(columnName));
                    fetchProgress.endTask();
                }
            }
        } finally {
            pm.removePropertyChangeListener(listener);
        }
    }
    res[STATS.SUM.ordinal()] = Double.toString(stats.getSum());
    res[STATS.AVG.ordinal()] = Double.toString(stats.getMean());
    res[STATS.COUNT.ordinal()] = Long.toString(stats.getN());
    res[STATS.MIN.ordinal()] = Double.toString(stats.getMin());
    res[STATS.MAX.ordinal()] = Double.toString(stats.getMax());
    res[STATS.STDDEV_SAMP.ordinal()] = Double.toString(stats.getStandardDeviation());
    return res;
}

From source file:com.puppycrawl.tools.checkstyle.api.AbstractViolationReporterTest.java

@Test
public void testCustomMessage() throws Exception {
    DefaultConfiguration config = createCheckConfig(emptyCheck.getClass());
    config.addMessage("msgKey", "This is a custom message.");
    emptyCheck.configure(config);//from   w  w  w  .java2  s  .  c  o  m

    LocalizedMessages collector = new LocalizedMessages();
    emptyCheck.setMessages(collector);

    emptyCheck.log(0, "msgKey");

    SortedSet<LocalizedMessage> messages = collector.getMessages();
    assertEquals(1, messages.size());
    assertEquals("This is a custom message.", messages.first().getMessage());
}