Example usage for java.util List isEmpty

List of usage examples for java.util List isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:Main.java

public static <T> boolean retainAllByValue(Collection<T> c1, Collection<? extends T> c2) {
    if (c1 == null || c2 == null || c1.isEmpty() || c2.isEmpty())
        return false;
    List<T> itemsToRemove = new ArrayList<T>();
    for (T item : c1) {
        if (!containsByValue(c2, item))
            itemsToRemove.add(item);/* w w  w .  ja v a 2s.  co  m*/
    }
    c1.removeAll(itemsToRemove);
    return (!itemsToRemove.isEmpty());
}

From source file:com.comphenix.xp.parser.Utility.java

public static String formatBoolean(String booleanName, List<Boolean> value) {
    // Mirror the query syntax
    if (value == null || value.isEmpty() || value.contains(null))
        return "";
    else//w  ww.  j  av  a  2 s . c om
        return value.get(0) ? booleanName : "!" + booleanName;
}

From source file:com.qubit.solution.fenixedu.integration.cgd.webservices.messages.CgdMessageUtils.java

public static Person readPersonByMemberCode(String populationCode, String memberCode) {
    Person requestedPerson = null;/*from w w w  . j a va  2  s .  c  o m*/
    if (!StringUtils.isEmpty(memberCode) && !StringUtils.isEmpty(populationCode)) {
        switch (populationCode.charAt(0)) {
        case 'A':
            Student student = null;

            try {
                int number = Integer.parseInt(memberCode);
                student = Student.readStudentByNumber(number);
            } catch (Exception e) {
                logger.warn(String.format("Invalid student number: [%s]", memberCode));
            }

            if (student != null) {
                requestedPerson = student.getPerson();
            }
        case 'E':
            // NOT YET IMPLEMENTED
            break;
        case 'D':
            List<Teacher> readByNumbers = Teacher.readByNumbers(Collections.singleton(memberCode));
            Teacher teacher = readByNumbers.isEmpty() ? null : readByNumbers.iterator().next();
            if (teacher != null) {
                requestedPerson = teacher.getPerson();
            }
        }
    }
    return requestedPerson;
}

From source file:com.jeklsoft.cassandraclient.hector.HectorTest.java

public static me.prettyprint.hector.api.Keyspace configureHectorAccessToCassandra(String cassandraHostname,
        Integer cassandraPort, String cassandraClusterName, String cassandraKeySpaceName,
        String configurationPath, List<String> cassandraCommands) throws Exception {

    try {/* www  .  j av  a2 s . c o m*/
        if (StringUtils.isNotEmpty(configurationPath) && (cassandraCommands != null)
                && (!cassandraCommands.isEmpty())) {
            URL stream = HectorTest.class.getClassLoader().getResource("cassandra.yaml");
            File cassandraYaml = new File(stream.toURI());

            EmbeddedCassandra.builder().withCleanDataStore().withStartupCommands(cassandraCommands)
                    .withHostname(cassandraHostname).withHostport(cassandraPort)
                    .withCassandaConfigurationDirectoryPath(configurationPath)
                    .withCassandaYamlFile(cassandraYaml).build();
        }

        CassandraHostConfigurator configurator = new CassandraHostConfigurator(
                cassandraHostname + ":" + cassandraPort);
        Cluster cluster = HFactory.getOrCreateCluster(cassandraClusterName, configurator);
        me.prettyprint.hector.api.Keyspace keyspace = HFactory.createKeyspace(cassandraKeySpaceName, cluster);
        return keyspace;
    } catch (Exception e) {
        throw new RuntimeException("Error configuring access", e);
    }
}

From source file:json.YetiJson.java

@SuppressWarnings("rawtypes")
static private AList convertList(AList expected, List value) {
    if (value.isEmpty()) {
        return null;
    }/*www .j  a v a  2  s  .com*/

    MList result = new MList();
    result.reserve(value.size());
    for (Object item : value) {
        result.add(convertValue(expected.first(), item));
    }
    return result;
}

From source file:json.YetiJson.java

@SuppressWarnings("rawtypes")
static private AList convertList(List value) {
    if (value.isEmpty()) {
        return null;
    }//from www . j  ava 2 s  . com

    MList result = new MList();
    result.reserve(value.size());
    for (Object item : value) {
        result.add(convertValue(item));
    }
    return result;
}

From source file:net.sourceforge.fenixedu.util.InquiriesUtil.java

/**
 * @return Returns the list containing with only the first occurrence of the
 *         elementes based on the equals method the result list is ordered
 *         by the externalId//from w w  w .  j a  v  a2s.  co  m
 */
public static void removeDuplicates(final List beanList) {
    if (beanList.isEmpty()) {
        return;
    }

    Collections.sort(beanList, new BeanComparator("externalId"));

    final Iterator iter = beanList.iterator();
    InfoObject prev = (InfoObject) iter.next();
    while (iter.hasNext()) {
        final InfoObject curr = (InfoObject) iter.next();
        if (curr.equals(prev)) {
            iter.remove();
        }
        prev = curr;
    }
}

From source file:Main.java

public static <T> List<T> unmodifiableList(final List<? extends T> l, final boolean newList,
        final boolean emptyAsNull) {
    if (l == null) {
        return null;
    }//w  w w . j  av a  2 s .  c  o  m

    if (emptyAsNull && l.isEmpty()) {
        return null;
    }

    return Collections.unmodifiableList(newList ? new ArrayList<>(l) : l);
}

From source file:Main.java

/**
 * This method joins two lists returning the a single list consisting of the first followed by the second.
 * //from  w  w  w  .  ja va2 s  .com
 * @param first  first list. can be null.
 * @param second second list. can be null.
 * @param emptyResultIsNull if the result is empty, should we return null?
 * @return the concatenation of both lists or null
 */
public static <T> List<T> nullSafeAppend(List<T> first, List<T> second, boolean emptyResultIsNull) {
    List<T> result = new ArrayList<T>();

    if (first != null)
        result.addAll(first);
    if (second != null)
        result.addAll(second);

    if (result.isEmpty() && emptyResultIsNull) {
        result = null;
    }
    return result;
}

From source file:de.tor.tribes.util.xml.JDomUtils.java

/** Get the value of the first available node.
 * @return the value of the first available node
 *//*from  w  w w.j  av  a 2 s . co m*/
public static String getNodeValue(Element element, String path) {
    List list;
    String getNodeValue;

    list = getList(element, path);
    if (list.isEmpty()) {
        getNodeValue = null;
    } else {
        getNodeValue = ((Element) list.get(0)).getTextTrim();
    }
    return getNodeValue;
}