List of usage examples for java.util Collection isEmpty
boolean isEmpty();
From source file:org.grails.datastore.mapping.redis.query.RedisQueryUtils.java
public static List<Long> transformRedisResults(ConversionService conversionService, Collection<String> results) { List<Long> returnResults; if (!results.isEmpty()) { List<Long> foreignKeys = new ArrayList<Long>(); for (String result : results) { foreignKeys.add(conversionService.convert(result, Long.class)); }//from w w w. j a v a 2 s.com returnResults = foreignKeys; } else { returnResults = Collections.emptyList(); } return returnResults; }
From source file:Main.java
public static String toString(Collection<Integer> stack, String delimiterChars) { if (stack.isEmpty()) { return ""; }/*from www . ja v a 2 s .c o m*/ if (stack.size() == 1) { return Integer.toString(stack.iterator().next()); } StringWriter writer = new StringWriter(); String delimiter = ""; for (Integer item : stack) { writer.append(delimiter); writer.append(Integer.toString(item)); delimiter = delimiterChars; } return writer.toString(); }
From source file:me.taylorkelly.mywarp.util.CommandUtils.java
/** * Joins all worlds in the given collection in one string, separated by {@code ", "}. * * @param worlds a collection of worlds// w w w . j a va 2s .c o m * @return a string with all world-names or {@code -} if the collection was empty */ public static String joinWorlds(Collection<LocalWorld> worlds) { if (worlds.isEmpty()) { return "-"; } StrBuilder ret = new StrBuilder(); for (LocalWorld world : worlds) { ret.appendSeparator(", "); ret.append(world.getName()); } return ret.toString(); }
From source file:Main.java
/** * @param col to filter using Collections2.filter * @param predicate to use//from w w w . java2 s . com * @param fallbackPredicate to use if predicate resulted in empty collection * @param <T> type contained in the collection * @return the filtered collection */ public static <T> Collection<T> filter(Collection<T> col, Predicate<? super T> predicate, Predicate<? super T> fallbackPredicate) { Collection<T> result = Collections2.filter(col, predicate); if (result.isEmpty()) { return Collections2.filter(col, fallbackPredicate); } return result; }
From source file:com.github.yongchristophertang.engine.AssertUtils.java
/** * Assert a collection of T instances is not empty. */// w w w . j av a2s .co m public static <T> void collectionNotEmpty(Collection<T> collection, String message) { if (collection.isEmpty()) { throw new IllegalArgumentException(message); } }
From source file:net.firejack.platform.core.utils.ArrayUtils.java
public static <T> T[] getArray(Collection<T> itemList, Class<T> clazz) { return itemList == null || itemList.isEmpty() ? null : itemList.toArray((T[]) Array.newInstance(clazz, itemList.size())); }
From source file:Main.java
/** * /*from w w w. ja v a 2 s. co m*/ * build a SQL IN clause from the array of parameters passed in * @param inListValues: components of the IN list * @return an empty string if the IN list will be empty */ protected static String inString(Collection<String> inListValues) { if (inListValues.isEmpty()) { return ""; } // the delimiter for strings in the DB is assumed to be a single quote. // this is the ANSI-92 standard. // if the ArrayList input is empty, IN ('') is returned. StringBuilder inBuilder = new StringBuilder(150); inBuilder.append("('"); boolean isFirst = true; for (String val : inListValues) { if (isFirst) { isFirst = false; } else { inBuilder.append("','"); } inBuilder.append(val); } inBuilder.append("')"); return inBuilder.toString(); }
From source file:Main.java
/** * Check whether a collection is null or empty. * * @param collection/*from www . j a va 2 s .c om*/ * Collection to check. * @return {@code true} if the collection is {@code null} or {@link Collection#isEmpty()} returns {@code true}. */ public static boolean isEmpty(Collection<?> collection) { return collection == null || collection.isEmpty(); }
From source file:Main.java
/** * Utility method to check for a not empty {@link Collection} including a null check. * * @param collection {@link Collection} to test for non empty * @return true if collection is not null and has at least one entry. *//* ww w.ja v a 2 s.com*/ public static boolean isNotEmpty(final Collection<?> collection) { return collection != null && !collection.isEmpty(); }
From source file:Main.java
/** * Return {@code true} if any element in '{@code candidates}' is contained in * '{@code source}', otherwise returns {@code false}. * //from w w w . jav a2s . c om * @param source * the source Collection. * @param candidates * the candidates to search for. * @return whether any of the candidates has been found. */ public static boolean containsAny(Collection<?> source, Object... candidates) { if (source == null || source.isEmpty() || candidates == null || candidates.length == 0) { return false; } for (Object candidate : candidates) { if (source.contains(candidate)) { return true; } } return false; }