Example usage for java.util SortedMap isEmpty

List of usage examples for java.util SortedMap isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:org.languagetool.rules.spelling.suggestions.SuggestionsChanges.java

private List<Map<String, Object>> gridsearch(SortedMap<String, List<Object>> grid,
        List<Map<String, Object>> current) {
    if (grid.isEmpty()) { // recursion exit
        return current;
    }// ww w.ja  va2 s.  c  o  m

    String name = grid.lastKey();
    List<Object> params = grid.get(name);
    List<Map<String, Object>> result = new LinkedList<>();

    if (current.isEmpty()) {
        for (Object value : params) {
            result.add(Collections.singletonMap(name, value));
        }
    } else {
        for (Map<String, Object> entry : current) {
            for (Object value : params) {
                Map<String, Object> modified = new HashMap<>(entry);
                modified.put(name, value);
                result.add(modified);
            }
        }
    }

    return gridsearch(grid.headMap(name), result);
}

From source file:org.uncommons.reportng.HTMLReporter.java

/**
 * Generate a groups list for each suite.
 * @param outputDirectory The target directory for the generated file(s).
 *//*w w  w  .  ja v a  2 s.  c o  m*/
private void createGroups(List<ISuite> suites, File outputDirectory) throws Exception {
    int index = 1;
    for (ISuite suite : suites) {
        SortedMap<String, SortedSet<ITestNGMethod>> groups = sortGroups(suite.getMethodsByGroups());
        if (!groups.isEmpty()) {
            VelocityContext context = createContext();
            context.put(SUITE_KEY, suite);
            context.put(GROUPS_KEY, groups);
            String fileName = String.format("suite%d_%s", index, GROUPS_FILE);
            generateFile(new File(outputDirectory, fileName), GROUPS_FILE + TEMPLATE_EXTENSION, context);
        }
        ++index;
    }
}

From source file:org.apache.metron.common.stellar.shell.StellarExecutor.java

