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:org.apilytic.currency.mvc.controller.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *//*  w  w w . j av  a2 s . 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;
    }

    try {
        rateIngestionService.syncCountryCurrenciesAndRates();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    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:org.apache.accumulo.test.randomwalk.concurrent.Config.java

private void changeNamespaceSetting(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> namespaces = env.getConnector().namespaceOperations().list().tailSet("nspc")
            .headSet("nspd");
    if (namespaces.isEmpty())
        return;/* w  w  w.  j av  a  2 s .  c  o m*/
    String namespace = random.nextSample(namespaces, 1)[0].toString();

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

From source file:io.wcm.devops.conga.tooling.maven.plugin.DefinitionPackageMojo.java

private void copyDefinitions(ResourceCollection sourceDir, File rootOutputDir, File parentTargetDir,
        String dirName) throws IOException {
    if (!sourceDir.exists()) {
        return;/*from  w  w  w .  ja  v  a  2 s. co  m*/
    }
    SortedSet<Resource> files = sourceDir.getResources();
    SortedSet<ResourceCollection> dirs = sourceDir.getResourceCollections();
    if (files.isEmpty() && dirs.isEmpty()) {
        return;
    }

    File targetDir = new File(parentTargetDir, dirName);
    if (!targetDir.exists()) {
        targetDir.mkdirs();
    }

    for (Resource file : files) {
        File targetFile = new File(targetDir, file.getName());

        getLog().info("Include " + getPathForLog(rootOutputDir, targetFile));

        if (targetFile.exists()) {
            targetFile.delete();
        }
        try (InputStream is = file.getInputStream()) {
            byte[] data = IOUtils.toByteArray(is);
            FileUtils.writeByteArrayToFile(targetFile, data);
        }
    }

    for (ResourceCollection dir : dirs) {
        copyDefinitions(dir, rootOutputDir, targetDir, dir.getName());
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.freemarker.loader.FreemarkerTemplateLoader.java

/**
 * Get the best template for this name. Walk the tree finding all possible
 * matches, then choose our favorite./*w ww.ja  va2s  .c  o m*/
 */
@Override
public Object findTemplateSource(String name) throws IOException {
    if (StringUtils.isBlank(name)) {
        return null;
    }

    SortedSet<PathPieces> matches = findAllMatches(new PathPieces(name));

    if (matches.isEmpty()) {
        return null;
    } else {
        return matches.last().path.toFile();
    }
}

From source file:gov.nih.nci.firebird.service.registration.CvPdfGenerator.java

private void addCertifications(int index) throws DocumentException {
    PdfPTable table = createTable(THREE_COLUMNS);
    addCertificationHeadings(table, index);
    SortedSet<AbstractCredential<?>> credentials = getProfile()
            .getCurrentCredentials(CredentialType.CERTIFICATION);
    if (credentials.isEmpty()) {
        addCellAndCompleteRow(table, getValueNone());
    } else {//from  ww w .  ja va  2  s. c om
        addCertifications(table, credentials);
    }
    getDocument().add(table);
}

From source file:org.tonguetied.keywordmanagement.KeywordRepositoryImpl.java

/**
 * Create the search criteria for a {@link Translation}.
 * /*from w w w.j av  a2  s.  co m*/
 * @param translations the translation to add to the criteria
 * @param ignoreCase flag indicating if case should be ignored during search
 * @param matchMode flag indicating the type of string pattern matching
 * @return the additional search parameters for the {@link Translation}
 * fields
 */
private Conjunction createTranslationConditions(SortedSet<Translation> translations, final boolean ignoreCase,
        final MatchMode matchMode) {
    Conjunction conjunction = null;
    if (translations != null && !translations.isEmpty()) {
        final Translation translation = translations.first();

        Example criterionTranslation = Example.create(translation);
        criterionTranslation.enableLike(matchMode);
        if (ignoreCase) {
            criterionTranslation.ignoreCase();
        }

        conjunction = conjunction();
        conjunction.add(criterionTranslation);

        addBundleCriteria(conjunction, translation.getBundle());
        addCountryCriteria(conjunction, translation.getCountry());
        addLanguageCriteria(conjunction, translation.getLanguage());
    }

    return conjunction;
}

From source file:org.springframework.web.reactive.resource.CssLinkResourceTransformer.java

private List<ContentChunkInfo> parseContent(String cssContent) {
    SortedSet<ContentChunkInfo> links = new TreeSet<>();
    this.linkParsers.forEach(parser -> parser.parse(cssContent, links));
    if (links.isEmpty()) {
        return Collections.emptyList();
    }/*from  w ww  .  j a  v  a 2  s.c  o m*/
    int index = 0;
    List<ContentChunkInfo> result = new ArrayList<>();
    for (ContentChunkInfo link : links) {
        result.add(new ContentChunkInfo(index, link.getStart(), false));
        result.add(link);
        index = link.getEnd();
    }
    if (index < cssContent.length()) {
        result.add(new ContentChunkInfo(index, cssContent.length(), false));
    }
    return result;
}

From source file:hu.ppke.itk.nlpg.purepos.decoder.BeamedViterbi.java

private List<Pair<List<Integer>, Double>> findMax(final HashMap<NGram<Integer>, Node> beam, int resultsNumber) {

    // Node max = Collections.max(beam.values());
    // Node act = max;
    // return decompose(max);

    SortedSet<Node> sortedKeys = new TreeSet<Node>(beam.values());

    List<Pair<List<Integer>, Double>> ret = new ArrayList<Pair<List<Integer>, Double>>();
    Node max;/*from w  w w. j  a va2  s  .  c  o  m*/
    for (int i = 0; i < resultsNumber && !sortedKeys.isEmpty(); ++i) {
        max = sortedKeys.last();
        sortedKeys.remove(max);
        List<Integer> maxTagSeq = decompose(max);
        ret.add(Pair.of(maxTagSeq, max.weight));
    }
    return ret;

}

From source file:org.libreplan.web.expensesheet.ExpenseSheetModel.java

private Resource initResource() {
    if (expenseSheet.isNotPersonal())
        return null;

    SortedSet<ExpenseSheetLine> expenseSheetLines = expenseSheet.getExpenseSheetLines();

    if (!expenseSheetLines.isEmpty())
        return expenseSheetLines.iterator().next().getResource();

    User user = UserUtil.getUserFromSession();

    return user.isBound() ? user.getWorker() : null;
}

From source file:uk.org.taverna.platform.report.StatusReport.java

/**
 * Get an invocation with a given name.//w  w  w  .  j av a  2s.c  o m
 * @param invocationName
 * @return
 */
public Invocation getInvocation(String invocationName) {
    NavigableSet<Invocation> invocs = getInvocations();
    // A Comparable Invocation with the desired name
    SortedSet<Invocation> tailSet = invocs.tailSet(new Invocation(invocationName));
    if (!tailSet.isEmpty())
        return tailSet.first();
    return null;
}