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:io.wcm.handler.media.format.impl.MediaFormatHandlerImpl.java

/**
 * Detect matching media format.//  w  ww.j a v a 2 s  .  com
 * @param extension File extension
 * @param fileSize File size
 * @param width Image width (or 0 if not image)
 * @param height Image height (or 0 if not image)
 * @return Media format or null if no matching media format found
 */
@Override
public MediaFormat detectMediaFormat(String extension, long fileSize, long width, long height) {
    SortedSet<MediaFormat> matchingFormats = detectMediaFormats(extension, fileSize, width, height);
    return !matchingFormats.isEmpty() ? matchingFormats.first() : null;
}

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

@Override
public Resource transform(HttpServletRequest request, Resource resource,
        ResourceTransformerChain transformerChain) throws IOException {

    resource = transformerChain.transform(request, resource);

    String filename = resource.getFilename();
    if (!"css".equals(StringUtils.getFilenameExtension(filename))
            || resource instanceof GzipResourceResolver.GzippedResource) {
        return resource;
    }//from www. jav  a2  s .  c o m

    if (logger.isTraceEnabled()) {
        logger.trace("Transforming resource: " + resource);
    }

    byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
    String content = new String(bytes, DEFAULT_CHARSET);

    SortedSet<ContentChunkInfo> links = new TreeSet<>();
    for (LinkParser parser : this.linkParsers) {
        parser.parse(content, links);
    }

    if (links.isEmpty()) {
        if (logger.isTraceEnabled()) {
            logger.trace("No links found.");
        }
        return resource;
    }

    int index = 0;
    StringWriter writer = new StringWriter();
    for (ContentChunkInfo linkContentChunkInfo : links) {
        writer.write(content.substring(index, linkContentChunkInfo.getStart()));
        String link = content.substring(linkContentChunkInfo.getStart(), linkContentChunkInfo.getEnd());
        String newLink = null;
        if (!hasScheme(link)) {
            String absolutePath = toAbsolutePath(link, request);
            newLink = resolveUrlPath(absolutePath, request, resource, transformerChain);
        }
        if (logger.isTraceEnabled()) {
            if (newLink != null && !newLink.equals(link)) {
                logger.trace("Link modified: " + newLink + " (original: " + link + ")");
            } else {
                logger.trace("Link not modified: " + link);
            }
        }
        writer.write(newLink != null ? newLink : link);
        index = linkContentChunkInfo.getEnd();
    }
    writer.write(content.substring(index));

    return new TransformedResource(resource, writer.toString().getBytes(DEFAULT_CHARSET));
}

From source file:org.isatools.tablib.export.graph2tab.LayersBuilder.java

/**
 * The first stage of the layering algorithm, layer indexes are computed by walking the graph upstream, i.e.: 
 * layer ( n ) = max ( layer ( in ) ) for each in in {@link Node#getInputs()}. This is the recursive step.   
 * /* w  w w.j  a  v  a2  s.co m*/
 */
private int computeUntypedLayer(Node node) {
    Integer result = node2Layer.get(node);
    if (result != null)
        return result;

    result = -1;
    SortedSet<Node> ins = node.getInputs();

    if (!ins.isEmpty())
        for (Node in : ins) {
            int il = computeUntypedLayer(in);
            if (result < il)
                result = il;
        }

    setLayer(node, ++result);
    return result;
}

From source file:org.apache.hive.ptest.execution.PTest.java