public Iterable<String> autoComplete(String buffer, final OperationType opType) {
    indexLock.readLock().lock();//from w  ww  .  j  av a 2s  .c o  m
    try {
        SortedMap<String, AutoCompleteType> ret = autocompleteIndex.prefixMap(buffer);
        if (ret.isEmpty()) {
            return new ArrayList<>();
        }
        return Iterables.transform(ret.entrySet(), kv -> kv.getValue().transform(opType, kv.getKey()));
    } finally {
        indexLock.readLock().unlock();
    }
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcLoadRecordWriter.java

@Override
public List<OnRecordErrorException> writeBatch(Iterator<Record> recordIterator) throws StageException {
    final List<OnRecordErrorException> errorRecords = new LinkedList<>();
    if (!recordIterator.hasNext()) {
        return errorRecords;
    }//from w  w  w .ja v  a2  s  .  c  o  m

    // Assume all records have the same columns.
    final Record first = recordIterator.next();
    SortedMap<String, String> columnsToParameters = recordReader.getColumnsToParameters(first,
            OperationType.LOAD_CODE, getColumnsToParameters(), getColumnsToFields());
    if (columnsToParameters.isEmpty()) {
        throw new StageException(JdbcErrors.JDBC_22);
    }

    final Set<String> columnNames = columnsToParameters.keySet();
    final String loadSql = "LOAD DATA LOCAL INFILE '' " + duplicateKeyAction.getKeyword() + " INTO TABLE "
            + getTableName() + " (" + Joiner.on(", ").join(columnNames) + ")";
    try (Connection connection = getDataSource().getConnection()) {
        Connection conn = connection.unwrap(Connection.class);
        try (PreparedStatement statement = conn.prepareStatement(loadSql)) {
            PipedInputStream is = new PipedInputStream();
            PipedOutputStream os = new PipedOutputStream(is);
            statement.getClass().getMethod("setLocalInfileInputStream", InputStream.class).invoke(statement,
                    is);

            Future<?> future = loadOutputExecutor.submit(() -> {
                try (OutputStreamWriter writer = new OutputStreamWriter(os)) {
                    CSVPrinter printer = new CSVPrinter(writer, CSVFormat.MYSQL);
                    Record record = first;
                    while (record != null) {
                        int opCode = getOperationCode(record, errorRecords);
                        if (opCode == OperationType.LOAD_CODE) {
                            for (String column : columnNames) {
                                Field field = record.get(getColumnsToFields().get(column));
                                printer.print(field.getValue());
                            }
                            printer.println();
                        } else if (opCode > 0) {
                            LOG.debug("Sending record to error due to unsupported operation {}", opCode);
                            errorRecords.add(new OnRecordErrorException(record, JdbcErrors.JDBC_70, opCode));
                        } else {
                            // It should be added to the error records.
                        }
                        record = recordIterator.hasNext() ? recordIterator.next() : null;
                    }
                    ;
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });

            if (LOG.isDebugEnabled()) {
                LOG.debug("Executing query: {}", statement.toString());
            }
            statement.execute();
            future.get();
        }
        connection.commit();
    } catch (SQLException e) {
        handleSqlException(e);
    } catch (Exception e) {
        throw new StageException(JdbcErrors.JDBC_14, e.getMessage(), e);
    }
    return errorRecords;
}

From source file:gridool.routing.strategy.ConsistentHash.java

public List<GridNode> listSuccessorsInPhysicalChain(@Nonnull final GridNode node, final int maxNodesToSelect,
        final boolean exclusive) {
    int numToGets = Math.min(maxNodesToSelect, liveNodes.size());
    final List<GridNode> retNodes = new ArrayList<GridNode>(numToGets);
    int accquired = 0;

    final SortedMap<GridNode, GridNode> tailMap = liveNodes.tailMap(node);
    final boolean noTail = tailMap.isEmpty();
    if (!noTail) {// has tail
        final Iterator<GridNode> tail = tailMap.values().iterator();
        if (exclusive) {
            assert (tail.hasNext());
            tail.next(); // skip
        }//from w w  w  . j a v  a 2 s. c o  m
        for (; tail.hasNext() && accquired < numToGets; accquired++) {
            GridNode n = tail.next();
            retNodes.add(n);
        }
    }
    if (accquired < numToGets) {
        final Iterator<GridNode> head = liveNodes.values().iterator();
        if (exclusive && noTail) {
            assert (head.hasNext());
            head.next(); // skip
        }
        for (; head.hasNext() && accquired < numToGets; accquired++) {
            GridNode n = head.next();
            retNodes.add(n);
        }
    }
    return retNodes;
}

From source file:gridool.routing.strategy.ConsistentHash.java

public List<GridNode> listSuccessorsInVirtualChain(@Nonnull final byte[] fromKey, final int maxNodesToSelect,
        final boolean exclusive) {
    if (circle.isEmpty()) {
        return Collections.emptyList();
    }/* w w w  .  j a  v a  2  s . c  o m*/
    int numToGets = Math.min(maxNodesToSelect, liveNodes.size());
    final List<GridNode> retNodes = new ArrayList<GridNode>(numToGets);
    int accquired = 0;

    final Long hash = hashFunction.hash(fromKey);

    if (exclusive && LOG.isWarnEnabled()) {
        if (!circle.containsKey(hash)) {
            LOG.warn("Routing table does not have a required node");
        }
    }

    final SortedMap<Long, GridNode> tailMap = circle.tailMap(hash);
    final boolean noTail = tailMap.isEmpty();
    if (!noTail) {
        final Iterator<GridNode> tail = tailMap.values().iterator();
        if (exclusive) {
            assert (tail.hasNext());
            tail.next(); // skip
        }
        for (; tail.hasNext() && accquired < numToGets;) {
            GridNode n = tail.next();
            if (!retNodes.contains(n)) {
                retNodes.add(n);
                accquired++;
            }
        }
    }
    if (accquired < numToGets) {
        final Iterator<GridNode> head = circle.values().iterator();
        if (exclusive && noTail) {
            assert (head.hasNext());
            head.next(); // skip
        }
        for (; head.hasNext() && accquired < numToGets;) {
            GridNode n = head.next();
            if (!retNodes.contains(n)) {
                retNodes.add(n);
                accquired++;
            }
        }
    }
    return retNodes;
}

From source file:org.kalypso.gml.ui.internal.coverage.CoverageColormapHandler.java

public void guessInitialColormap(final Shell shell, final ICoverage[] coverages) {
    final RasterSymbolizer symb = getRasterSymbolizer();
    if (symb == null)
        return;/*from   w w w .  j  a  v  a  2  s.c  o m*/

    final SortedMap<Double, ColorMapEntry> colorMap = symb.getColorMap();
    if (!colorMap.isEmpty())
        return;

    try {
        /* In order to show anything to the user, create a default color map, if no colors have been defined yet */
        final Range<Double> minMax = ElevationUtilities.calculateRange(coverages);
        final Double min = minMax.getMinimum();
        final Double max = minMax.getMaximum();

        // TODO: check for infinity
        if (Doubles.isNullOrInfinite(min, max))
            return;

        // TODO: find better step...
        final BigDecimal stepWidth = new BigDecimal("0.1"); //$NON-NLS-1$
        final Color fromColor = new Color(0, 255, 0, 200);
        final Color toColor = new Color(255, 0, 0, 200);

        // TODO: scale?! -> get max scale from all coverages
        final BigDecimal minDecimal = new BigDecimal(min);
        final BigDecimal maxDecimal = new BigDecimal(max);

        final ColorMapEntry[] colors = SldHelper.createColorMap(fromColor, toColor, stepWidth, minDecimal,
                maxDecimal, 250);
        updateRasterSymbolizer(shell, colors);
    } catch (final CoreException e) {
        // will not happen, as we do not define a class limit in createColorMap
    }
}

From source file:co.rsk.remasc.RemascStorageProviderTest.java

@Test
public void getDefaultSiblings() {
    String accountAddress = randomAddress();
    Repository repository = new RepositoryImpl();

    RemascStorageProvider provider = new RemascStorageProvider(repository, accountAddress);

    SortedMap<Long, List<Sibling>> map = provider.getSiblings();

    Assert.assertNotNull(map);/*  www  . j  a v  a2  s.c om*/
    Assert.assertTrue(map.isEmpty());
}

From source file:com.maxpowered.amazon.advertising.api.SignedRequestsHelper.java

/**
 * Canonicalize the query string as required by Amazon.
 *
 * @param sortedParamMap/*from  ww w. ja va 2 s. c  o m*/
 *            Parameter name-value pairs in lexicographical order.
 * @return Canonical form of query string.
 */
private String canonicalize(final SortedMap<String, String> sortedParamMap) {
    if (sortedParamMap.isEmpty()) {
        return "";
    }

    final StringBuffer buffer = new StringBuffer();
    final Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator();

    while (iter.hasNext()) {
        final Map.Entry<String, String> kvpair = iter.next();
        buffer.append(percentEncodeRfc3986(kvpair.getKey()));
        buffer.append("=");
        buffer.append(percentEncodeRfc3986(kvpair.getValue()));
        if (iter.hasNext()) {
            buffer.append("&");
        }
    }
    final String cannoical = buffer.toString();
    return cannoical;
}

From source file:uk.org.sappho.applications.transcript.service.registry.WorkingCopy.java

public void putProperties(String environment, String application, SortedMap<String, Object> properties,
        boolean isMerge) throws TranscriptException {

    Gson gson = new Gson();
    synchronized (getLock()) {
        SortedMap<String, Object> oldProperties = getJsonProperties(environment, application);
        SortedMap<String, Object> newProperties;
        if (isMerge && !oldProperties.isEmpty()) {
            newProperties = new TreeMap<String, Object>();
            for (String key : oldProperties.keySet()) {
                newProperties.put(key, oldProperties.get(key));
            }/*from w  w  w  . j  a  va 2s.c o  m*/
            for (String key : properties.keySet()) {
                Object newValue = properties.get(key);
                if (transcriptParameters.isFailOnValueChange() && oldProperties.containsKey(key)
                        && !gson.toJson(newValue).equals(gson.toJson(oldProperties.get(key)))) {
                    throw new TranscriptException("Value of property " + environment + ":" + application + ":"
                            + key + " would change");
                }
                newProperties.put(key, newValue);
            }
        } else {
            newProperties = properties;
        }
        String oldJson = gson.toJson(oldProperties);
        String newJson = gson.toJson(newProperties);
        if (!newJson.equals(oldJson)) {
            putProperties(environment, application, newProperties);
        }
    }
}