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:org.jasig.schedassist.model.AvailableBlockBuilderTest.java

/**
 * Create 2 adjacent blocks visitor limit set to 10.
 * Pass them into combine, assert they come out 1 combined block.
 * /* ww w. j  a v a  2 s  .  com*/
 * @throws Exception
 */
@Test
public void testCombineVisitorLimit10() throws Exception {
    AvailableBlock block1 = AvailableBlockBuilder.createBlock("20091007-1200", "20091007-1230", 10);
    assertEquals(30, block1.getDurationInMinutes());
    AvailableBlock block2 = AvailableBlockBuilder.createBlock("20091007-1230", "20091007-1300", 10);
    assertEquals(30, block2.getDurationInMinutes());
    SortedSet<AvailableBlock> smallBlocks = new TreeSet<AvailableBlock>();
    smallBlocks.add(block1);
    smallBlocks.add(block2);
    SortedSet<AvailableBlock> resultCombined = AvailableBlockBuilder.combine(smallBlocks);
    assertEquals(resultCombined.size(), 1);
    AvailableBlock expectedCombined = AvailableBlockBuilder.createBlock("20091007-1200", "20091007-1300", 10);
    assertTrue(resultCombined.contains(expectedCombined));
    assertEquals(60, expectedCombined.getDurationInMinutes());
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.SharedBuildNumberController.java

protected ModelAndView listBuildNumbers(HttpServletRequest request) {
    ModelAndView modelAndView = new ModelAndView(this.listJspPagePath);

    boolean descending = "desc".equalsIgnoreCase(request.getParameter("direction"));

    SortedSet<SharedBuildNumber> set;
    if ("name".equalsIgnoreCase(request.getParameter("sort"))) {
        set = this.configurationService.getAllSharedBuildNumbersSortedByName(descending);
        modelAndView.getModel().put("sortedBy", "name");
    } else {/*from  w  ww.ja va  2s  .  c  o  m*/
        set = this.configurationService.getAllSharedBuildNumbersSortedById(descending);
        modelAndView.getModel().put("sortedBy", "id");
    }

    modelAndView.getModel().put(SharedBuildNumberController.PREFIX,
            BuildNumberPropertiesProvider.PARAMETER_PREFIX);
    modelAndView.getModel().put("numResults", set.size());
    modelAndView.getModel().put("buildNumbers", set);
    modelAndView.getModel().put("sortClass", descending ? "sortedDesc" : "sortedAsc");
    modelAndView.getModel().put("sortChange", descending ? "asc" : "desc");

    return modelAndView;
}

From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java

/**
 * Create adjacent available blocks but set different meeting locations.
 * Confirm blocks not combined by combine method.
 * @throws InputFormatException // w  ww.j  a v a 2 s. c o  m
 * 
 */
@Test
public void testDifferentMeetingLocationNotCombined() throws InputFormatException {
    AvailableBlock blockNoLocation = AvailableBlockBuilder.createBlock("20110810-0900", "20110810-0930", 1,
            "some location");
    AvailableBlock blockWithLocation = AvailableBlockBuilder.createBlock("20110810-0930", "20110810-1000", 1,
            "different location");

    SortedSet<AvailableBlock> smallBlocks = new TreeSet<AvailableBlock>();
    smallBlocks.add(blockNoLocation);
    smallBlocks.add(blockWithLocation);

    SortedSet<AvailableBlock> combined = AvailableBlockBuilder.combine(smallBlocks);
    Assert.assertEquals(2, combined.size());
    Assert.assertEquals(blockNoLocation, combined.first());
    Assert.assertEquals(blockWithLocation, combined.last());
}

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

protected Object decipherDocumentSurrogateKeyValue(final URI uri, final Prototype prototype) {

    final ApiNavigator apiNavigator = getParentApiNavigator(uri);

    if (apiNavigator == null) {
        return null;
    }/*from w ww . j a v a2s. com*/

    final SortedSet<Parameter> surrogateKeyComponents = apiNavigator.getSurrogateKeyComponents(uri, prototype);
    if (surrogateKeyComponents == null || surrogateKeyComponents.isEmpty()) {
        return null;
    }

    final Set<String> allKeySlotNames = prototype.getAllKeySlotNames();

    final Object surrogateKeyValue;
    if (surrogateKeyComponents.size() == 1) {
        final Parameter surrogateKeyPair = surrogateKeyComponents.first();

        final String slotName = surrogateKeyPair.getName();
        if (!allKeySlotNames.contains(slotName)) {
            return null;
        }

        final String slotTextValue = surrogateKeyPair.getValue();
        final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue);

        surrogateKeyValue = slotValue;
    } else {

        final SortedMap<String, Object> keySlots = new TreeMap<String, Object>();

        for (final Parameter surrogateKeyPair : surrogateKeyComponents) {

            final String slotName = surrogateKeyPair.getName();
            if (!allKeySlotNames.contains(slotName)) {
                continue;
            }

            final String slotTextValue = surrogateKeyPair.getValue();
            final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue);

            if (slotValue == null) {
                continue;
            }

            keySlots.put(slotName, slotValue);

        }

        if (keySlots.size() == 1) {
            surrogateKeyValue = keySlots.get(keySlots.firstKey());
        } else {
            surrogateKeyValue = new CompositeKey(keySlots);
        }
    }

    return surrogateKeyValue;

}

