List of usage examples for java.util Set isEmpty
boolean isEmpty();
From source file:Main.java
protected static Set intersectEmail(Set permitted, String email) { String _sub = email.substring(email.indexOf('@') + 1); if (permitted.isEmpty()) { permitted.add(_sub);//ww w . j a v a2 s .co m return permitted; } else { Set intersect = new HashSet(); Iterator _iter = permitted.iterator(); while (_iter.hasNext()) { String _permitted = (String) _iter.next(); if (_sub.endsWith(_permitted)) { intersect.add(_sub); } else if (_permitted.endsWith(_sub)) { intersect.add(_permitted); } } return intersect; } }
From source file:com.google.mr4c.config.ConfigUtils.java
public static String applyProperties(String template, Properties props, boolean checkAll) { Properties trimmed = CollectionUtils.toTrimmedProperties(props); String result = StrSubstitutor.replace(template, trimmed); if (checkAll) { Set<String> missing = extractVariables(result); if (!missing.isEmpty()) { throw new IllegalStateException("No values found for parameters [" + missing + "]"); }/*from w ww . j a v a2s . c o m*/ } return result; }
From source file:Main.java
protected static Set unionEmail(Set excluded, String email) { String _sub = email.substring(email.indexOf('@') + 1); if (excluded.isEmpty()) { excluded.add(_sub);// w w w.j av a 2 s . c om return excluded; } else { Set intersect = new HashSet(); Iterator _iter = excluded.iterator(); while (_iter.hasNext()) { String _excluded = (String) _iter.next(); if (_sub.endsWith(_excluded)) { intersect.add(_excluded); } else if (_excluded.endsWith(_sub)) { intersect.add(_sub); } else { intersect.add(_excluded); intersect.add(_sub); } } return intersect; } }
From source file:br.usp.poli.lta.cereda.aa.utils.SetOperations.java
/** * Calcula o produto cartesiano de um vetor de conjuntos. * @param sets Vetor de conjuntos.// ww w.j a v a2 s . c om * @return Produto cartesiano do vetor de conjuntos. */ public static Set<List<Object>> cartesianProduct(Set<?>... sets) { // deve haver mais do que um conjunto Validate.isTrue(sets.length > 1, "No possvel calcular o produto cartesiano " + "de apenas um conjunto."); // nenhum conjunto pode ser vazio for (Set<?> set : sets) { Validate.isTrue(!set.isEmpty(), "No possvel calcular o produto cartesiano " + "quando um dos conjuntos vazio."); } // calcula o produto cartesiano Set<List<Object>> elements = fetchElements(0, sets); // o retorno da funo gera listas com elementos em ordem // reversa, portanto, necessrio inverter os elementos das // listas obtidas Set<List<Object>> result = new HashSet<>(); for (List<Object> list : elements) { Collections.reverse(list); result.add(list); } return result; }
From source file:Main.java
/** * set convert to byte[]/*from w w w.j a v a 2 s. c om*/ */ public static byte[] setConvertToByte(Set<String> values, String separate) { if (values == null) { return null; } if (values.isEmpty()) { return new byte[0]; } String sp = TextUtils.isEmpty(separate) ? COMMA : separate; StringBuilder sb = new StringBuilder(64); int _size = values.size() - 1; int count = 0; for (String value : values) { sb.append(value); if (count != _size) { sb.append(sp); } count++; } return sb.toString().getBytes(); }
From source file:Main.java
/** * set convert to string//from w w w . j a v a 2 s . c o m */ public static String setConvertToString(Set<String> values, String separate) { if (values == null) { return null; } if (values.isEmpty()) { return ""; } String sp = TextUtils.isEmpty(separate) ? COMMA : separate; StringBuilder sb = new StringBuilder(64); int _size = values.size() - 1; int count = 0; for (String value : values) { sb.append(value); if (count != _size) { sb.append(sp); } count++; } return sb.toString(); }
From source file:com.enonic.cms.core.search.builder.ContentIndexDataFieldValueSetFactory.java
private static void addStringFieldValue(ContentIndexDataElement element, final Set<ContentIndexDataFieldAndValue> set) { final Set<String> elementStringValues = element.getStringValues(); if (elementStringValues != null && !elementStringValues.isEmpty()) { set.add(new ContentIndexDataFieldAndValue(element.getFieldBaseName(), elementStringValues)); }/*from w ww .j a va 2s .co m*/ }
From source file:com.sonicle.webtop.core.app.util.ClassHelper.java
public static Annotation getClassAnnotation(Class clazz, Class annotationClass) { if (clazz == null) return null; Set<Annotation> annotations = getClassAnnotations(clazz, annotationClass); return annotations.isEmpty() ? null : annotations.iterator().next(); }
From source file:Main.java
public static <T> boolean hasCycle(Collection<T> vertices, Function<T, Collection<T>> neighborExtractor) { Map<T, Collection<T>> parents = vertices.stream().collect(toMap(identity(), v -> new ArrayList<T>())); vertices.forEach(/*from w w w. j a v a 2 s . c om*/ v -> nullSafeCollection(neighborExtractor.apply(v)).forEach(child -> parents.get(child).add(v))); Set<T> roots = vertices.stream().filter(v -> parents.get(v).isEmpty()).collect(Collectors.toSet()); while (!roots.isEmpty()) { T root = roots.iterator().next(); roots.remove(root); parents.remove(root); nullSafeCollection(neighborExtractor.apply(root)).forEach(child -> { parents.get(child).remove(root); if (parents.get(child).isEmpty()) { roots.add(child); } }); } return !parents.isEmpty(); }
From source file:com.enonic.cms.core.search.builder.ContentIndexDataFieldValueSetFactory.java
private static void addNumericFieldValue(ContentIndexDataElement element, final Set<ContentIndexDataFieldAndValue> contentIndexDataFieldAndValues) { final Set<Double> elementNumericValues = element.getNumericValues(); if (elementNumericValues != null && !elementNumericValues.isEmpty()) { contentIndexDataFieldAndValues.add(new ContentIndexDataFieldAndValue( element.getFieldBaseName() + INDEX_FIELD_TYPE_SEPARATOR + NUMBER_FIELD_POSTFIX, elementNumericValues));//from w w w . ja va2 s.co m } }