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:de.science.hack.meshbuilding.MeshBuilder.java

/**
 * Creats a triangle mesh for the wind data.
 *
 * @param data as sorted map./* w  ww .  j a v  a  2 s .  c  o m*/
 * @return
 */
public TriangleMesh build(SortedMap<Float, List<Line>> data) {

    TriangleMesh mesh = new WETriangleMesh();
    if (!data.isEmpty()) {
        StopWatch stopWatch = new StopWatch();

        stopWatch.start();
        addFaces(mesh, pool.invoke(new FacesBuilderTask(data)));
        stopWatch.stop();

        LOG.info("constructed mesh in {} ms", stopWatch);
    }
    return mesh;
}

From source file:com.scraper.SignedRequestsHelper.java

private String canonicalize(SortedMap<String, String> sortedParamMap) {
    if (sortedParamMap.isEmpty()) {
        return "";
    }//from  ww w.jav  a2  s.  c o  m

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

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

From source file:FocusTraversalExample.java

public Component getComponentBefore(Container focusCycleRoot, Component aComponent) {
    if (!(aComponent instanceof JButton)) {
        return null;
    }/*www  .j  a v  a  2 s  .  c  om*/

    SortedMap buttons = getSortedButtons(focusCycleRoot);
    SortedMap prevButtons = // Find all buttons before this one.
            buttons.headMap(((JButton) aComponent).getText());
    if (prevButtons.isEmpty()) { // Wrapped back to end.
        if (!buttons.isEmpty()) {
            return (Component) buttons.get(buttons.lastKey());
        }
        return null; // Degenerate case of no buttons.
    }
    return (Component) prevButtons.get(prevButtons.lastKey());
}

From source file:fr.gael.dhus.util.functional.collect.SortedMapTest.java

/** Constructor: Empty map param. */
@Test/*ww w .j av  a2s .  c om*/
public void emptyMapTest() {
    SortedMap sorted_map = new SortedMap(Collections.emptyMap(), cmp);
    Assert.assertTrue(sorted_map.isEmpty());
    Assert.assertEquals(sorted_map.size(), 0);
    Assert.assertFalse(sorted_map.keySet().iterator().hasNext());
    Assert.assertFalse(sorted_map.values().iterator().hasNext());
    Assert.assertFalse(sorted_map.entrySet().iterator().hasNext());
}

From source file:org.sonar.test.i18n.BundleSynchronizedMatcher.java

private void print(String title, SortedMap<String, String> translations, StringBuilder to) {
    if (!translations.isEmpty()) {
        to.append(title);/*  w  ww  .j  a  v a  2 s  . c om*/
        for (Map.Entry<String, String> entry : translations.entrySet()) {
            to.append("\n").append(entry.getKey()).append("=").append(entry.getValue());
        }
    }
}

From source file:org.archive.crawler.processor.LexicalCrawlMapper.java

/**
 * Look up the crawler node name to which the given CrawlURI 
 * should be mapped. /* w w  w  .j a  v a  2  s  . c o  m*/
 * 
 * @param cauri CrawlURI to consider
 * @return String node name which should handle URI
 */
protected String map(CrawlURI cauri) {
    // get classKey, via frontier to generate if necessary
    String classKey = frontier.getClassKey(cauri);
    SortedMap<String, String> tail = map.tailMap(classKey);
    if (tail.isEmpty()) {
        // wraparound
        tail = map;
    }
    // target node is value of nearest subsequent key
    return (String) tail.get(tail.firstKey());
}

From source file:cherry.goods.telno.TelNoNormalizerImpl.java

private List<Triple<Integer, Integer, Integer>> decompose(String telNo) {
    if (StringUtils.isEmpty(telNo)) {
        return null;
    } else if (telNo.startsWith("0120")) {
        // ??0120
        // 0120-DEF-GHJ
        return asList(Triple.of(4, 3, 3));
    } else if (telNo.startsWith("0800")) {
        // ??0800
        // 0800-DEF-GHJK
        return asList(Triple.of(4, 3, 4));
    } else if (telNo.startsWith("050")) {
        // IP??050
        // 050-CDEF-GHJK
        return asList(Triple.of(3, 4, 4));
    } else if (telNo.startsWith("070")) {
        // ?PHS??070
        // 070-CDEF-GHJK
        return asList(Triple.of(3, 4, 4));
    } else if (telNo.startsWith("080")) {
        // ?PHS??080
        // 080-CDEF-GHJK
        return asList(Triple.of(3, 4, 4));
    } else if (telNo.startsWith("090")) {
        // ?PHS??090
        // 090-CDEF-GHJK
        return asList(Triple.of(3, 4, 4));
    } else if (telNo.startsWith("020")) {
        // ??020//from  w  ww  .j  av a2 s  . co m
        // 020-CDEF-GHJK
        return asList(Triple.of(3, 4, 4));
    } else if (telNo.startsWith("0570")) {
        // ??0570
        // 0570-DEF-GHJ
        return asList(Triple.of(4, 3, 3));
    } else if (telNo.startsWith("0990")) {
        // ???0990
        // 0990-DE-FGHJ
        return asList(Triple.of(4, 2, 4));
    } else {
        // ??
        if (telNo.length() <= 2) {
            return null;
        }
        String prefix = (telNo.length() > 6 ? telNo.substring(0, 6) : telNo);
        SortedMap<String, Integer> map = areaCodeTable.prefixMap(prefix);
        if (map.isEmpty()) {
            return null;
        }
        Set<Integer> set = new TreeSet<>(map.values());
        List<Triple<Integer, Integer, Integer>> list = new ArrayList<>(set.size());
        for (Integer l : set) {
            list.add(Triple.of(l, 6 - l, 4));
        }
        return list;
    }
}

From source file:com.baidubce.auth.BceV1Signer.java

private String getCanonicalHeaders(SortedMap<String, String> headers) {
    if (headers.isEmpty()) {
        return "";
    }/*w w w.  ja  v  a  2s. c om*/

    List<String> headerStrings = Lists.newArrayList();
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        String key = entry.getKey();
        if (key == null) {
            continue;
        }
        String value = entry.getValue();
        if (value == null) {
            value = "";
        }
        headerStrings
                .add(HttpUtils.normalize(key.trim().toLowerCase()) + ':' + HttpUtils.normalize(value.trim()));
    }
    Collections.sort(headerStrings);

    return headerJoiner.join(headerStrings);
}