From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java

/**
 * Create a series of (combined) blocks. 
 * Expand that series, then re-combined.
 * Assert the re-combined set matches the original set.
 * // w w w . j  a  va 2  s  .  c  om
 * @throws Exception
 */
@Test
public void testCombine() throws Exception {
    SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat();
    Date startDate = dateFormat.parse("20080624");
    Date endDate = dateFormat.parse("20080806");
    Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "11:30 AM", "MTWRF", startDate,
            endDate);

    // 32 weekdays between June 24 2008 and August 6 2008
    assertEquals(32, blocks.size());

    SortedSet<AvailableBlock> expandedBlocks = AvailableBlockBuilder.expand(blocks, 30);
    assertEquals(160, expandedBlocks.size());

    Set<AvailableBlock> recombinedBlocks = AvailableBlockBuilder.combine(expandedBlocks);
    Iterator<AvailableBlock> originalIterator = blocks.iterator();
    Iterator<AvailableBlock> recombinedIterator = recombinedBlocks.iterator();
    for (int i = 0; i < 32; i++) {
        assertEquals(originalIterator.next(), recombinedIterator.next());
    }

    assertEquals(32, recombinedBlocks.size());
}

From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java

/** 
 * Create 1 years worth of (combined) blocks.
 * Expand the set./*from w  w w. jav a  2s  .  co m*/
 * Re-combine the expanded set, assert matches original set.
 * 
 * @throws Exception
 */
@Test
public void testCombine2() throws Exception {
    SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat();
    Date startDate = dateFormat.parse("20080101");
    Date endDate = dateFormat.parse("20081231");
    Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("12:00 AM", "11:30 PM", "NMTWRFS",
            startDate, endDate);

    // 366 days in 2008
    assertEquals(366, blocks.size());

    SortedSet<AvailableBlock> expandedBlocks = AvailableBlockBuilder.expand(blocks, 30);
    assertEquals(17202, expandedBlocks.size());

    Set<AvailableBlock> recombinedBlocks = AvailableBlockBuilder.combine(expandedBlocks);
    Iterator<AvailableBlock> originalIterator = blocks.iterator();
    Iterator<AvailableBlock> recombinedIterator = recombinedBlocks.iterator();
    for (int i = 0; i < 366; i++) {
        assertEquals(originalIterator.next(), recombinedIterator.next());
    }

    assertEquals(366, recombinedBlocks.size());
}

From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java

/**
 * Create 50 years worth of (combined) blocks.
 * Expand the set./*from   ww w  . j a  v a  2  s.  c  o  m*/
 * Re-combine the expanded set, assert matches original set.
 * 
 * @throws Exception
 */
//@Test
public void testCombine50Years() throws Exception {
    SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat();
    Date startDate = dateFormat.parse("20080101");
    Date endDate = dateFormat.parse("20581231");
    Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("12:00 AM", "11:30 PM", "NMTWRFS",
            startDate, endDate);

    assertEquals(18628, blocks.size());

    SortedSet<AvailableBlock> expandedBlocks = AvailableBlockBuilder.expand(blocks, 30);
    assertEquals(875516, expandedBlocks.size());

    Set<AvailableBlock> recombinedBlocks = AvailableBlockBuilder.combine(expandedBlocks);
    Iterator<AvailableBlock> originalIterator = blocks.iterator();
    Iterator<AvailableBlock> recombinedIterator = recombinedBlocks.iterator();
    for (int i = 0; i < 18628; i++) {
        assertEquals(originalIterator.next(), recombinedIterator.next());
    }

    assertEquals(18628, recombinedBlocks.size());
}

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

/**
 * Determine which resource(s) match the requested resource id.
 * <p/>/*www  . j  ava  2s  .co m*/
 * Note: This needs to be as fast as possible because it is used during client request handling.
 */