public int run() {
    int result = 0;
    boolean error = false;
    List<String> messages = Lists.newArrayList();
    Map<String, Long> elapsedTimes = Maps.newTreeMap();
    try {//from   w w  w  . ja  v  a  2  s.c o m
        mLogger.info("Running tests with " + mConfiguration);
        mLogger.info("Running tests with configuration context=[{}]", mConfiguration.getContext());
        for (Phase phase : mPhases) {
            String msg = "Executing " + phase.getClass().getName();
            mLogger.info(msg);
            messages.add(msg);
            long start = System.currentTimeMillis();
            try {
                phase.execute();
            } finally {
                long elapsedTime = TimeUnit.MINUTES.convert((System.currentTimeMillis() - start),
                        TimeUnit.MILLISECONDS);
                elapsedTimes.put(phase.getClass().getSimpleName(), elapsedTime);
            }
        }
        if (!mFailedTests.isEmpty()) {
            throw new TestsFailedException(mFailedTests.size() + " tests failed");
        }
    } catch (Throwable throwable) {
        mLogger.error("Test run exited with an unexpected error", throwable);
        // NonZeroExitCodeExceptions can have long messages and should be
        // trimmable when published to the JIRA via the JiraService
        if (throwable instanceof NonZeroExitCodeException) {
            messages.add("Tests exited with: " + throwable.getClass().getSimpleName());
            for (String line : Strings.nullToEmpty(throwable.getMessage()).split("\n")) {
                messages.add(line);
            }
        } else {
            messages.add("Tests exited with: " + throwable.getClass().getSimpleName() + ": "
                    + throwable.getMessage());
        }
        error = true;
    } finally {
        for (HostExecutor hostExecutor : mHostExecutors) {
            hostExecutor.shutdownNow();
            if (hostExecutor.isBad()) {
                mExecutionContext.addBadHost(hostExecutor.getHost());
            }
        }
        mSshCommandExecutor.shutdownNow();
        mRsyncCommandExecutor.shutdownNow();
        mExecutor.shutdownNow();
        SortedSet<String> failedTests = new TreeSet<String>(mFailedTests);
        if (failedTests.isEmpty()) {
            mLogger.info(String.format("%d failed tests", failedTests.size()));
        } else {
            mLogger.warn(String.format("%d failed tests", failedTests.size()));
        }
        for (String failingTestName : failedTests) {
            mLogger.warn(failingTestName);
        }
        mLogger.info("Executed " + mExecutedTests.size() + " tests");
        for (Map.Entry<String, Long> entry : elapsedTimes.entrySet()) {
            mLogger.info(String.format("PERF: Phase %s took %d minutes", entry.getKey(), entry.getValue()));
        }
        publishJiraComment(error, messages, failedTests, mAddedTests);
        if (error || !mFailedTests.isEmpty()) {
            result = 1;
        }
    }
    return result;
}

From source file:org.isatools.tablib.export.graph2tab.LayersBuilder.java

/**
 * The minimal order on the left side of the node. That is: 
 * <ul>//  w ww  . j a  v  a 2s.c  o m
 *   <li>l0 = min ( nl.getOrder() != -1 and for all nl in m:layer(m) = layer(n) - 1)</li>
 *   <li>if no node with order != -1 exist on the immediate left, layer(n) - 2,3,4... are evaluated the same way, 
 *   the final result is -1 if we reach the leftmost side of the graph</li>
 * </ul>
 * 
 * This means that we seek for the node having a significant order that is closer to the current node, if no such 
 * node exists, we signal that by returning -1 (proper decisions are taken in {@link #computeTypedLayers()} in 
 * such cases, see there).
 *   
 */
private int minOrderLeft(int layer) {
    while (--layer >= 0) {
        SortedSet<Node> lNodes = layer2Nodes.get(layer);
        if (!lNodes.isEmpty()) {
            int lno = lNodes.first().getOrder();
            // Ignore "doesn't matter" nodes
            if (lno > -1)
                return lno;
        }
    }
    return -1;
}

From source file:eu.ggnet.dwoss.stock.CommissioningManagerView.java

private void detailButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detailButtonActionPerformed
    StringBuilder sb = new StringBuilder("Noch nicht erfasst: ").append(SystemUtils.LINE_SEPARATOR)
            .append(SystemUtils.LINE_SEPARATOR);
    SortedSet<String> missing = model.getMissingRefurbishedIds();
    if (missing.isEmpty()) {
        sb.append("Alle Gert sind erfasst.");
    } else {/*ww w .j  ava 2  s .  co m*/
        for (String line : missing) {
            sb.append(" - ").append(line).append(SystemUtils.LINE_SEPARATOR);
        }
    }
    JOptionPane.showMessageDialog(this, sb.toString());
}

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

/**
 * @param searchTerm//w w  w  . ja v  a 2  s . c om
 *            template we are looking for
 * @param expectedHowMany
 *            How many matches do we expect?
 * @param expectedBestFit
 *            What should the best match turn out to be?
 * @throws IOException
 */
