Example usage for java.util Set isEmpty

List of usage examples for java.util Set isEmpty

Introduction

In this page you can find the example usage for java.util Set isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:tools.xor.util.ClassUtil.java

public static boolean intersectsTags(String[] tags, String[] otherTags) {
    Set<String> commonTags = new HashSet<String>(Arrays.asList(tags));
    commonTags.retainAll(new HashSet<String>(Arrays.asList(otherTags)));
    if (commonTags.isEmpty()) {
        // applies to different tags so they do not overlap
        return false;
    }// w ww . j  a v  a2s  .  c om

    return true;
}

From source file:com.janrain.backplane2.server.Scope.java

/**
 * @return a new Scope consisting of all scope values present in the first one, less the auth-req scope values in 'revoke'
 *///from   ww  w .  ja v  a2  s  .  com
public static Scope revoke(@NotNull Scope scope, @NotNull Scope revoke) {
    Map<BackplaneMessage.Field, LinkedHashSet<String>> newScope = new LinkedHashMap<BackplaneMessage.Field, LinkedHashSet<String>>();

    for (BackplaneMessage.Field scopeKey : scope.getScopeMap().keySet()) {
        Set<String> revokeValues = revoke.getScopeFieldValues(scopeKey);
        if (scopeKey.getScopeType() != ScopeType.AUTHZ_REQ || revokeValues == null || revokeValues.isEmpty()) {
            newScope.put(scopeKey, scope.getScopeMap().get(scopeKey));
        } else {
            LinkedHashSet<String> newValues = new LinkedHashSet<String>();
            for (String scopeValue : scope.getScopeFieldValues(scopeKey)) {
                if (!revokeValues.contains(scopeValue)) {
                    newValues.add(scopeValue);
                }
            }
            newScope.put(scopeKey, newValues);
        }
    }

    return new Scope(newScope);
}

From source file:com.tech.utils.CustomCollectionUtil.java

/**
 * Method to return comma separated value String for set of long values.
 * //from ww w .jav  a 2 s  . c  o m
 * @param itemSet
 * @return csvString
 */
public static String convertSetToString(Set<Long> set) {
    StringBuilder csvString = new StringBuilder();
    if (set != null && !set.isEmpty()) {
        for (Long item : set) {
            if (csvString.length() > 0) {
                csvString.append(COMMA_SEPARATOR);
                csvString.append(item.toString());
            } else {
                csvString.append(item.toString());
            }
        }
    }
    if (csvString.length() > 0) {
        return csvString.toString();
    } else {
        return BLANK_STRING;
    }
}

From source file:dk.kontentsu.api.exposure.ItemExposure.java

private static MultipartUploadItemRepresentation valid(
        final MultipartUploadItemRepresentation uploadItemRepresentation) {
    ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
    Validator validator = vf.getValidator();
    Set<ConstraintViolation<MultipartUploadItemRepresentation>> errors = validator
            .validate(uploadItemRepresentation, Default.class);
    if (!errors.isEmpty()) {
        throw new ConstraintViolationException("Error in multipart upload for item with URI: "
                + Objects.toString(uploadItemRepresentation.getUri()), errors);
    }/*from w w  w. j a  v a 2  s.c o  m*/
    return uploadItemRepresentation;
}

From source file:de.unisb.cs.st.javaslicer.slicing.DirectSlicer.java

private static <T> Set<T> intersect(Set<T> set1, Set<T> set2) {
    if (set1.isEmpty() || set2.isEmpty())
        return Collections.emptySet();

    Set<T> smallerSet;/*  w w w  .  ja  v a 2 s.  c  om*/
    Set<T> biggerSet;
    if (set1.size() < set2.size()) {
        smallerSet = set1;
        biggerSet = set2;
    } else {
        smallerSet = set2;
        biggerSet = set1;
    }

    Set<T> intersection = null;
    for (T obj : smallerSet) {
        if (biggerSet.contains(obj)) {
            if (intersection == null)
                intersection = new HashSet<T>();
            intersection.add(obj);
        }
    }

    if (intersection == null)
        return Collections.emptySet();
    return intersection;
}

From source file:Main.java

/**
 * Internal function to realize the mathematical combination of given
 * values. This method creates the next sub-tree by iterating over values
 * given by parameter set./*from   w  w w  .  ja v a 2s  . c om*/
 * 
 * @param <E>
 *            the type of the given and returned values
 * @param set
 *            the possible values for next iteration
 * @param combination
 *            the current path of the abstract combination tree
 * @param combinations
 *            overall combinations
 */
private static <E extends Object> void combination(Set<E> set, Set<E> combination, Set<Set<E>> combinations) {
    for (E value : set) {
        Set<E> combination_ = new HashSet<E>();
        combination_.addAll(combination);
        combination_.add(value);
        combinations.add(combination_);

        Set<E> set_ = new HashSet<E>();
        set_.addAll(set);
        long size = set_.size();
        set_.remove(value);
        if (set_.size() == size) {
            for (E v : set_) {
                if (v.equals(value)) {
                    set_.remove(v);
                    break;
                }
            }
        }
        if (!set_.isEmpty()) {
            combination(set_, combination_, combinations);
        }
    }
}