private SortedSet<ResourceMatchResult> match(final URI uri) {

    ApiNavigator.LOG.debug("Attempting match on URI {}", new Object[] { uri });

    if (uri == null) {
        ApiNavigator.LOG.error("3 This ApiNavigator cannot locate a resource with a *null* identifier.");
        throw new ApiNavigatorException("This ApiNavigator cannot locate a resource with a *null* identifier.",
                null, this);

    }

    final URI apiUri = getApiUri();

    final String requestUriString = uri.toString();
    final String apiUriString = apiUri.toString();

    if (!requestUriString.startsWith(apiUriString)) {
        ApiNavigator.LOG.error("4 This ApiNavigator has charted \"" + apiUri
                + "\", which does not manage the specified resource (" + uri + ")");
        throw new ApiNavigatorException(
                "This ApiNavigator has charted \"" + apiUri
                        + "\", which does not manage the specified resource (" + uri + ")",
                null, this, Status.NOT_FOUND);
    }

    final String path = requestUriString.substring(apiUriString.length());

    final SortedSet<ResourceMatchResult> results = matchPath(path);

    if (results == null || results.isEmpty() || results.size() == 1) {
        return results;
    }

    int resultsTiedForFirst = 0;
    final int highestScore = results.first().getScore();
    for (final ResourceMatchResult result : results) {
        final int score = result.getScore();
        if (score == highestScore) {
            resultsTiedForFirst++;
        } else {
            break;
        }
    }

    // TODO there's no differentiation here; either a lot of logic missing, or a lot of unnecessary logic
    if (resultsTiedForFirst == 1) {
        return results;
    }

    return results;
}

From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java

/**
 * Create a set of blocks with createBlocks.
 * expand, then remove some of the expanded elements.
 * call combine and verify blocks are created properly.
 * // w w  w.ja  v  a  2s  .  com
 * @throws Exception
 */
@Test
public void testCombine3() throws Exception {
    SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat();
    Date startDate = dateFormat.parse("20080720");
    Date endDate = dateFormat.parse("20080726");
    Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("8:00 AM", "4:00 PM", "MWF", startDate,
            endDate);

    // Mon/Wed/Fri from July 20 to July 26
    // 3 days in this span
    assertEquals(3, blocks.size());
    // 16 blocks per day (8 hours)
    SortedSet<AvailableBlock> expandedBlocks = AvailableBlockBuilder.expand(blocks, 30);
    assertEquals(48, expandedBlocks.size());

    // remove 12:00 to 12:30 on Wednesday
    expandedBlocks.remove(AvailableBlockBuilder.createBlock("20080723-1200", "20080723-1230"));

    assertEquals(47, expandedBlocks.size());

    SortedSet<AvailableBlock> recombinedBlocks = AvailableBlockBuilder.combine(expandedBlocks);
    assertEquals(4, recombinedBlocks.size());

    SortedSet<AvailableBlock> reexpandedBlocks = AvailableBlockBuilder.expand(recombinedBlocks, 30);
    assertEquals(47, reexpandedBlocks.size());

    // remove 3:30 to 4:00 on Friday
    reexpandedBlocks.remove(AvailableBlockBuilder.createBlock("20080725-1530", "20080725-1600"));
    assertEquals(46, reexpandedBlocks.size());
    // recombining shouldn't change the size; we're just trimming the length of the last large block
    assertEquals(4, AvailableBlockBuilder.combine(reexpandedBlocks).size());
}

From source file:org.kuali.kfs.coa.service.impl.ObjectCodeServiceImpl.java

/**
 * @see org.kuali.kfs.coa.service.ObjectCodeService#getObjectCodeNamesByCharts(java.lang.Integer, java.lang.String[],
 *      java.lang.String)/* w  w  w . j  ava 2  s. co m*/
 */
@Override
public String getObjectCodeNamesByCharts(Integer universityFiscalYear, String[] chartOfAccountCodes,
        String financialObjectCode) {
    String onlyObjectCodeName = "";
    SortedSet<String> objectCodeNames = new TreeSet<String>();
    List<String> objectCodeNameList = new ArrayList<String>();
    for (String chartOfAccountsCode : chartOfAccountCodes) {
        ObjectCode objCode = this.getByPrimaryId(universityFiscalYear, chartOfAccountsCode,
                financialObjectCode);
        if (objCode != null) {
            onlyObjectCodeName = objCode.getFinancialObjectCodeName();
            objectCodeNames.add(objCode.getFinancialObjectCodeName());
            objectCodeNameList.add(chartOfAccountsCode + ": " + objCode.getFinancialObjectCodeName());
        } else {
            onlyObjectCodeName = "Not Found";
            objectCodeNameList.add(chartOfAccountsCode + ": Not Found");
        }
    }
    if (objectCodeNames.size() > 1) {
        return StringUtils.join(objectCodeNames.toArray(), ", ");
    } else {
        return onlyObjectCodeName;
    }
}