Example usage for java.util SortedSet isEmpty

List of usage examples for java.util SortedSet isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:eugene.agent.noise.impl.PlaceOrderBehaviour.java

/**
 * Cancels the oldest working order.//from ww w. ja  v a  2 s  . c om
 */
private void cancel() {
    final SortedSet<OrderReference> orders = session.getOrderReferences();
    if (!orders.isEmpty()) {
        session.send(cancelRequest(orders.first()));
    }
}

From source file:org.sakuli.loader.BaseActionLoaderImpl.java

@Override
public TestCaseStep getCurrentTestCaseStep() {
    if (currentTestCase != null) {
        SortedSet<TestCaseStep> steps = currentTestCase.getStepsAsSortedSet();
        if (!steps.isEmpty()) {
            for (TestCaseStep step : steps) {
                step.refreshState();/*  w ww . j a va  2s . c o  m*/
                //find first step with init state and returns it
                if (!step.getState().isFinishedWithoutErrors()) {
                    return step;
                }
            }
        }
    }
    return null;
}

From source file:org.cloudata.core.commitlog.pipe.BufferPool.java

int clearExpiredEntries(int msec) {
    PoolEntry e = new PoolEntry((System.currentTimeMillis() + 10) - msec);
    int sizeOfDeallocated = 0;

    synchronized (bufferMap) {
        Iterator<TreeSet<PoolEntry>> iter = bufferMap.values().iterator();
        while (iter.hasNext()) {
            TreeSet<PoolEntry> entrySet = iter.next();
            SortedSet<PoolEntry> expiredSet = entrySet.headSet(e);

            if (expiredSet.isEmpty() == false) {
                LOG.debug(expiredSet.size() + " pool entries are removed");
                Iterator<PoolEntry> expiredIter = expiredSet.iterator();

                while (expiredIter.hasNext()) {
                    PoolEntry expiredEntry = expiredIter.next();
                    poolMonitor.deallocated(expiredEntry.buffer.capacity());
                    sizeOfDeallocated += expiredEntry.buffer.capacity();
                }//from ww w. ja v  a 2s.c o  m

                expiredSet.clear();

                if (entrySet.isEmpty()) {
                    LOG.debug("entry set is removed");
                    iter.remove();
                }
            }
        }
    }

    return sizeOfDeallocated;
}

From source file:org.fao.geonet.guiservices.util.GetImportXSLs.java

/**
 * @return a Map with the schema name as key and the import XSL filenames as values.
 *//* w w  w .j  a v a  2 s .c o m*/
private SortedMap<String, SortedSet<String>> getImportXslForSchemas(ServiceContext context) {

    SortedMap<String, SortedSet<String>> ret = new TreeMap<String, SortedSet<String>>();

    GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SchemaManager schemaMan = gc.getSchemamanager();

    for (String schemaName : schemaMan.getSchemas()) {
        String schemaDir = schemaMan.getSchemaDir(schemaName);
        File convertDir = new File(schemaDir, Geonet.Path.CONVERT_STYLESHEETS);
        File importDir = new File(convertDir, "import");

        if (importDir.isDirectory()) {
            Collection<File> files = FileUtils.listFiles(importDir, new String[] { "xsl" }, false);
            SortedSet<String> fileNames = new TreeSet<String>();
            for (File file : files) {
                fileNames.add(file.getName());
            }

            if (!fileNames.isEmpty()) {
                ret.put(schemaName, fileNames);
            }
        }
    }

    return ret;
}

From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java

