Example usage for java.util Collection isEmpty

List of usage examples for java.util Collection isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:cross.io.PropertyFileGenerator.java

/**
 * Creates a property object for the given class, containing those fields,
 * which are annotated by {/* w  w  w.j  a  v a2s. com*/
 *
 * @return 
 * @Configurable}.
 * @param c
 */
public static PropertiesConfiguration createProperties(Class<?> c) {
    Collection<String> keys = AnnotationInspector.getRequiredConfigKeys(c);
    if (!keys.isEmpty()) {
        PropertiesConfiguration pc = new PropertiesConfiguration();
        for (String key : keys) {
            pc.addProperty(key, AnnotationInspector.getDefaultValueFor(c, key));
        }
        return pc;
    } else {
        LoggerFactory.getLogger(PropertyFileGenerator.class)
                .info("Could not find annotated configuration keys for class {}!", c.getName());
    }
    return new PropertiesConfiguration();
}

From source file:com.cloudera.oryx.common.math.VectorMath.java

/**
 * @param M tall, skinny matrix/* www  .  jav a  2  s  .c  o m*/
 * @return MT * M as a dense matrix
 */
public static RealMatrix transposeTimesSelf(Collection<float[]> M) {
    if (M == null || M.isEmpty()) {
        return null;
    }
    int features = 0;
    RealMatrix result = null;
    for (float[] vector : M) {
        if (result == null) {
            features = vector.length;
            result = new Array2DRowRealMatrix(features, features);
        }
        for (int row = 0; row < features; row++) {
            float rowValue = vector[row];
            for (int col = 0; col < features; col++) {
                result.addToEntry(row, col, rowValue * vector[col]);
            }
        }
    }
    return result;
}

From source file:Main.java

/**
 * Checks if the given collection is instancied and not empty
 *
 * @param <T>//from   w  w w.j  a  v  a2  s  .  c  o m
 * @param collection
 * @return
 */
public static <T> boolean isNotEmpty(final Collection<T> collection) {
    return collection != null && !collection.isEmpty();
}

From source file:Main.java

/**
 * Creates a map with the elements of the collection as values using the
 * specified keyMethod to obtain the key from the elements.
 *//* w  w  w  .  ja  v a 2  s. co m*/
@SuppressWarnings("unchecked")
public static <K, T> Map<K, T> createMap(Collection<T> collection, String keyMethod) {
    Map<K, T> map = new HashMap<>(collection.size());

    if (collection.isEmpty()) {
        return map;
    }

    Class<?> elementClass = collection.iterator().next().getClass();

    Method getKeyMethod;

    try {
        getKeyMethod = elementClass.getMethod(keyMethod, new Class[0]);
    } catch (Exception e) {
        throw new RuntimeException("Failed to get key method", e);
    }

    for (T element : collection) {
        K key;
        try {
            key = (K) getKeyMethod.invoke(element, (Object[]) null);
        } catch (Exception e) {
            throw new RuntimeException("Failed to get key", e);
        }

        map.put(key, element);
    }

    return map;
}

From source file:adalid.commons.util.ColUtils.java

public static <T extends Comparable<? super T>> Collection<T> sort(Collection<T> collection) {
    if (collection instanceof List && !collection.isEmpty()) {
        List<T> list = (List<T>) collection;
        Collections.sort(list);//from   w  w w. j a  va  2 s .c om
    }
    return collection;
}

From source file:de.kbs.acavis.integration.mas.odata.EntityHelper.java

public static String idLongInList(String property, Collection<Long> ids) {
    // Avoid errors caused by empty filter-statements using a valid but false expression
    if (ids.isEmpty())
        return "1 eq 0";

    return property + " eq " + StringUtils.join(ids, " or " + property + " eq ");
}

From source file:com.jkoolcloud.tnt4j.streams.sample.custom.SampleIntegration.java

/**
 * Configure streams and parsers, and run each stream in its own thread.
 *
 * @param cfgFileName/*from w w  w . j  av a2s.c o m*/
 *            configuration file name
 */
public static void loadConfigAndRun(String cfgFileName) {
    try {
        StreamsConfigLoader cfg = StringUtils.isEmpty(cfgFileName) ? new StreamsConfigLoader()
                : new StreamsConfigLoader(cfgFileName);
        Collection<TNTInputStream<?, ?>> streams = cfg.getStreams();
        if (streams == null || streams.isEmpty()) {
            throw new IllegalStateException("No Activity Streams found in configuration"); // NON-NLS
        }

        ThreadGroup streamThreads = new ThreadGroup("Streams"); // NON-NLS
        StreamThread ft;
        for (TNTInputStream<?, ?> stream : streams) {
            ft = new StreamThread(streamThreads, stream,
                    String.format("%s:%s", stream.getClass().getSimpleName(), stream.getName())); // NON-NLS
            ft.start();
        }
    } catch (Exception e) {
        LOGGER.log(OpLevel.ERROR, String.valueOf(e.getLocalizedMessage()), e);
    }
}

From source file:de.kbs.acavis.integration.mas.odata.EntityHelper.java

public static String idInList(String property, Collection<Integer> ids) {
    // Avoid errors caused by empty filter-statements using a valid but false expression
    if (ids.isEmpty())
        return "1 eq 0";

    return property + " eq " + StringUtils.join(ids, " or " + property + " eq ");
}

From source file:grakn.core.util.GraqlTestUtil.java

public static <T> void assertCollectionsNonTriviallyEqual(Collection<T> c1, Collection<T> c2) {
    assertFalse("Trivial equality!", c1.isEmpty() && c2.isEmpty());
    assertCollectionsEqual(c1, c2);/*from w  ww  . j av  a 2  s .  c  o  m*/
}

From source file:grakn.core.util.GraqlTestUtil.java

public static <T> void assertCollectionsNonTriviallyEqual(String msg, Collection<T> c1, Collection<T> c2) {
    assertFalse("Trivial equality!", c1.isEmpty() && c2.isEmpty());
    assertCollectionsEqual(msg, c1, c2);
}