From source file:org.apache.hadoop.io.compress.CompressionCodecFactory.java

/**
 * Find the relevant compression codec for the given file based on its
 * filename suffix.//ww w  .ja v  a  2  s. c om
 * @param file the filename to check
 * @return the codec object
 */
public CompressionCodec getCodec(Path file) {
    CompressionCodec result = null;
    if (codecs != null) {
        String filename = file.getName();
        String reversedFilename = new StringBuffer(filename).reverse().toString();
        SortedMap<String, CompressionCodec> subMap = codecs.headMap(reversedFilename);
        if (!subMap.isEmpty()) {
            String potentialSuffix = subMap.lastKey();
            if (reversedFilename.startsWith(potentialSuffix)) {
                result = codecs.get(potentialSuffix);
            }
        }
    }
    return result;
}

From source file:io.github.alechenninger.monarch.Main.java

public void run(String[] args) throws ParseException, IOException {
    try {/*from  w  w  w  . ja  va2 s .com*/
        CliInputs cliInputs = CliInputs.parse(args);

        if (cliInputs.helpRequested()) {
            System.out.print(cliInputs.helpMessage());
            return;
        }

        MonarchOptions options = getOptionsFromInputsAndConfigFiles(cliInputs, fileSystem, parsers);

        Path outputDir = options.outputDir().orElseThrow(missingOptionException("output directory"));
        Path dataDir = options.dataDir().orElseThrow(missingOptionException("data directory"));
        Hierarchy hierarchy = options.hierarchy().orElseThrow(missingOptionException("hierarchy"));
        String target = options.target().orElseThrow(missingOptionException("target"));
        Iterable<Change> changes = options.changes();
        Set<String> mergeKeys = options.mergeKeys();

        if (!changes.iterator().hasNext()) {
            System.out.println("No changes provided; formatting target.");
        }

        List<String> affectedSources = hierarchy.hierarchyOf(target).orElseThrow(
                () -> new IllegalArgumentException("Target source not found in hierarchy: " + options.target()))
                .descendants();

        Map<String, Map<String, Object>> currentData = readDataForHierarchy(dataDir, hierarchy);

        Map<String, Map<String, Object>> result = monarch.generateSources(hierarchy, changes, target,
                currentData, mergeKeys);

        for (Map.Entry<String, Map<String, Object>> sourceToData : result.entrySet()) {
            String source = sourceToData.getKey();

            if (!affectedSources.contains(source)) {
                continue;
            }

            Path sourcePath = outputDir.resolve(source);
            ensureParentDirectories(sourcePath);

            SortedMap<String, Object> sorted = new TreeMap<>(sourceToData.getValue());

            if (sorted.isEmpty()) {
                Files.write(sourcePath, new byte[] {});
            } else {
                yaml.dump(sorted, Files.newBufferedWriter(sourcePath, UTF_8));
            }
        }
    } catch (MonarchException | ParseException e) {
        e.printStackTrace();
        System.out.print(CliInputs.parse(new String[0]).helpMessage());
    }
}