private void changeTableSetting(RandomData random, State state, Environment env, Properties props)
        throws Exception {
    // pick a random property
    int choice = random.nextInt(0, tableSettings.length - 1);
    Setting setting = tableSettings[choice];

    // pick a random table
    SortedSet<String> tables = env.getConnector().tableOperations().list().tailSet("ctt").headSet("ctu");
    if (tables.isEmpty())
        return;/*from  ww  w. j a  va 2 s . c  om*/
    String table = random.nextSample(tables, 1)[0].toString();

    // generate a random value
    long newValue = random.nextLong(setting.min, setting.max);
    state.set(LAST_TABLE_SETTING, table + "," + choice);
    log.debug("Setting " + setting.property.getKey() + " on table " + table + " to " + newValue);
    try {
        env.getConnector().tableOperations().setProperty(table, setting.property.getKey(), "" + newValue);
    } catch (AccumuloException ex) {
        if (ex.getCause() instanceof ThriftTableOperationException) {
            ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause();
            if (ttoe.type == TableOperationExceptionType.NOTFOUND)
                return;
        }
        throw ex;
    }
}

From source file:sipackage.mvc.controller.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *//* w w w.j  av a  2s  .  co  m*/
@RequestMapping(value = { "/", "/tweets" })
public String home(Model model, @RequestParam(required = false) Long latestTweetId,
        @RequestParam(defaultValue = "DESCENDING", required = false) SortOrder sortOrder) {

    if (latestTweetId == null) {
        latestTweetId = 0L;
    }

    final SortedSet<TwitterMessage> twitterMessages = twitterService.getTwitterMessages(latestTweetId,
            sortOrder);

    TwitterMessages twitterMessagesWrapper = new TwitterMessages();

    if (twitterMessages == null || twitterMessages.isEmpty()) {
        twitterMessagesWrapper.setLatestTweetId(latestTweetId);
    } else {
        twitterMessagesWrapper.setTwitterMessages(twitterMessages);
    }

    twitterMessagesWrapper.setAdapterRunning(twitterService.isTwitterAdapterRunning());

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Latest Tweet ID: '%s'; Adapter running: %s",
                twitterMessagesWrapper.getLatestTweetId(), twitterMessagesWrapper.isAdapterRunning()));
    }

    model.addAttribute("tweets", twitterMessagesWrapper);

    return "home";
}

From source file:jenkins.scm.impl.subversion.SubversionSCMSource.java

/**
 * Groups a set of path segments based on a supplied prefix.
 *
 * @param pathSegments the input path segments.
 * @param prefix       the prefix to group on.
 * @return a map, all keys will {@link #startsWith(java.util.List, java.util.List)} the input prefix and be longer
 *         than the input prefix, all values will {@link #startsWith(java.util.List,
 *         java.util.List)} their corresponding key.
 *//*from w  ww.  jav  a 2 s.  c  o  m*/
@NonNull
static SortedMap<List<String>, SortedSet<List<String>>> groupPaths(
        @NonNull SortedSet<List<String>> pathSegments, @NonNull List<String> prefix) {
    // ensure pre-condition is valid and ensure we are using a copy
    pathSegments = filterPaths(pathSegments, prefix);

    SortedMap<List<String>, SortedSet<List<String>>> result = new TreeMap<List<String>, SortedSet<List<String>>>(
            COMPARATOR);
    while (!pathSegments.isEmpty()) {
        List<String> longestPrefix = null;
        int longestIndex = -1;
        for (List<String> pathSegment : pathSegments) {
            if (longestPrefix == null) {
                longestPrefix = pathSegment;
                longestIndex = indexOfNextWildcard(pathSegment, prefix.size());

            } else {
                int index = indexOfNextWildcard(pathSegment, prefix.size());
                if (index > longestIndex) {
                    longestPrefix = pathSegment;
                    longestIndex = index;
                }
            }
        }
        assert longestPrefix != null;
        longestPrefix = new ArrayList<String>(longestPrefix.subList(0, longestIndex));
        SortedSet<List<String>> group = filterPaths(pathSegments, longestPrefix);
        result.put(longestPrefix, group);
        pathSegments.removeAll(group);
    }
    String optimization;
    while (null != (optimization = getOptimizationPoint(result.keySet(), prefix.size()))) {
        List<String> optimizedPrefix = copyAndAppend(prefix, optimization);
        SortedSet<List<String>> optimizedGroup = new TreeSet<List<String>>(COMPARATOR);
        for (Iterator<Map.Entry<List<String>, SortedSet<List<String>>>> iterator = result.entrySet()
                .iterator(); iterator.hasNext();) {
            Map.Entry<List<String>, SortedSet<List<String>>> entry = iterator.next();
            if (startsWith(entry.getKey(), optimizedPrefix)) {
                iterator.remove();
                optimizedGroup.addAll(entry.getValue());
            }
        }
        result.put(optimizedPrefix, optimizedGroup);
    }
    return result;
}

