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:nz.co.senanque.workflowui.LaunchWizard.java

public int setup() {
    SortedSet<ProcessDefinitionHolder> options = getVisibleProcesses();
    final Container c = new IndexedContainer();
    if (options != null) {
        for (final Iterator<?> i = options.iterator(); i.hasNext();) {
            c.addItem(i.next());//from ww w . j  av a2  s . c o m
        }
    }
    select.setContainerDataSource(c);
    select.setRows(Math.min(10, options.size() + 2));
    return options.size();
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java

@Override
public AvailableBlock retrieveTargetBlock(final IScheduleOwner owner, final Date startDate) {
    SortedSet<AvailableBlock> expanded = retrieveBlocksForDayInternal(owner, startDate);
    // truncate startDate to the second
    final Date truncatedStart = DateUtils.truncate(startDate, Calendar.MINUTE);

    if (expanded.size() > 0) {
        for (Iterator<AvailableBlock> expandedIterator = expanded.iterator(); expandedIterator.hasNext();) {
            AvailableBlock block = expandedIterator.next();
            if (block.getStartTime().equals(truncatedStart)) {
                // always return preferred minimum length block
                return block;
            }/*from   w  ww  .  j  ava 2  s  .  c  o m*/
            if (block.getStartTime().after(truncatedStart)) {
                // iterated past the target block, can short circuit and say we didn't find it
                return null;
            }
        }
    }
    // block not found, return null
    return null;
}

From source file:ubic.gemma.core.loader.expression.geo.GeoSampleCorrespondence.java

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();

    StringBuilder singletons = new StringBuilder();
    SortedSet<String> groupStrings = new TreeSet<>();
    for (Set<String> set : sets) {
        StringBuilder group = new StringBuilder();
        SortedSet<String> sortedSet = new TreeSet<>(set);
        for (String accession : sortedSet) {
            group.append(accession).append(" ('")
                    .append(accToTitle != null && accToTitle.containsKey(accession) ? accToTitle.get(accession)
                            : "[no title]")
                    .append("'").append(accToDataset != null ? (" in " + accToDataset.get(accession)) : "")
                    .append(")");

            if (sortedSet.size() == 1) {
                singletons.append(group).append("\n");
                group.append(" - singleton");
            } else {
                group.append("\t<==>\t");
            }//from w ww . j  a v a2  s .c om
        }
        group.append("\n");
        groupStrings.add(group.toString());
    }

    for (String string : groupStrings) {
        buf.append(string);
    }

    return buf.toString().replaceAll("\\t<==>\\t\\n", "\n")
            + (singletons.length() > 0 ? "\nSingletons:\n" + singletons.toString() : "");
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java

@Override
public AvailableBlock retrieveTargetDoubleLengthBlock(IScheduleOwner owner, Date startDate) {
    SortedSet<AvailableBlock> expanded = retrieveBlocksForDayInternal(owner, startDate);
    // truncate startDate to the second
    final Date truncatedStart = DateUtils.truncate(startDate, Calendar.MINUTE);

    if (expanded.size() > 0) {
        for (Iterator<AvailableBlock> expandedIterator = expanded.iterator(); expandedIterator.hasNext();) {
            AvailableBlock block = expandedIterator.next();
            if (block.getStartTime().equals(truncatedStart)) {
                if (owner.getPreferredMeetingDurations().isDoubleLength() && expandedIterator.hasNext()) {
                    // combine the block with the next
                    AvailableBlock nextBlock = expandedIterator.next();
                    AvailableBlock combined = AvailableBlockBuilder.createBlock(block.getStartTime(),
                            nextBlock.getEndTime(), block.getVisitorLimit(), block.getMeetingLocation());
                    return combined;
                }//from   w  w w  .j ava  2  s  . co m
            }

            if (block.getStartTime().after(truncatedStart)) {
                // iterated past the target block, can short circuit and say we didn't find it
                return null;
            }
        }
    }
    // block not found, return null
    return null;
}

From source file:uk.co.flax.biosolr.ontology.core.ols.OLSOntologyHelper.java

/**
 * Find the IRIs of all terms referenced by a related URL.
 *
 * @param baseUrl the base URL to look up, from a Link or similar
 * query-type URL./*  w  w w.j a  va2 s.c  o m*/
 * @return a set of IRIs referencing the terms found for the
 * given URL.
 * @throws OntologyHelperException if problems occur accessing the
 * web service.
 */
protected Set<String> queryWebServiceForTerms(String baseUrl) throws OntologyHelperException {
    updateLastCallTime();
    Set<String> retList;

    // Build URL for first page
    List<String> urls = buildPageUrls(baseUrl, 0, 1);
    // Sort returned calls by page number
    SortedSet<RelatedTermsResult> results = new TreeSet<>(
            (RelatedTermsResult r1, RelatedTermsResult r2) -> r1.getPage().compareTo(r2.getPage()));
    results.addAll(olsClient.callOLS(urls, RelatedTermsResult.class));

    if (results.size() == 0) {
        retList = Collections.emptySet();
    } else {
        Page page = results.first().getPage();
        if (page.getTotalPages() > 1) {
            // Get remaining pages
            urls = buildPageUrls(baseUrl, page.getNumber() + 1, page.getTotalPages());
            results.addAll(olsClient.callOLS(urls, RelatedTermsResult.class));
        }

        retList = new HashSet<>(page.getTotalSize());
        for (RelatedTermsResult result : results) {
            result.getTerms().forEach(t -> {
                terms.put(t.getIri(), t);
                retList.add(t.getIri());
            });
        }
    }

    return retList;
}

From source file:org.tonguetied.datatransfer.importing.PropertiesImporterTest.java

/**
 * Test method for/*from w ww . j  a  va  2s.co m*/
 * {@link PropertiesImporter#importData(ImportParameters)}.
 */
public final void testImportData() throws Exception {
    final String fileName = "PropertiesImporterTest";
    File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.properties.getDefaultFileExtension());
    byte[] input = FileUtils.readFileToByteArray(file);
    final Importer importer = ImporterFactory.getImporter(FormatType.properties, keywordService,
            transferRepository);
    TranslationState expectedState = TranslationState.VERIFIED;
    ImportParameters parameters = new ImportParameters();
    parameters.setData(input);
    parameters.setTranslationState(expectedState);
    parameters.setFileName(fileName);
    importer.importData(parameters);
    Keyword actual = keywordService.getKeyword("import.test.one");
    assertNotNull(actual);
    SortedSet<Translation> translations = actual.getTranslations();
    assertEquals(1, translations.size());
    Object[] actualTranslations = actual.getTranslations().toArray();
    Translation actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("Value 1", actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.two");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.three");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("new value 3", actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.four");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.five");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle1, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("value 5 \nnew line", actualTranslation.getValue());
}

From source file:org.tonguetied.datatransfer.importing.PropertiesImporterTest.java

/**
 * Test method for//from  www . j  a v  a  2  s  .  c o  m
 * {@link PropertiesImporter#importData(ImportParameters)}.
 */
public final void testImportDataWithBundle() throws Exception {
    final String fileName = "PropertiesImporterTest";
    File file = new File(TEST_DATA_DIR, fileName + "." + FormatType.properties.getDefaultFileExtension());
    byte[] input = FileUtils.readFileToByteArray(file);
    final Importer importer = ImporterFactory.getImporter(FormatType.properties, keywordService,
            transferRepository);
    TranslationState expectedState = TranslationState.VERIFIED;
    ImportParameters parameters = new ImportParameters();
    parameters.setData(input);
    parameters.setTranslationState(expectedState);
    parameters.setFileName(fileName);
    parameters.setBundle(bundle2);
    importer.importData(parameters);
    Keyword actual = keywordService.getKeyword("import.test.one");
    assertNotNull(actual);
    SortedSet<Translation> translations = actual.getTranslations();
    assertEquals(1, translations.size());
    Object[] actualTranslations = actual.getTranslations().toArray();
    Translation actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("Value 1", actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.two");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(1, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.three");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[1];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("new value 3", actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.four");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[1];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertNull(actualTranslation.getValue());

    actual = keywordService.getKeyword("import.test.five");
    assertNotNull(actual);
    translations = actual.getTranslations();
    assertEquals(2, translations.size());
    actualTranslations = actual.getTranslations().toArray();
    actualTranslation = (Translation) actualTranslations[0];
    assertEquals(defaultCountry, actualTranslation.getCountry());
    assertEquals(defaultLanguage, actualTranslation.getLanguage());
    assertEquals(bundle2, actualTranslation.getBundle());
    assertEquals(expectedState, actualTranslation.getState());
    assertEquals("value 5 \nnew line", actualTranslation.getValue());
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImplTest.java

@Test
public void testClearWeekUnevenSchedule() throws InputFormatException, ParseException {
    // get owner with meeting durations preference of 17 minutes
    IScheduleOwner owner = sampleOwners[2];

    SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat();
    SortedSet<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:03 AM", "3:19 PM", "MWF",
            dateFormat.parse("20100830"), dateFormat.parse("20101001"), 1);
    availableScheduleDao.addToSchedule(owner, blocks);

    AvailableSchedule stored = availableScheduleDao.retrieve(owner);
    SortedSet<AvailableBlock> storedBlocks = stored.getAvailableBlocks();
    Assert.assertEquals(15, storedBlocks.size());

    SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(storedBlocks, 17);
    Assert.assertEquals(330, expanded.size());

    AvailableSchedule weekToRemove = availableScheduleDao.retrieveWeeklySchedule(owner,
            dateFormat.parse("20100912"));
    Assert.assertEquals(3, weekToRemove.getAvailableBlocks().size());
    Assert.assertEquals(66, AvailableBlockBuilder.expand(weekToRemove.getAvailableBlocks(), 17).size());
    availableScheduleDao.removeFromSchedule(owner, weekToRemove.getAvailableBlocks());

    AvailableSchedule storedAfterRemove = availableScheduleDao.retrieve(owner);
    Assert.assertEquals(12, storedAfterRemove.getAvailableBlocks().size());
}

From source file:org.eclipse.winery.repository.rest.resources.artifacts.GenericArtifactsResource.java

/**
 * Required for artifacts.jsp/*from   w w w  .j  a va  2 s  . c om*/
 *
 * @return list of known artifact types.
 */
public List<QName> getAllArtifactTypes() {
    SortedSet<ArtifactTypeId> allArtifactTypes = RepositoryFactory.getRepository()
            .getAllDefinitionsChildIds(ArtifactTypeId.class);
    List<QName> res = new ArrayList<>(allArtifactTypes.size());
    for (ArtifactTypeId id : allArtifactTypes) {
        res.add(id.getQName());
    }
    return res;
}

From source file:org.cloudata.examples.web.TermUploadJob.java

public void exec(String[] options) throws Exception {
    if (options.length < 1) {
        System.out.println("Usage: java TermUploadJob <num of repeats> termUpload <inputPath> [#redcue]");
        System.exit(0);/*w w  w. j ava  2  s  .  c o  m*/
    }
    JobConf jobConf = new JobConf(TermUploadJob.class);
    JobClient jobClinet = new JobClient(jobConf);
    int maxReduce = jobClinet.getClusterStatus().getMaxReduceTasks() * 2;
    if (options.length > 1) {
        maxReduce = Integer.parseInt(options[1]);
    }

    jobConf.setInt("mapred.task.timeout", 60 * 60 * 1000);

    FileSystem fs = FileSystem.get(jobConf);

    CloudataConf nconf = new CloudataConf();
    if (!CTable.existsTable(nconf, TERM_TABLE)) {
        //Table  
        Path path = new Path("blogdata/tmp/weight");
        FileStatus[] paths = fs.listStatus(path);
        if (paths == null || paths.length == 0) {
            LOG.error("No Partition info:" + path);
            return;
        }
        SortedSet<Text> terms = new TreeSet<Text>();
        Text text = new Text();
        for (FileStatus eachPath : paths) {
            CloudataLineReader reader = new CloudataLineReader(fs.open(eachPath.getPath()));
            while (true) {
                int length = reader.readLine(text);
                if (length <= 0) {
                    break;
                }
                terms.add(new Text(text));
            }
        }

        int temrsPerTablet = terms.size() / (maxReduce - 1);
        int count = 0;
        List<Row.Key> rowKeys = new ArrayList<Row.Key>();
        for (Text term : terms) {
            count++;
            if (count == temrsPerTablet) {
                rowKeys.add(new Row.Key(term.getBytes()));
                count = 0;
            }
        }
        rowKeys.add(Row.Key.MAX_KEY);

        TableSchema temrTableInfo = new TableSchema(TERM_TABLE, "Test", TERM_TABLE_COLUMNS);
        CTable.createTable(nconf, temrTableInfo, rowKeys.toArray(new Row.Key[] {}));
    }
    CTable termTable = CTable.openTable(nconf, TERM_TABLE);
    TabletInfo[] tabletInfos = termTable.listTabletInfos();

    Path tempOutputPath = new Path("WebTableJob_" + System.currentTimeMillis());

    jobConf.setJobName("TermUploadJob" + "(" + new Date() + ")");
    FileInputFormat.addInputPath(jobConf, new Path(options[0]));

    //<MAP>
    jobConf.setMapperClass(TermUploadMap.class);
    jobConf.setMapOutputKeyClass(Text.class);
    jobConf.setMapOutputValueClass(Text.class);
    jobConf.setInputFormat(TextInputFormat.class);
    jobConf.set(AbstractTabletInputFormat.OUTPUT_TABLE, TERM_TABLE);
    jobConf.setPartitionerClass(WebKeyRangePartitioner.class);
    jobConf.setMaxMapAttempts(0);
    //</MAP>

    //<REDUCE>
    jobConf.setReducerClass(TermUploadReduce.class);
    jobConf.setOutputKeyClass(Text.class);
    jobConf.setOutputValueClass(Text.class);
    jobConf.setNumReduceTasks(tabletInfos.length);
    FileOutputFormat.setOutputPath(jobConf, tempOutputPath);
    jobConf.setNumReduceTasks(maxReduce);
    jobConf.setMaxReduceAttempts(0);
    //<REDUCE>

    //Run Job
    JobClient.runJob(jobConf);

    fs.delete(tempOutputPath);
}