List of usage examples for java.util Collection add
boolean add(E e);
From source file:com.shenit.commons.utils.CollectionUtils.java
public static <V> V add(Collection<V> col, V val) { if (!ValidationUtils.isEmpty(col)) col.add(val); return val; }
From source file:com.glaf.core.util.JsonUtils.java
public static JSONObject toJSONObject(Map<String, Object> params) { JSONObject jsonObject = null;//ww w .j a v a 2 s . co m if (params != null) { jsonObject = new JSONObject(); Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); try { if (value != null) { if (value instanceof Object[]) { Object[] array = (Object[]) value; Collection<Object> collection = new java.util.ArrayList<Object>(); for (int i = 0; i < array.length; i++) { collection.add(array[i]); } jsonObject.put(key, collection); } else if (value instanceof Collection<?>) { Collection<?> collection = (Collection<?>) value; jsonObject.put(key, collection); } else if (value instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) value; jsonObject.put(key, map); } else if (value instanceof java.util.Date) { java.util.Date date = (java.util.Date) value; String datetime = DateUtils.getDateTime(date); jsonObject.put(key, datetime); } else { jsonObject.put(key, value); } } } catch (JSONException ex) { ex.printStackTrace(); } } } return jsonObject; }
From source file:com.google.gerrit.sshd.DatabasePubKeyAuth.java
private static void addPublicKey(final Collection<PublicKey> out, final KeyPairProvider p, final String type) { final KeyPair pair = p.loadKey(type); if (pair != null && pair.getPublic() != null) { out.add(pair.getPublic()); }// ww w . j a v a 2s.c o m }
From source file:com.glaf.core.util.JsonUtils.java
public static String encode(Map<String, Object> params) { JSONObject jsonObject = null;//from w ww . java2s . com String str = null; if (params != null) { jsonObject = new JSONObject(); Set<Entry<String, Object>> entrySet = params.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); try { if (value != null) { if (value instanceof Object[]) { Object[] array = (Object[]) value; Collection<Object> collection = new java.util.ArrayList<Object>(); for (int i = 0; i < array.length; i++) { collection.add(array[i]); } jsonObject.put(key, collection); } else if (value instanceof Collection<?>) { Collection<?> collection = (Collection<?>) value; jsonObject.put(key, collection); } else if (value instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) value; jsonObject.put(key, map); } else if (value instanceof java.util.Date) { java.util.Date date = (java.util.Date) value; String datetime = DateUtils.getDateTime(date); jsonObject.put(key, datetime); } else { jsonObject.put(key, value); } } } catch (JSONException ex) { ex.printStackTrace(); } } str = jsonObject.toString(); } return str; }
From source file:edu.uci.ics.jung.utils.PredicateUtils.java
public static Collection getSatisfyingElements(Collection c, Predicate p) { Collection satisfied = new LinkedList(); for (Iterator iter = c.iterator(); iter.hasNext();) { Object o = iter.next();/* w w w . j av a 2 s . c o m*/ if (p.evaluate(o)) satisfied.add(o); } return satisfied; }
From source file:Main.java
/** * Removes all available elements from this {@link Iterable} and adds * them to the given {@link Collection}. *//* w w w. j ava 2s. c o m*/ public static <T> int drainTo(Iterable<? extends T> src, Collection<? super T> dst, int max) { if (src instanceof BlockingQueue<?>) { return ((BlockingQueue<? extends T>) src).drainTo(dst, max); } int count = 0; for (Iterator<? extends T> it = src.iterator(); it.hasNext();) { if (count >= max) { break; } dst.add(it.next()); it.remove(); ++count; } return count; }
From source file:com.glaf.core.util.JsonUtils.java
public static Map<String, String> decodeStringMap(String str) { Map<String, String> dataMap = new LinkedHashMap<String, String>(); if (StringUtils.isNotEmpty(str) && (str.length() > 0 && str.charAt(0) == '{') && str.endsWith("}")) { try {/*from w w w.jav a 2 s . c om*/ JSONObject jsonObject = (JSONObject) JSON.parse(str); Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String key = (String) entry.getKey(); Object value = entry.getValue(); if (value != null) { if (value instanceof Object[]) { Object[] array = (Object[]) value; Collection<Object> collection = new java.util.ArrayList<Object>(); for (int i = 0; i < array.length; i++) { collection.add(array[i]); } } else if (value instanceof JSONArray) { JSONArray array = (JSONArray) value; Collection<Object> collection = new java.util.ArrayList<Object>(); for (int i = 0, len = array.size(); i < len; i++) { collection.add(array.get(i)); } } else if (value instanceof Collection<?>) { } else if (value instanceof Map<?, ?>) { } else { dataMap.put(key, value.toString()); } } } } catch (JSONException ex) { ex.printStackTrace(); } } return dataMap; }
From source file:exm.stc.ic.ICUtil.java
public static void addIfVar(Collection<Var> res, Arg a) { if (a.isVar()) { res.add(a.getVar()); } }
From source file:Main.java
public static <E> boolean addAll(final Collection<? super E> c, final E[] array, final int off, final int len) { final int end = off + len; boolean result = false; for (int i = off; i < end; i++) { result |= c.add(array[i]); }/*from w w w . j ava2s . c om*/ return result; }
From source file:rashjz.info.com.az.util.AuthoritiesConverter.java
public static Collection<GrantedAuthority> getAuthorities(Set set) { //make everyone ROLE_USER Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); if (set == null) { GrantedAuthority grantedAuthority = new GrantedAuthority() { //anonymous inner type public String getAuthority() { return "ROLE_USER"; }/*from w w w. jav a 2 s. co m*/ }; grantedAuthorities.add(grantedAuthority); return grantedAuthorities; } else { for (Iterator<UserRoles> it = new HashSet<UserRoles>(set).iterator(); it.hasNext();) { UserRoles ur = it.next(); GrantedAuthority grantedAuthority = new GrantedAuthority() { //anonymous inner type public String getAuthority() { return "ROLE_USER"; } }; grantedAuthorities.add(grantedAuthority); } return grantedAuthorities; } }