List of utility methods to do List Single Value
T | single(List single if (list.size() == 1) { return list.get(0); } else if (list.size() == 0) { throw new RuntimeException("No results found!"); } else { throw new RuntimeException("More results returned than one!"); |
List | singleElementList(T element) single Element List List<T> newElementList = new ArrayList<>(1); newElementList.add(element); return newElementList; |
ArrayList | singleItemAsList(T item) Puts the single item inside newly created ArrayList and returns this list. ArrayList<T> list = new ArrayList<T>(); list.add(item); return list; |
List | singleQuoatanizeStringList(List Place single quotes around the individual entries in a List of Strings List<String> quotedEntries = new ArrayList<String>(entries == null ? 0 : entries.size()); if (entries != null) { for (Iterator<String> iterator = entries.iterator(); iterator.hasNext();) { String entry = (String) iterator.next(); quotedEntries.add("'" + entry + "'"); return quotedEntries; ... |
List | singletonList(final T source) singleton List return Collections.singletonList(source);
|
List | singletonList(T element) Replies a singleton list with the given element, or the empty list if the element is null .
if (element == null) { return Collections.emptyList(); return Collections.singletonList(element); |
List | singletonListIfNotNullOrEmptyListIfNull(T element) singleton List If Not Null Or Empty List If Null if (element == null) { return new LinkedList<T>(); } else { return list(element); |
T | singleValue(Class single Value if (null == values || values.size() != 1) { throw new IllegalStateException("Expecting a single value"); return type.cast(values.get(0)); |
T | singleValue(List l) single Value if (l == null || l.isEmpty()) return null; else return (T) l.get(0); |
T | singleValue(List single Value return values == null || values.isEmpty() ? null : values.get(0);
|