List of usage examples for java.util Collections emptyList
@SuppressWarnings("unchecked") public static final <T> List<T> emptyList()
From source file:Main.java
/** * Converts the specified {@link JSONArray JSON array} to a * {@link List list}./*from w ww . ja v a 2s. c o m*/ * * @param <T> the type of elements maintained by the specified json array * @param jsonArray the specified json array * @return an {@link ArrayList array list} */ @SuppressWarnings("unchecked") public static <T> List<T> jsonArrayToList(final JSONArray jsonArray) { if (null == jsonArray) { return Collections.emptyList(); } final List<T> ret = new ArrayList<T>(); for (int i = 0; i < jsonArray.length(); i++) { ret.add((T) jsonArray.opt(i)); } return ret; }
From source file:com.tek271.reverseProxy.utils.RegexTools.java
/** Find all matches in a string */ public static List<Tuple3<Integer, Integer, String>> findAll(Pattern pattern, String text, boolean matchGroups) { if (StringUtils.isEmpty(text)) return Collections.emptyList(); Matcher matcher = pattern.matcher(text); List<Tuple3<Integer, Integer, String>> r = Lists.newArrayList(); while (matcher.find()) { int groupCount = matcher.groupCount(); if (groupCount == 0 || !matchGroups) { r.add(getMatch(matcher, 0)); } else {// ww w . ja v a 2s . c om for (int i = 1; i <= groupCount; i++) { r.add(getMatch(matcher, i)); } } } return r; }
From source file:com.mooing.wss.common.util.BeanUtil.java
public static <T> List<Integer> getIds(List<T> beanList) { if (beanList.isEmpty()) { return Collections.emptyList(); }/*from w w w . ja v a2 s . co m*/ List<Integer> ids = new ArrayList<Integer>(); Class<? extends Object> beanClass = beanList.get(0).getClass(); try { Method method = beanClass.getMethod("getId"); for (T beanObj : beanList) { ids.add((Integer) method.invoke(beanObj)); } } catch (Exception e) { throw new IllegalArgumentException("Element of argument must be support getId() method"); } return ids; }
From source file:Main.java
public static List<Node> contents(Element element) { if (element == null || !element.hasChildNodes()) { return Collections.emptyList(); }//from w ww . j a va2s . c o m List<Node> contents = new ArrayList<Node>(); for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) { contents.add(child); } return contents; }
From source file:Main.java
/** * Copies the contents of a Collection to a new, unmodifiable Collection. If the Collection is null, an empty * Collection will be returned.//from ww w . j a va 2s. c o m * <p> * This is especially useful for methods which take Collection parameters. Directly assigning such a Collection * to a member variable can allow external classes to modify internal state. Classes may have different state * depending on the size of a Collection; for example, a button might be disabled if the the Collection size is zero. * If an external object can change the Collection, the containing class would have no way have knowing a * modification occurred. * * @param <T> The type of element in the Collection. * @param collection The Collection to copy. * @return A new, unmodifiable Collection which contains all of the elements of the List parameter. Will never be * null. */ public static <T> Collection<T> copyToUnmodifiableCollection(Collection<T> collection) { if (collection != null) { Collection<T> collectionCopy = new ArrayList(collection); return Collections.unmodifiableCollection(collectionCopy); } else { return Collections.emptyList(); } }
From source file:Main.java
private static List<String> parseParticipants(String s) { if (s == null || s.length() == 0) { return Collections.emptyList(); }//from www . ja va2 s .c o m String[] parts = s.split(","); List<String> ret = new ArrayList<String>(); for (String part : parts) { ret.add(part.trim()); } return ret; }
From source file:com.liferay.ide.core.util.FileListing.java
public static List<File> getFileListing(File dir) throws FileNotFoundException { List<File> result = new ArrayList<>(); File[] files = dir.listFiles(); if (ListUtil.isEmpty(files)) { return Collections.emptyList(); }/* w ww . j av a2 s . c o m*/ for (File file : files) { result.add(file); if (!file.isFile()) { List<File> deeperList = getFileListing(file); result.addAll(deeperList); } } return result; }
From source file:Main.java
public static <T> List<List<T>> innerJoin(List<T> l1, List<T> l2, BiFunction<T, T, T> function) { if (l1 == null || l2 == null) { throw new NullPointerException("inner join arrays must not be null"); }/*from ww w . j a v a2 s .c om*/ if (l1.isEmpty() && l2.isEmpty()) { return Collections.emptyList(); } else if (l1.isEmpty()) { return Collections.singletonList(l2); } else if (l2.isEmpty()) { return Collections.singletonList(l1); } List<List<T>> result = new ArrayList<>(l1.size() * l2.size()); l1.stream().forEach(t1 -> { List<T> l = new ArrayList<>(); l2.stream().forEach(t2 -> l.add(function.apply(t1, t2))); result.add(l); }); return result; }
From source file:Main.java
public static <E> List<E> asList(E... elements) { if (elements == null || elements.length == 0) { return Collections.emptyList(); }/*from w w w.jav a 2s . com*/ // Avoid integer overflow when a large array is passed in int capacity = (int) Math.min(5L + elements.length + (elements.length / 10), Integer.MAX_VALUE); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }
From source file:Main.java
/** * Returns a list of the given size containing value. * //w w w.j a v a 2 s . c o m * @param theValue value to be filled with * @param theSize size of the collection * @return list containing value * * @version 0.2 * @since 0.2 */ public static <T> List<T> getFilledList(T theValue, int theSize) { if (theSize < 0) { return Collections.emptyList(); } List<T> lstReturn = new ArrayList<>(); for (int i = 0; i < theSize; i++) { lstReturn.add(theValue); } return lstReturn; }