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:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Returns a sorted array containing all of the elements for all of the
 * {@link DeviceProtocolInfoSource} {@link Set}s.
 * <p>//from   www. j  a v  a  2s.c  om
 * The returned array will be "safe" in that no reference to it is
 * maintained. (In other words, this method must allocate a new array). The
 * caller is thus free to modify the returned array.
 *
 * @return An array containing all the {@link ProtocolInfo} instances.
 */
public ProtocolInfo[] toArray() {
    SortedSet<ProtocolInfo> result = new TreeSet<>();
    setsLock.readLock().lock();
    try {
        for (SortedSet<ProtocolInfo> set : protocolInfoSets.values()) {
            if (set != null) {
                result.addAll(set);
            }
        }
    } finally {
        setsLock.readLock().unlock();
    }
    return result.toArray(new ProtocolInfo[result.size()]);
}

From source file:no.abmu.questionnaire.service.QuestionnaireServiceHelperH3Impl.java

public SchemaList getSchemaDataBySchemaTypeNameAndVersion(SortedSet<OrgUnitReport> orgSortedSet,
        SchemaTypeNameAndVersion schemaTypeNameAndVersion) {

    Assert.checkRequiredArgument("orgSortedSet", orgSortedSet);
    Assert.checkRequiredArgument("schemaTypeNameAndVersion", schemaTypeNameAndVersion);

    String dbSchemaName = schemaTypeNameAndVersion.getDbSchemaName();
    String version = schemaTypeNameAndVersion.getVersion();

    int numberOfReports = orgSortedSet.size();

    SchemaList schemaList = new SchemaList(numberOfReports);
    ProgressStatistics ps = new ProgressStatistics(numberOfReports);
    for (OrgUnitReport orgUnitReport : orgSortedSet) {
        Map<String, Object> report = orgUnitReport.createReport();
        fillInReportValues(report, dbSchemaName, version);
        schemaList.add(report);/* ww w  . ja v  a2 s  .  com*/
        ps.increaseCountAndDumpStatus();
    }
    ps.dumpStatus(true);

    return schemaList;
}

From source file:com.yahoo.pulsar.common.naming.NamespaceBundlesTest.java

