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:Main.java

public static <T> T findLastItemAtPosition(SortedSet<T> queryResult, int itemPosition) {
    if (queryResult == null || queryResult.isEmpty())
        throw new IllegalArgumentException("Provided result set is 'null' or empty.");

    Iterator<T> resultSetIterator = queryResult.iterator();
    int nbItemInList = 0;
    T lastItem = null;//from  ww  w .  j  a  va  2  s  .c o m
    while (resultSetIterator.hasNext() && nbItemInList++ < itemPosition)
        lastItem = resultSetIterator.next();
    return lastItem;
}

From source file:Main.java

public static <T> T findLastItem(SortedSet<T> queryResult, int lastItemPosition) {
    if (queryResult == null || queryResult.isEmpty())
        throw new IllegalArgumentException("Provided result set is 'null' or empty.");

    Iterator<T> resultSetIterator = queryResult.iterator();
    int nbItemInList = 0;
    T lastItem = null;/*  ww  w .j  av a  2  s.co  m*/
    while (resultSetIterator.hasNext() && nbItemInList++ < lastItemPosition)
        lastItem = resultSetIterator.next();
    return lastItem;
}

From source file:org.archive.util.PrefixFinder.java

private static String last(SortedSet<String> set) {
    return set.isEmpty() ? null : set.last();
}

From source file:com.cyberway.issue.net.PublicSuffixes.java

protected static void buildRegex(String stem, StringBuilder regex, SortedSet<String> prefixes) {
    if (prefixes.isEmpty()) {
        return;//from   www .  ja v  a2s  .c om
    }
    if (prefixes.size() == 1 && prefixes.first().equals(stem)) {
        // avoid unnecessary "(?:)"
        return;
    }
    regex.append("(?:");
    if (stem.length() == 0) {
        regex.append("\n "); // linebreak-space before first character
    }
    Iterator<String> iter = prefixes.iterator();
    char c = 0;
    while (iter.hasNext()) {
        String s = iter.next();
        if (s.length() > stem.length()) {
            char d = s.charAt(stem.length());

            if (d == '+') {
                // convert exception to zero-width-positive-lookahead
                regex.append("(?=" + s.substring(stem.length() + 1) + ")");
            } else {
                if (d == c) {
                    continue;
                }
                c = d;
                regex.append(c);
                String newStem = s.substring(0, stem.length() + 1);
                SortedSet<String> tail = prefixes.tailSet(newStem);
                SortedSet<String> range = null;
                successor: for (String candidate : tail) {
                    if (!candidate.equals(newStem)) {
                        range = prefixes.subSet(s, candidate);
                        break successor;
                    }
                }
                if (range == null) {
                    range = prefixes.tailSet(s);
                }
                buildRegex(newStem, regex, range);
            }
            regex.append('|');
        } else {
            // empty suffix; insert dummy to be eaten when loop exits
            regex.append('@');
        }
    }
    // eat the trailing '|' (if no empty '@') or dummy
    regex.deleteCharAt(regex.length() - 1);
    regex.append(')');
    if (stem.length() == 1) {
        regex.append('\n'); // linebreak for TLDs
    }
}

From source file:io.wcm.devops.conga.plugins.sling.util.ProvisioningUtil.java

/**
 * Get the relative path for a configuration
 *///from   www .  j a v  a2s.  c  o  m
private static String getPathForConfiguration(Configuration configuration, RunMode runMode) {
    SortedSet<String> runModesList = new TreeSet<>();
    if (runMode.getNames() != null) {
        runModesList.addAll(ImmutableList.copyOf(runMode.getNames()));
    }

    // run modes directory
    StringBuilder path = new StringBuilder();
    if (!runModesList.isEmpty() && !runMode.isSpecial()) {
        path.append(StringUtils.join(runModesList, ".")).append("/");
    }

    // main name
    if (configuration.getFactoryPid() != null) {
        path.append(configuration.getFactoryPid()).append("-");
    }
    path.append(configuration.getPid()).append(".config");

    return path.toString();
}

From source file:com.espertech.esper.schedule.ScheduleComputeHelper.java

private static int nextValue(SortedSet<Integer> valueSet, int startValue) {
    if (valueSet == null) {
        return startValue;
    }/*  www.  ja v a2  s. com*/

    if (valueSet.contains(startValue)) {
        return startValue;
    }

    SortedSet<Integer> tailSet = valueSet.tailSet(startValue + 1);

    if (tailSet.isEmpty()) {
        return -1;
    } else {
        return tailSet.first();
    }
}

From source file:org.ardverk.gibson.EventUtils.java

public static Set<String> keywords(Event event) {
    if (event == null) {
        throw new NullPointerException("event");
    }// www .  j  a va  2s.  c  o m

    SortedSet<String> keywords = new TreeSet<String>();

    String message = event.getMessage();
    if (message != null) {
        keywords(message, keywords);
    }

    Condition condition = event.getCondition();
    if (condition != null) {
        keywords(condition, keywords);
    }

    String marker = event.getMarker();
    if (marker != null) {
        keywords(marker, keywords);
    }

    if (keywords.isEmpty()) {
        return null;
    }

    return keywords;
}

From source file:gov.nih.nci.cananolab.util.StringUtils.java

public static String sortJoin(Collection<String> strings, String delimiter) {
    SortedSet<SortableName> sortableNames = new TreeSet<SortableName>();
    for (String str : strings) {
        sortableNames.add(new SortableName(str));
    }/*  www. ja v  a2  s  .  c  o m*/
    String joinedStr = "";
    if (sortableNames == null || sortableNames.isEmpty()) {
        return joinedStr;
    }
    StringBuilder sb = new StringBuilder();
    int i = 0;
    for (SortableName sortableName : sortableNames) {
        if (i < sortableNames.size() - 1) {
            if (!StringUtils.isEmpty(sortableName.getName()))
                // joinedStr += sortableName.getName() + delimiter;
                sb.append(sortableName.getName());
            sb.append(delimiter);
        } else {
            if (!StringUtils.isEmpty(sortableName.getName()))
                // joinedStr += sortableName.getName();
                sb.append(sortableName.getName());
        }
        i++;
    }
    joinedStr = sb.toString();
    return joinedStr;
}

From source file:net.sf.json.test.JSONAssert.java

private static String missingExpectedNames(JSONObject expected, JSONObject actual) {
    SortedSet keysInExpectedButNotInActual = new TreeSet(expected.keySet());
    keysInExpectedButNotInActual.removeAll(actual.keySet());
    if (keysInExpectedButNotInActual.isEmpty()) {
        return null;
    } else {/*from  www .j  a  va  2s  .c  o  m*/
        return "missing expected names: [" + StringUtils.join(keysInExpectedButNotInActual, ", ") + "]";
    }
}

From source file:net.sf.json.test.JSONAssert.java

private static String unexpectedNames(JSONObject expected, JSONObject actual) {
    SortedSet keysInActualButNotInExpected = new TreeSet(actual.keySet());
    keysInActualButNotInExpected.removeAll(expected.keySet());
    if (keysInActualButNotInExpected.isEmpty()) {
        return null;
    } else {//  w  w  w .  jav  a 2 s.  co m
        return "unexpected names: [" + StringUtils.join(keysInActualButNotInExpected, ", ") + "]";
    }
}