private void assertMatches(String searchTerm, int expectedHowMany, String expectedBestFitString) {
    Path expectedBestFit = (expectedBestFitString == null) ? null : Paths.get(expectedBestFitString);

    SortedSet<PathPieces> matches = runTheVisitor(searchTerm);
    int actualHowMany = matches.size();
    Path actualBestFit = matches.isEmpty() ? null : matches.last().path;

    if (expectedHowMany != actualHowMany) {
        fail("How many results: expected " + expectedHowMany + ", but was  " + actualHowMany + ": " + matches);
    }
    assertEquals("Best result", expectedBestFit, actualBestFit);
}

From source file:org.isatools.tablib.export.graph2tab.LayersBuilder.java

/**
 * Computes the minimal order on the right side of the node, using the same approach described in 
 * {@link #minOrderLeft(Node)}. /*from   w w w.j  a  v  a  2 s  .  co  m*/
 * 
 */
private int minOrderRight(int layer) {
    while (++layer <= maxLayer) {
        SortedSet<Node> rNodes = layer2Nodes.get(layer);
        if (!rNodes.isEmpty()) {
            int result = -1;
            for (Node rnode : rNodes) {
                int ro = rnode.getOrder();
                // Ignore "doesn't matter" nodes and keep searching until you find "good" nodes
                if (ro < 0)
                    continue;
                if (result == -1 || ro < result)
                    result = ro;
            }
            // Ignore "doesn't matter" nodes and keep going right until you find "good" nodes
            if (result > -1)
                return result;
        }
    }
    return -1;
}

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

/**
 * Try for exact match, then pare down if needed, just like Freemarker
 * would.//from w  w w  .j a va2  s.c  om
 */
private void assertFM(String searchTerm, int expectedNumberOfTries, String expectedBestString) {
    Path expectedBestFit = expectedBestString == null ? null : Paths.get(expectedBestString);
    PathPieces stPp = new PathPieces(searchTerm);

    int actualNumberOfTries = 0;
    Path actualBestFit = null;

    if (StringUtils.isNotBlank(stPp.region)) {
        actualNumberOfTries++;
        SortedSet<PathPieces> matches = runTheVisitor(stPp.base + stPp.language + stPp.region + stPp.extension);
        if (!matches.isEmpty()) {
            actualBestFit = matches.last().path;
        }
    }
    if (actualBestFit == null && StringUtils.isNotBlank(stPp.language)) {
        actualNumberOfTries++;
        SortedSet<PathPieces> matches = runTheVisitor(stPp.base + stPp.language + stPp.extension);
        if (!matches.isEmpty()) {
            actualBestFit = matches.last().path;
        }
    }
    if (actualBestFit == null) {
        actualNumberOfTries++;
        SortedSet<PathPieces> matches = runTheVisitor(stPp.base + stPp.extension);
        if (!matches.isEmpty()) {
            actualBestFit = matches.last().path;
        }
    }

    assertEquals("How many tries", expectedNumberOfTries, actualNumberOfTries);
    assertEquals("best fit", expectedBestFit, actualBestFit);
}

From source file:co.rsk.peg.BridgeStorageProviderTest.java

@Test
public void createInstance() throws IOException {
    Repository repository = new RepositoryImpl();
    BridgeStorageProvider provider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR);

    SortedSet<Sha256Hash> processed = provider.getBtcTxHashesAlreadyProcessed();

    Assert.assertNotNull(processed);//from  w w w .  j  av  a2  s.  c om
    Assert.assertTrue(processed.isEmpty());

    SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> broadcasting = provider.getRskTxsWaitingForBroadcasting();

    Assert.assertNotNull(broadcasting);
    Assert.assertTrue(broadcasting.isEmpty());

    SortedMap<Sha3Hash, BtcTransaction> confirmations = provider.getRskTxsWaitingForConfirmations();

    Assert.assertNotNull(confirmations);
    Assert.assertTrue(confirmations.isEmpty());

    SortedMap<Sha3Hash, BtcTransaction> signatures = provider.getRskTxsWaitingForSignatures();

    Assert.assertNotNull(signatures);
    Assert.assertTrue(signatures.isEmpty());

    List<UTXO> utxos = provider.getBtcUTXOs();

    Assert.assertNotNull(utxos);
    Assert.assertTrue(utxos.isEmpty());

    Wallet wallet = provider.getWallet();

    Assert.assertNotNull(wallet);
    Assert.assertNotNull(wallet.getCoinSelector());
}