@SuppressWarnings("unchecked")
@Test//from  w w w  . j ava2 s  . c  o m
public void testConstructor() throws Exception {
    try {
        new NamespaceBundles(null, (SortedSet<Long>) null, null);
        fail("Should fail w/ null pointer exception");
    } catch (NullPointerException npe) {
        // OK, expected
    }

    try {
        new NamespaceBundles(new NamespaceName("pulsar/use/ns2"), (SortedSet<Long>) null, null);
        fail("Should fail w/ null pointer exception");
    } catch (NullPointerException npe) {
        // OK, expected
    }

    try {
        new NamespaceBundles(new NamespaceName("pulsar.use.ns2"), (SortedSet<Long>) null, null);
        fail("Should fail w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
        // OK, expected
    }

    try {
        new NamespaceBundles(new NamespaceName("pulsar/use/ns2"), (SortedSet<Long>) null, factory);
        fail("Should fail w/ null pointer exception");
    } catch (NullPointerException npe) {
        // OK, expected
    }

    SortedSet<Long> partitions = Sets.newTreeSet();
    try {
        new NamespaceBundles(new NamespaceName("pulsar/use/ns2"), partitions, factory);
        fail("Should fail w/ illegal argument exception");
    } catch (IllegalArgumentException iae) {
        // OK, expected
    }

    partitions.add(0l);
    partitions.add(0x10000000l);
    partitions.add(0x40000000l);
    partitions.add(0xffffffffl);
    NamespaceBundles bundles = new NamespaceBundles(new NamespaceName("pulsar/use/ns2"), partitions, factory);
    Field partitionField = NamespaceBundles.class.getDeclaredField("partitions");
    Field nsField = NamespaceBundles.class.getDeclaredField("nsname");
    Field bundlesField = NamespaceBundles.class.getDeclaredField("bundles");
    partitionField.setAccessible(true);
    nsField.setAccessible(true);
    bundlesField.setAccessible(true);
    long[] partFld = (long[]) partitionField.get(bundles);
    // the same instance
    assertEquals(partitions.size(), partFld.length);
    NamespaceName nsFld = (NamespaceName) nsField.get(bundles);
    assertTrue(nsFld.toString().equals("pulsar/use/ns2"));
    ArrayList<NamespaceBundle> bundleList = (ArrayList<NamespaceBundle>) bundlesField.get(bundles);
    assertEquals(bundleList.size(), 3);
    assertEquals(bundleList.get(0),
            factory.getBundle(nsFld, Range.range(0l, BoundType.CLOSED, 0x10000000l, BoundType.OPEN)));
    assertEquals(bundleList.get(1),
            factory.getBundle(nsFld, Range.range(0x10000000l, BoundType.CLOSED, 0x40000000l, BoundType.OPEN)));
    assertEquals(bundleList.get(2), factory.getBundle(nsFld,
            Range.range(0x40000000l, BoundType.CLOSED, 0xffffffffl, BoundType.CLOSED)));
}

From source file:org.apache.wiki.auth.user.XMLUserDatabase.java

/**
 * Returns all WikiNames that are stored in the UserDatabase
 * as an array of WikiPrincipal objects. If the database does not
 * contain any profiles, this method will return a zero-length
 * array.//from  w w w .j a  va 2s .  co m
 * @return the WikiNames
 * @throws WikiSecurityException In case things fail.
 */
public Principal[] getWikiNames() throws WikiSecurityException {
    if (c_dom == null) {
        throw new IllegalStateException("FATAL: database does not exist");
    }
    SortedSet<Principal> principals = new TreeSet<Principal>();
    NodeList users = c_dom.getElementsByTagName(USER_TAG);
    for (int i = 0; i < users.getLength(); i++) {
        Element user = (Element) users.item(i);
        String wikiName = user.getAttribute(WIKI_NAME);
        if (wikiName == null) {
            log.warn("Detected null wiki name in XMLUserDataBase. Check your user database.");
        } else {
            Principal principal = new WikiPrincipal(wikiName, WikiPrincipal.WIKI_NAME);
            principals.add(principal);
        }
    }
    return principals.toArray(new Principal[principals.size()]);
}

From source file:de.knowwe.defi.usermanager.XMLUserDatabase.java

/**
 * Returns all WikiNames that are stored in the UserDatabase
 * as an array of WikiPrincipal objects. If the database does not
 * contain any profiles, this method will return a zero-length
 * array./*from   ww  w. j a  v a  2  s . c  o m*/
 * @return the WikiNames
 * @throws org.apache.wiki.auth.WikiSecurityException In case things fail.
 */
@Override
public Principal[] getWikiNames() throws WikiSecurityException {
    if (c_dom == null) {
        throw new IllegalStateException("FATAL: database does not exist");
    }
    SortedSet<Principal> principals = new TreeSet<>();
    NodeList users = c_dom.getElementsByTagName(USER_TAG);
    for (int i = 0; i < users.getLength(); i++) {
        Element user = (Element) users.item(i);
        String wikiName = user.getAttribute(WIKI_NAME);
        if (wikiName == null) {
            Log.warning("Detected null wiki name in XMLUserDataBase. Check your user database.");
        } else {
            Principal principal = new WikiPrincipal(wikiName, WikiPrincipal.WIKI_NAME);
            principals.add(principal);
        }
    }
    return principals.toArray(new Principal[principals.size()]);
}

From source file:org.wrml.runtime.rest.ApiNavigator.java

private SortedSet<ResourceMatchResult> matchPath(String path) {

    // TODO Is this needed? The path should be sanitized before getting this far....
    path = StringUtils.trim(path);//from www . j  a  v a  2s  . c om
    if (path.length() == 0 || ApiNavigator.DOCROOT_PATH.equals(path)) {
        return _DocrootResults;
    }

    final SortedSet<ResourceMatchResult> results = new TreeSet<ResourceMatchResult>();
    final String[] pathSegments = StringUtils.split(path, ApiNavigator.PATH_SEPARATOR_CHAR);
    // TODO Refactor out of C-style method calling? Why not return results? MSM: Current approach uses recursion;
    // but still could return results. Note that all of this is private implementation detail.
    matchPathSegment(_Docroot, pathSegments, 0, 0, results);

    ApiNavigator.LOG.debug("The path \"{}\" matches *{}* results.", path, results.size());
    return results;
}

From source file:com.github.FraggedNoob.GitLabTransfer.GitlabRelatedData.java

/**
 * Put in all the notes for a single issue
 * Warning: Will simply add to any existing issue - duplicates will occur 
 * if run more than once./*w w  w  . ja va2  s.  c  o  m*/
 * @param api The api instance to use
 * @param iss Issue from the current project
 * @param ns A sorted set of notes from the source project
 * @return F=fail, T=success
 */
public boolean putIssueNotes(GitlabAPI api, GitlabIssue iss, SortedSet<GitlabNote> ns) {

    // TODO putIssueNotes() blindly adds notes, instead of skipping existing matches.

    int count = 1;
    for (GitlabNote n : ns) {
        try {
            api.createNote(iss, n.getBody());
            System.out.printf("Setting issue note %d/%d, Issue IID=%d.\n", count, ns.size(), iss.getIid());
            count++;
        } catch (IOException e) {
            System.out.printf("Error setting issue note, Issue IID=%d (ID=%d).\n", iss.getIid(), iss.getId());
            e.printStackTrace();
            return false;
        }
    }

    return true;
}

From source file:com.redhat.rhn.manager.configuration.test.ConfigurationManagerTest.java

/**
 * 1) Create a central config channel (A) add a bunch of files &amp; dirs
 * 2) Call ConfigurationManager.countCentrallyManagedFiles and verify
 *      that we have the correct answer//  w  w w. java 2 s .c o m
 * 3) Create a new channel and add ONE file thats new and One file
 *      duplicate of a file in Channel (A) ...
 * 4) Call ConfigurationManager.countCentrallyManagedFiles and verify
 *      that the answer is number of files in Channel A + 1
 * @throws Exception under exceptional circumstances
 */

public void testCountCentrallyManagedFiles() throws Exception {
    user.getOrg().addRole(RoleFactory.CONFIG_ADMIN);
    user.addPermanentRole(RoleFactory.CONFIG_ADMIN);
    Server s = makeServerForChannelCountTests();
    ConfigFileCount actual = cm.countCentrallyManagedPaths(s, user);

    assertEquals(EXPECTED_COUNT, actual);

    final ConfigChannel c = s.getConfigChannels().get(0);

    SortedSet files = c.getConfigFiles();
    assertEquals(files.size(), EXPECTED_COUNT.getFiles() + EXPECTED_COUNT.getDirectories());
    //now add a new channel -
    // (with some file/ directory intersections)

    ConfigFile fl = (ConfigFile) files.first();
    final String path = fl.getConfigFileName().getPath();

    ConfigChannel cc = ConfigTestUtils.createConfigChannel(user.getOrg());

    //Create a Duplicate Path and add it to the new channel
    final ConfigFile fl2 = cc.createConfigFile(ConfigFileState.normal(), path);
    ConfigTestUtils.createConfigRevision(fl2, ConfigFileType.file());

    //Now Create a NEW Path and add it to the new channel
    ConfigFile fl3 = ConfigTestUtils.createConfigFile(cc);
    ConfigTestUtils.createConfigRevision(fl3, ConfigFileType.file());

    s.subscribeAt(cc, 0);
    ServerFactory.save(s);
    actual = cm.countCentrallyManagedPaths(s, user);

    ConfigFileCount expected = ConfigFileCount.create(EXPECTED_COUNT.getFiles() + 1,
            EXPECTED_COUNT.getDirectories(), 0);
    assertEquals(expected, actual);
}

From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportJobsQuartzScheduler.java

protected String enumerateCronVals(SortedSet vals, int totalCount) {
    if (vals == null || vals.isEmpty()) {
        throw new JSException("jsexception.no.values.to.enumerate");
    }//from w ww  .ja  v a2  s .  c  o m

    if (vals.size() == totalCount) {
        return "*";
    }

    StringBuffer enumStr = new StringBuffer();
    for (Iterator it = vals.iterator(); it.hasNext();) {
        Byte val = (Byte) it.next();
        enumStr.append(val.byteValue());
        enumStr.append(',');
    }
    return enumStr.substring(0, enumStr.length() - 1);
}