List of usage examples for java.util Collections emptySet
@SuppressWarnings("unchecked") public static final <T> Set<T> emptySet()
From source file:Main.java
/** * Returns <code>theSet</code> if it is not <code>null</code> or * an unmodifiable singleton empty set (see {@link Collections#emptySet()}). * @param <T>/*from w w w.j a v a 2 s. c o m*/ * @param theSet * @return */ public static <T> Set<T> emptySetIfNull(final Set<T> theSet) { if (theSet == null) return Collections.emptySet(); else return theSet; }
From source file:me.smoe.adar.utils.cam.o.common.SentenceAnalyzer.java
public static Set<String> analyzer(String sentence) throws Exception { if (StringUtils.isEmpty(sentence)) { return Collections.emptySet(); }// w w w.java2s .com Analyzer analyzer = new StandardAnalyzer(); try { TokenStream tokenStream = analyzer.tokenStream(StringUtils.EMPTY, new StringReader(sentence)); tokenStream.addAttribute(CharTermAttribute.class); tokenStream.reset(); Set<String> words = new LinkedHashSet<>(); while (tokenStream.incrementToken()) { String word = ((CharTermAttribute) tokenStream.getAttribute(CharTermAttribute.class)).toString(); if (word.length() <= 1) { continue; } words.add(word); } return words; } finally { analyzer.close(); } }
From source file:io.syndesis.credential.CredentialFlowStateHelper.java
static Set<CredentialFlowState> restoreFrom(final Restorer restore, final HttpServletRequest request) { final Cookie[] servletCookies = request.getCookies(); if (ArrayUtils.isEmpty(servletCookies)) { return Collections.emptySet(); }// w ww . j av a 2 s.co m final List<javax.ws.rs.core.Cookie> credentialCookies = Arrays.stream(servletCookies) .filter(c -> c.getName().startsWith(CredentialFlowState.CREDENTIAL_PREFIX)) .map(CredentialFlowStateHelper::toJaxRsCookie).collect(Collectors.toList()); try { return restore.apply(credentialCookies, CredentialFlowState.class); } catch (final IllegalArgumentException e) { return Collections.emptySet(); } }
From source file:net.openid.appauth.AdditionalParamsProcessor.java
static Set<String> builtInParams(String... params) { if (params == null || params.length == 0) { return Collections.emptySet(); }/* w ww .ja v a 2 s .c o m*/ return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(params))); }
From source file:Main.java
private static <T> Set<T> _asSet(T[] a, boolean makeImmutable) { int count = (a != null) ? a.length : 0; Set<T> outSet;/*from ww w . j a v a2 s. co m*/ if (count == 0) { outSet = Collections.emptySet(); } else { if (count == 1) { outSet = Collections.singleton(a[0]); } else { // make the initial size big enough that we don't have to rehash to fit the array, for // the .75 load factor we pass in int initialSize = (int) Math.ceil(count / .75d); outSet = new HashSet<T>(initialSize, .75f); for (int i = 0; i < count; i++) { outSet.add(a[i]); } if (makeImmutable) { outSet = Collections.unmodifiableSet(outSet); } } } return outSet; }
From source file:Main.java
public static final Set<String> stringArrayToSet(final String[] array) { if (array == null) { return Collections.emptySet(); }//from w ww . ja v a 2 s . co m Set<String> tmp = new LinkedHashSet<>(); for (String part : array) { String trimmed = part.trim(); if (trimmed.length() > 0) { tmp.add(trimmed.intern()); } } return tmp; }
From source file:Main.java
/** * @param orig// w w w .j a va 2 s .co m * if null, return intersect */ public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect) { if (orig == null) return intersect; if (intersect == null || orig.isEmpty()) return Collections.emptySet(); Set<Object> set = new HashSet<Object>(orig.size()); for (Object p : orig) { if (intersect.contains(p)) set.add(p); } return set; }
From source file:Main.java
public static <T> Set<T> inter(final List<Set<T>> sets) { final List<Set<T>> mutable = new ArrayList<Set<T>>(sets.size()); for (final Set<T> s : sets) { // ignore nulls if (s != null) mutable.add(s);//w w w . j a v a2 s . co m } if (mutable.isEmpty()) return null; else if (mutable.size() == 1) return mutable.get(0); final int indexMin = indexOfMinSize(mutable); if (indexMin != 0) { mutable.add(0, mutable.remove(indexMin)); return inter(mutable); } if (mutable.get(0).isEmpty()) return Collections.emptySet(); // replace the first 2 by their intersection // (inter will swap as appropriate if java doesn't evalute args in source order) mutable.add(0, inter(mutable.remove(0), mutable.remove(0))); return inter(mutable); }
From source file:org.jboss.capedwarf.connect.server.HttpHeaders.java
/** * Get headers; read-only./* w w w . j av a 2s.co m*/ * * @return the headers */ public static Set<Header> getHeaders() { Set<Header> set = tlh.get(); if (set == null) return Collections.emptySet(); return Collections.unmodifiableSet(set); }
From source file:com.igitras.codegen.common.utils.Utils.java
public static <T> boolean checkCollectionEqual(Collection<T> from, Collection<T> to) { if (from == null) { from = Collections.emptySet(); }//w w w. j a v a 2s . c o m if (to == null) { to = Collections.emptySet(); } for (T t : from) { if (!to.contains(t)) { return false; } } for (T t : to) { if (!from.contains(t)) { return false; } } return true; }