List of usage examples for java.util Collection isEmpty
boolean isEmpty();
From source file:Main.java
public static boolean isEmpty(final Collection<?> collection) { if (null == collection) { return true; } else {//from w w w . ja va 2s .c o m return collection.isEmpty(); } }
From source file:Main.java
public static <T> T getObjInList(Class<T> clazz, Collection<T> all, String valueStr, String propName) throws Exception { if (all.isEmpty() || valueStr == null) { return null; }// w w w. j a va 2 s.c om T obj = null; Iterator<T> iter = all.iterator(); for (; iter.hasNext();) { T temp = iter.next(); Object match = null; if (propName == null) { match = temp.toString(); } else { Field field = clazz.getField(propName); field.setAccessible(true); match = field.get(temp); } if (valueStr.equals(match)) { obj = temp; break; } } return obj; }
From source file:fi.hsl.parkandride.core.service.PasswordValidator.java
public static void validate(String password) { Collection<Violation> violations = new ArrayList<>(); validate(password, violations);/*from w ww .j a va2 s . c o m*/ if (!violations.isEmpty()) { throw new ValidationException(violations); } }
From source file:Main.java
public static String[][] returnTable(Collection E) { if ((E == null) || E.isEmpty()) { System.out.println("The collection is empty!"); }//from www . j a va 2s .c o m Set<Field> collectionFields = new TreeSet<>(new Comparator<Field>() { @Override public int compare(Field o1, Field o2) { return o1.getName().compareTo(o2.getName()); } }); for (Object o : E) { Class c = o.getClass(); createSetOfFields(collectionFields, c); while (c.getSuperclass() != null) { c = c.getSuperclass(); createSetOfFields(collectionFields, c); } } String[][] exitText = new String[E.size() + 1][collectionFields.size() + 1]; exitText[0][0] = String.format("%20s", "Class"); int indexOfColumn = 0; for (Field f : collectionFields) { exitText[0][indexOfColumn + 1] = String.format("%20s", f.getName()); indexOfColumn++; } int indexOfRow = 0; for (Object o : E) { indexOfColumn = 0; exitText[indexOfRow + 1][0] = String.format("%20s", o.getClass().getSimpleName()); for (Field field : collectionFields) { try { field.setAccessible(true); if (field.get(o) instanceof Date) { exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20tD", field.get(o)); } else { String temp = String.valueOf(field.get(o)); exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20s", temp); } } catch (Exception e) { exitText[indexOfRow + 1][indexOfColumn + 1] = String.format("%20s", "-"); } indexOfColumn++; } indexOfRow++; } return exitText; }
From source file:Main.java
public static Collection<String> addElementBeforeAndAfter(Collection<?> collection, String toAddBefore, String toAddAfter) {// ww w.java 2 s .c o m if (collection == null || collection.isEmpty()) { return Collections.emptyList(); } List<String> result = new ArrayList<>(collection.size()); for (Object o : collection) { StringBuilder stringBuilder = new StringBuilder( o.toString().length() + toAddBefore.length() + toAddAfter.length()); stringBuilder.append(toAddBefore); stringBuilder.append(o.toString().trim()); stringBuilder.append(toAddAfter); result.add(stringBuilder.toString()); } return result; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> List<T> generatePropertyList(Collection<?> collection, String property) { assert property != null; if (collection == null || collection.isEmpty()) { return new ArrayList<T>(0); }/* w w w .ja v a 2 s. c om*/ List<T> list = new ArrayList<T>(collection.size()); try { for (Object obj : collection) { Field field = obj.getClass().getDeclaredField(property); field.setAccessible(true); Object object = field.get(obj); list.add((T) object); } return list; } catch (Throwable e) { throw new RuntimeException(e); } }
From source file:com.mseeworld.qzh.util.Debug.java
/** * ??// w w w.jav a2 s .c o m * @param list * @param ts * @date 2013-5-8 */ public static final <T> void printf(Collection<T> list, ToString<T> ts) { if (list == null || list.isEmpty()) return; Iterator<T> iter = list.iterator(); while (iter.hasNext()) { T t = iter.next(); // if(t == null)continue ; if (ts == null) { System.out.println(t.toString()); } else { String msg = ts.toString(t); // if(msg != null) { System.out.println(msg); // } } } }
From source file:Main.java
/** * Checks passed {@link Collection} instance on null and on emptiness * returns true if it is not null and is not empty * //from w w w. j a v a 2 s . c o m * @param collection * @return <code></code> */ public static boolean valid(Collection<?> collection) { return (collection != null && !collection.isEmpty()); }
From source file:com.emarsys.predict.StringUtil.java
/** * Constructs a new String from the elements of input list separated elements with delimiter. * * @param l items for the construction * @param delimiter the delimiter/*from w w w.j a va 2 s . co m*/ * @return the constructed string */ static String toStringWithDelimiter(Collection<?> l, String delimiter) { String ret = ""; if (l != null && !l.isEmpty()) { Iterator<?> i = l.iterator(); while (i.hasNext()) { ret += i.next() + delimiter; } ret = ret.substring(0, ret.length() - delimiter.length()); } return ret; }
From source file:Main.java
private static String toString(Collection<int[]> arrays) { if (arrays == null || arrays.isEmpty()) { return "[]"; }/*from ww w. j av a2 s . c o m*/ StringBuilder buffer = new StringBuilder(); buffer.append('['); Iterator<int[]> it = arrays.iterator(); while (it.hasNext()) { buffer.append(Arrays.toString(it.next())); if (it.hasNext()) { buffer.append(", "); } } buffer.append(']'); return buffer.toString(); }