Example usage for java.util TreeSet size

List of usage examples for java.util TreeSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

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

Usage

From source file:org.apache.hadoop.hbase.allocation.CheckMeta.java

/**
 * get table descriptors./*  www  .  j a va  2s .com*/
 * 
 * @return table descriptors.
 */
public static HTableDescriptor[] getTables() {
    HTableDescriptor[] ret = null;
    try {
        Scan s = new Scan();
        if (t == null)
            t = new HTable(".META.");
        t.setScannerCaching(1000);
        s.setCaching(1000);
        ResultScanner sn = t.getScanner(s);
        Result r = null;
        final TreeSet<HTableDescriptor> uniqueTables = new TreeSet<HTableDescriptor>();
        while ((r = sn.next()) != null) {
            byte[] value = r.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
            HRegionInfo info = null;
            if (value != null) {
                info = Writables.getHRegionInfo(value);
            }
            // Only examine the rows where the startKey is zero length
            if (info != null && info.getStartKey().length == 0) {
                uniqueTables.add(info.getTableDesc());
            }
        }
        try {
            sn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        ret = uniqueTables.toArray(new HTableDescriptor[uniqueTables.size()]);
        return ret;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.dasein.cloud.util.APITrace.java

static public String[] listAccounts(@Nonnull String provider, @Nonnull String cloud) {
    provider = provider.replaceAll(DELIMITER_REGEX, "_");
    cloud = cloud.replaceAll(DELIMITER_REGEX, "_");
    TreeSet<String> list = new TreeSet<String>();

    synchronized (apiCount) {
        for (String call : apiCount.keySet()) {
            String[] parts = call.split(DELIMITER_REGEX);

            if (parts.length > 2 && parts[0].equals(provider) && parts[1].equals(cloud)) {
                list.add(parts[2]);/*from  ww  w. j  av  a2  s  .  co m*/
            }
        }
    }
    return list.toArray(new String[list.size()]);
}

From source file:com.espertech.esper.collection.TestNumberSetShiftGroupEnumeration.java

private int[] getArr(TreeSet<Integer> set) {
    int[] arr = new int[set.size()];
    int count = 0;
    for (int val : set) {
        arr[count++] = val;
    }//w  ww. j  av  a  2 s.  c om
    return arr;
}

From source file:org.mapfish.print.output.OutputFactory.java

private boolean permitted(String supportedFormat, Config config) {
    TreeSet<String> configuredFormats = config.getFormats();
    if (configuredFormats.size() == 1 && configuredFormats.iterator().next().trim().equals("*")) {
        return true;
    }/*from  w  w w . j  ava2 s.  c  o  m*/

    if (configuredFormats.isEmpty()) {
        return "pdf".equalsIgnoreCase(supportedFormat);
    }

    for (String configuredFormat : configuredFormats) {
        if (configuredFormat.equalsIgnoreCase(supportedFormat))
            return true;
    }

    return false;
}

From source file:com.btmura.android.reddit.content.RelatedSubredditLoader.java

private MatrixCursor buildCursor(TreeSet<String> subreddits) {
    int i = 0;/*w  ww.  jav a  2  s .  c o  m*/
    MatrixCursor cursor = new MatrixCursor(COLUMN_NAMES, subreddits.size());
    for (String subreddit : subreddits) {
        cursor.addRow(Array.of(i++, subreddit));
    }
    return cursor;
}

From source file:turtlekit.viewer.PopulationCharter.java

/**
 * //from  w  w  w.j a  v a 2s  . co  m
 */
protected void updateSeries() {
    TreeSet<String> roles = getExistingRoles();
    if (roles != null && roles.size() != handledRoles.size()) {
        for (String role : roles) {
            if (handledRoles.add(role)) {
                addSerie(role);
            }
        }
    }
}

From source file:org.springframework.integration.x.rollover.file.RolloverFileMessageHandlerTest.java

@Test
public void testRolloverFileSink() throws IOException, InterruptedException {

    applicationContext.start();//from   w ww  .  j a v  a 2  s.co  m

    input.send(new GenericMessage<String>("foo"));

    Thread.sleep(1100); // > 1 sec to make sure it crosses the rollover time trigger set to 1 second.

    input.send(new GenericMessage<String>("bar")); // Second message should land in a new file.

    TreeSet<File> files = new TreeSet<File>(FileUtils.listFiles(tmpDir, null, false));

    assertEquals(2, files.size());

    Iterator<File> iterator = files.iterator();

    File firstFile = iterator.next();
    assertTrue(firstFile.toString().startsWith("test_results/archive.test666_"));
    // no gzip at the moment as the compression now happens asynchronous
    assertEquals("foo\n", IOUtils.toString(firstFile.toURI()));

    File secondFile = iterator.next();
    assertTrue(secondFile.toString().startsWith("test_results/test666_"));
    assertEquals("bar\n", IOUtils.toString(secondFile.toURI()));
}

From source file:org.eclipse.skalli.model.ext.maven.internal.MavenReactorConverter.java

@Override
protected void marshal(MavenReactorProjectExt extension) throws IOException {
    MavenReactor reactor = extension.getMavenReactor();
    if (reactor != null) {
        MavenModule reactorCoordinate = reactor.getCoordinate();
        if (reactorCoordinate != null) {
            writer.object(TAG_COORDINATE);
            writeCoordinate(reactorCoordinate);
            writer.end();//from   w  w w.j a  va  2 s . c om
        }
        TreeSet<MavenModule> modules = reactor.getModules();
        if (modules.size() > 0) {
            writer.array(TAG_MODULES, TAG_MODULE);
            for (MavenModule moduleCoordinate : modules) {
                writer.object();
                writeCoordinate(moduleCoordinate);
                writer.end();
            }
            writer.end();
        }
    }
}

From source file:org.eclipse.skalli.model.ext.maven.internal.MavenReactorConverter.java

@Deprecated
@Override/*w  w w .  j a  v a2 s  .  com*/
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
    MavenReactorProjectExt ext = (MavenReactorProjectExt) source;
    MavenReactor reactor = ext.getMavenReactor();
    if (reactor != null) {
        MavenModule reactorCoordinate = reactor.getCoordinate();
        if (reactorCoordinate != null) {
            writer.startNode(TAG_COORDINATE); // <mavenReactor>
            writeContent(writer, reactorCoordinate);
            writer.endNode(); // </coordinate>
        }

        TreeSet<MavenModule> modules = reactor.getModules();
        if (modules.size() > 0) {
            writer.startNode(TAG_MODULES); // <modules>
            for (MavenModule moduleCoordinate : modules) {
                writer.startNode(TAG_MODULE); // <module>
                writeContent(writer, moduleCoordinate);
                writer.endNode(); // </module>
            }
            writer.endNode(); // </modules>
        }
    }
}

From source file:net.java.sip.communicator.impl.history.HistoryReaderImpl.java

/**
 * Used to limit the files if any starting or ending date exist
 * So only few files to be searched.//from w ww  .  ja  v a 2 s  .  co  m
 *
 * @param filelist Iterator
 * @param startDate Date
 * @param endDate Date
 * @param reverseOrder reverse order of files
 * @return Vector
 */
static Vector<String> filterFilesByDate(Iterator<String> filelist, Date startDate, Date endDate,
        final boolean reverseOrder) {
    if (startDate == null && endDate == null) {
        // no filtering needed then just return the same list
        Vector<String> result = new Vector<String>();
        while (filelist.hasNext()) {
            result.add(filelist.next());
        }

        Collections.sort(result, new Comparator<String>() {

            public int compare(String o1, String o2) {
                if (reverseOrder)
                    return o2.compareTo(o1);
                else
                    return o1.compareTo(o2);
            }
        });

        return result;
    }
    // first convert all files to long
    TreeSet<Long> files = new TreeSet<Long>();
    while (filelist.hasNext()) {
        String filename = filelist.next();

        files.add(Long.parseLong(filename.substring(0, filename.length() - 4)));
    }

    TreeSet<Long> resultAsLong = new TreeSet<Long>();

    // Temporary fix of a NoSuchElementException
    if (files.size() == 0) {
        return new Vector<String>();
    }

    Long startLong;
    Long endLong;

    if (startDate == null)
        startLong = Long.MIN_VALUE;
    else
        startLong = startDate.getTime();

    if (endDate == null)
        endLong = Long.MAX_VALUE;
    else
        endLong = endDate.getTime();

    // get all records inclusive the one before the startdate
    for (Long f : files) {
        if (startLong <= f && f <= endLong) {
            resultAsLong.add(f);
        }
    }

    // get the subset before the start date, to get its last element
    // if exists
    if (!files.isEmpty() && files.first() <= startLong) {
        SortedSet<Long> setBeforeTheInterval = files.subSet(files.first(), true, startLong, true);
        if (!setBeforeTheInterval.isEmpty())
            resultAsLong.add(setBeforeTheInterval.last());
    }

    Vector<String> result = new Vector<String>();

    Iterator<Long> iter = resultAsLong.iterator();
    while (iter.hasNext()) {
        Long item = iter.next();
        result.add(item.toString() + ".xml");
    }

    Collections.sort(result, new Comparator<String>() {

        public int compare(String o1, String o2) {
            if (reverseOrder)
                return o2.compareTo(o1);
            else
                return o1.compareTo(o2);
        }
    });

    return result;
}