From source file:org.apache.hadoop.hbase.regionserver.Segment.java

/**
 * Returns the first cell in the segment that has equal or greater key than the given cell
 * @return the first cell in the segment that has equal or greater key than the given cell
 *//*from  ww  w  . ja  v a  2 s .c  om*/
public Cell getFirstAfter(Cell cell) {
    SortedSet<Cell> snTailSet = tailSet(cell);
    if (!snTailSet.isEmpty()) {
        return snTailSet.first();
    }
    return null;
}

From source file:com.doitnext.http.router.DefaultEndpointResolverTest.java

@Test
public void testResolveEndpoints() {

    DefaultEndpointResolver resolver = new DefaultEndpointResolver();
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    resolver.setApplicationContext(applicationContext);
    TestCollectionImpl testCollectionImpl = new TestCollectionImpl();

    when(applicationContext.getBean("testCollection1", TestCollectionImpl.class))
            .thenReturn(testCollectionImpl);

    ResponseHandler errorHandlerJson = mock(ResponseHandler.class);
    ResponseHandler successHandlerJson = mock(ResponseHandler.class);
    MethodInvoker invoker = mock(MethodInvoker.class);
    Map<MethodReturnKey, ResponseHandler> errorHandlers = new HashMap<MethodReturnKey, ResponseHandler>();
    Map<MethodReturnKey, ResponseHandler> successHandlers = new HashMap<MethodReturnKey, ResponseHandler>();

    errorHandlers.put(new MethodReturnKey("", "application/json"), errorHandlerJson);
    errorHandlers.put(new MethodReturnKey("", "text/plain"), errorHandlerJson);
    successHandlers.put(new MethodReturnKey("", "application/json"), successHandlerJson);
    successHandlers.put(new MethodReturnKey("", ""), successHandlerJson);

    resolver.setErrorHandlers(errorHandlers);
    resolver.setSuccessHandlers(successHandlers);
    resolver.setMethodInvoker(invoker);//  w  ww. j a  v  a  2 s  .  co  m

    SortedSet<Route> routes = resolver.resolveEndpoints("/gigi", "com.doitnext.http.router.exampleclasses");

    verify(applicationContext, atLeastOnce()).getBean(eq("testCollection1"), eq(TestCollectionImpl.class));
    Assert.assertNotNull(routes);
    Assert.assertFalse(routes.isEmpty());
}

From source file:org.orbisgis.view.toc.actions.cui.legend.ui.PnlAbstractCategorized.java

/**
 * This method is called by EventHandler when clicking on the button dedicated to classification creation.
 *///from   w ww .  j  a v  a2s .  c o  m
public void onComputeClassification() {
    String name = getFieldName();
    if (thresholds == null || !thresholds.getFieldName().equals(name)) {
        thresholds = computeStats(name);
    }
    ContainerItemProperties selectedItem = (ContainerItemProperties) methodCombo.getSelectedItem();
    CategorizeMethod cm = CategorizeMethod.valueOf(selectedItem.getKey());
    Integer number = (Integer) numberCombo.getSelectedItem();
    SortedSet<Double> set = thresholds.getThresholds(cm, number);
    if (!set.isEmpty()) {
        ColorScheme sc = colorConfig.getColorScheme();
        MappedLegend<Double, U> cl = createColouredClassification(set, new NullProgressMonitor(), sc);
        cl.setLookupFieldName(((MappedLegend) getLegend()).getLookupFieldName());
        cl.setName(getLegend().getName());
        setLegend(cl);
    }
}