From source file:edu.oregonstate.eecs.mcplan.abstraction.WekaUtil.java

public static Instances powerSet(final Instances D, final int n) {
    final Attribute class_attr = D.classAttribute();

    final ImmutableSet.Builder<Integer> b = new ImmutableSet.Builder<Integer>();
    final int Nattr = class_attr != null ? D.numAttributes() - 1 : D.numAttributes();
    for (final int i : Fn.range(1, Nattr)) {
        b.add(i);//w w  w.  j a v  a2  s  . co  m
    }
    final Set<Set<Integer>> index = Sets.powerSet(b.build());

    final ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    for (final Set<Integer> subset : index) {
        if (subset.isEmpty() || subset.size() > n) {
            continue;
        }

        final StringBuilder attr_name = new StringBuilder();
        int count = 0;
        for (final Integer i : subset) {
            if (count++ > 0) {
                attr_name.append("_x_");
            }
            attr_name.append(D.attribute(i).name());
        }

        attributes.add(new Attribute(attr_name.toString()));
    }
    if (class_attr != null) {
        assert (class_attr.isNominal());
        attributes.add(WekaUtil.createNominalAttribute(class_attr.name(), class_attr.numValues()));
    }

    final String Pname = "P" + n + "_" + D.relationName();
    final Instances P = new Instances(Pname, attributes, 0);
    if (class_attr != null) {
        P.setClassIndex(attributes.size() - 1);
    }

    for (final Instance inst : D) {
        final double[] xp = new double[attributes.size()];
        int idx = 0;
        for (final Set<Integer> subset : index) {
            if (subset.isEmpty() || subset.size() > n) {
                continue;
            }

            double p = 1.0;
            for (final Integer i : subset) {
                p *= inst.value(i);
            }
            xp[idx++] = p;
        }
        if (class_attr != null) {
            xp[idx++] = inst.classValue();
        }

        WekaUtil.addInstance(P, new DenseInstance(inst.weight(), xp));
    }

    return P;
}

From source file:grails.plugin.searchable.internal.util.GrailsDomainClassUtils.java

/**
 * Get the parent GrailsDomainClass for the given GrailsDomainClass, if it
 * exists in the given collection otherwise null
 *
 * @param grailsDomainClass the class whose parent to find
 * @param grailsDomainClasses the collection of possible parents
 * @return null if the given class has no parent or the parent is not in the collection
 *///from w  w  w.j  av a2 s.c o  m
public static GrailsDomainClass getSuperClass(GrailsDomainClass grailsDomainClass,
        Collection grailsDomainClasses) {
    Set candidates = new HashSet();
    for (Iterator iter = grailsDomainClasses.iterator(); iter.hasNext();) {
        GrailsDomainClass gdc = (GrailsDomainClass) iter.next();
        if (gdc.getSubClasses().contains(grailsDomainClass)) {
            candidates.add(gdc);
        }
    }
    if (candidates.isEmpty()) {
        return null;
    }
    while (candidates.size() > 1) {
        Set copy = new HashSet(candidates);
        for (Iterator iter = copy.iterator(); iter.hasNext();) {
            GrailsDomainClass supsup = (GrailsDomainClass) iter.next();
            boolean remove = false;
            for (Iterator iter2 = candidates.iterator(); iter2.hasNext();) {
                GrailsDomainClass sup = (GrailsDomainClass) iter2.next();
                if (supsup.getSubClasses().contains(sup)) {
                    remove = true;
                    break;
                }
            }
            if (remove) {
                candidates.remove(supsup);
                break;
            }
        }
    }
    return (GrailsDomainClass) candidates.iterator().next();
}

From source file:davmail.util.StringUtil.java

/**
 * Join values with given separator./*w w w.j a  va2  s  .  c o m*/
 *
 * @param values    value set
 * @param separator separator
 * @return joined values
 */
public static String join(Set<String> values, String separator) {
    if (values != null && !values.isEmpty()) {
        StringBuilder result = new StringBuilder();
        for (String value : values) {
            if (result.length() > 0) {
                result.append(separator);
            }
            result.append(value);
        }
        return result.toString();
    } else {
        return null;
    }
}

From source file:com.tech.utils.CustomCollectionUtil.java

/**
 * Method to calculate standard set union operation. Example : Consider set1
 * = {1,2,3} and set2 = {2,3,4,5} then output of this method will be
 * setUnion = {1,2,3,4,5}/*from  w  w w .j ava  2  s  . co  m*/
 * 
 * @param set1
 * @param set2
 * @return setUnion
 */
public static Set<Long> setUnion(Set<Long> itemSet1, Set<Long> itemSet2) {
    Set<Long> setUnion = new HashSet<Long>();
    if (itemSet1 != null && !itemSet1.isEmpty()) {
        for (Long item : itemSet1) {
            setUnion.add(item);
        }
    }
    if (itemSet2 != null && !itemSet2.isEmpty()) {
        for (Long item : itemSet2) {
            setUnion.add(item);
        }
    }
    return setUnion;
}