Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:ai.serotonin.haystack.validator.Source.java

public static void clean(List<HMap> rows) throws Exception {
    Set<String> tags = Tags.getTags();

    // Dump the fields we're not interested in.
    List<HMap> rowDump = new ArrayList<>();
    for (HMap row : rows) {
        Set<String> keyDump = new HashSet<>();
        for (String key : row.keySet()) {
            if (!tags.contains(key))
                keyDump.add(key);//w  w w . j av a2s  . c om
        }
        for (String key : keyDump)
            row.delete(key);
        row.delete("id");
        row.delete("dis");

        if (row.isEmpty())
            rowDump.add(row);
    }

    rows.removeAll(rowDump);
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.common.EntityListingTestUtils.java

public static void assertCorrectEntityAndPropertyTypeReferences(DataIterator<? extends CodeRecord> entityCodes,
        List<? extends BaseEntityPropertyRecord> properties, PropertyType[] propertyTypes) {
    assertTrue(properties.size() > 0);
    Set<Long> propertyTypesIds = extractIds(Arrays.asList(propertyTypes));
    Set<Long> entityIds = extractVOIds(asList(entityCodes));
    for (BaseEntityPropertyRecord property : properties) {
        assertTrue("Property type not found: " + property.prty_id, propertyTypesIds.contains(property.prty_id));
        assertTrue("Entity not found: " + property.entity_id, entityIds.contains(property.entity_id));
    }//  w w w .  ja  va  2s  . c o m
}

From source file:ca.sqlpower.architect.TestUtils.java

/**
 * Sets all the settable properties on the given target object
 * which are not in the given ignore set.
 * //w  ww  .  ja va  2 s .  com
 * @param target The object to change the properties of
 * @param propertiesToIgnore The properties of target not to modify or read
 * @return A Map describing the new values of all the non-ignored, readable 
 * properties in target.
 */
public static Map<String, Object> setAllInterestingProperties(Object target, Set<String> propertiesToIgnore)
        throws Exception {

    PropertyDescriptor props[] = PropertyUtils.getPropertyDescriptors(target);
    for (int i = 0; i < props.length; i++) {
        Object oldVal = null;
        if (PropertyUtils.isReadable(target, props[i].getName()) && props[i].getReadMethod() != null
                && !propertiesToIgnore.contains(props[i].getName())) {
            oldVal = PropertyUtils.getProperty(target, props[i].getName());
        }
        if (PropertyUtils.isWriteable(target, props[i].getName()) && props[i].getWriteMethod() != null
                && !propertiesToIgnore.contains(props[i].getName())) {

            NewValueMaker valueMaker = new ArchitectValueMaker(new SPObjectRoot());
            Object newVal = valueMaker.makeNewValue(props[i].getPropertyType(), oldVal, props[i].getName());

            System.out.println("Changing property \"" + props[i].getName() + "\" to \"" + newVal + "\"");
            PropertyUtils.setProperty(target, props[i].getName(), newVal);

        }
    }

    // read them all back at the end in case there were dependencies between properties
    return ca.sqlpower.testutil.TestUtils.getAllInterestingProperties(target, propertiesToIgnore);
}

From source file:com.asakusafw.testdriver.compiler.util.DeploymentUtil.java

/**
 * Deploys an artifact onto the directory.
 * @param source the source file/directory
 * @param destination the target path/*from  w w w  .  j a  va  2  s.  co m*/
 * @param options the deployment options
 * @throws IOException if I/O error was occurred
 */
public static void deploy(File source, File destination, DeployOption... options) throws IOException {
    Objects.requireNonNull(source);
    Objects.requireNonNull(destination);
    Objects.requireNonNull(options);
    Set<DeployOption> opts = EnumSet.noneOf(DeployOption.class);
    Collections.addAll(opts, options);
    if (opts.contains(DeployOption.DELETE_SOURCE)) {
        move(source, destination);
    } else {
        copy(source, destination);
    }
}

From source file:com.asakusafw.testdriver.compiler.util.DeploymentUtil.java

/**
 * Deletes the target file/directory.//from  www. j a v  a  2s. com
 * @param target the target file/directory
 * @param options the operation options
 * @return {@code true} if the target file/directory was successfully deleted (or does not exist initially),
 *     otherwise {@code false}
 * @throws IOException if I/O error was occurred
 */
public static boolean delete(File target, DeleteOption... options) throws IOException {
    if (target.exists() == false) {
        return true;
    }
    Set<DeleteOption> opts = EnumSet.noneOf(DeleteOption.class);
    Collections.addAll(opts, options);
    if (opts.contains(DeleteOption.QUIET)) {
        return FileUtils.deleteQuietly(target);
    } else {
        FileUtils.forceDelete(target);
        return true;
    }
}

From source file:com.vmware.identity.openidconnect.common.ResponseType.java

public static ResponseType parse(String responseTypeString) throws ParseException {
    Validate.notEmpty(responseTypeString, "responseTypeString");

    Set<ResponseTypeValue> valueSet = new HashSet<ResponseTypeValue>();
    String[] parts = responseTypeString.split(" ");
    for (String part : parts) {
        ResponseTypeValue value = ResponseTypeValue.parse(part);
        valueSet.add(value);//w  w w  .  j a  va2s.  c o  m
    }

    ResponseType result;
    if (valueSet.size() == 1 && valueSet.contains(ResponseTypeValue.AUTHORIZATION_CODE)) {
        result = ResponseType.authorizationCode();
    } else if (valueSet.size() == 1 && valueSet.contains(ResponseTypeValue.ID_TOKEN)) {
        result = ResponseType.idToken();
    } else if (valueSet.size() == 2 && valueSet.contains(ResponseTypeValue.ID_TOKEN)
            && valueSet.contains(ResponseTypeValue.ACCESS_TOKEN)) {
        result = ResponseType.idTokenAccessToken();
    } else {
        throw new ParseException(ErrorObject.unsupportedResponseType("unsupported response_type"));
    }
    return result;
}

From source file:de.se_rwth.langeditor.util.Misc.java

public static <T> void traverse(T root, Function<T, Collection<? extends T>> childGenerator,
        Consumer<? super T> enter, Consumer<? super T> exit) {

    Set<T> previouslyVisited = new HashSet<>();
    Stack<T> yetToVisit = new Stack<>();
    yetToVisit.push(root);//from w  ww . j a v  a  2 s. com

    T nextElement;
    while (!yetToVisit.isEmpty()) {
        nextElement = yetToVisit.peek();
        if (!previouslyVisited.contains(nextElement)) {
            enter.accept(nextElement);
            previouslyVisited.add(nextElement);
            yetToVisit.addAll(childGenerator.apply(nextElement));
        } else {
            exit.accept(yetToVisit.pop());
        }
    }
}

From source file:Main.java

/**
 * Get the elements who's tags match those passed in. 
 * @param nodeList - the node list in which to look for elements 
 * @param tags - the tags to match (empty returns all elements).
 * @return The elements that matched.//from www. j  a v  a  2s .c  om
 */
public static List<Element> getElements(NodeList nodeList, String... tags) {
    int nNodes = nodeList.getLength();
    List<Element> elements = new ArrayList<Element>(nNodes);

    Set<String> tagSet = new HashSet<String>(tags.length);
    for (String tag : tags) {
        tagSet.add(tag);
    }
    for (int i = 0; i < nNodes; ++i) {
        Node node = nodeList.item(i);
        if (node instanceof Element) {
            Element element = (Element) node;
            String tagName = element.getTagName();
            if (tagSet.isEmpty() || tagSet.contains(tagName)) {
                elements.add(element);
            }
        }
    }
    return elements;
}

From source file:juicebox.tools.utils.juicer.arrowhead.BlockBuster.java

/**
 * Set difference - returns the high scores in longerList that are not in shorterList.
 *
 * @param listA/*from  w ww. ja va 2  s  . c o  m*/
 * @param listB
 * @return set difference
 */
private static List<HighScore> orderedSetDifference(List<HighScore> listA, List<HighScore> listB) {
    // remove duplicates
    Set<HighScore> setA = new HashSet<HighScore>(listA);
    Set<HighScore> setB = new HashSet<HighScore>(listB);

    List<HighScore> diffSet = new ArrayList<HighScore>();
    for (HighScore score : setA) {
        if (!setB.contains(score)) {
            diffSet.add(score);
        }
    }

    return diffSet;
}

From source file:com.github.javarch.jsf.tags.security.SpringSecurityELLibrary.java

/**
 * Method that checks if the user holds <b>any</b> of the given roles.
 * Returns <code>true, when the first match is found, <code>false</code> if no match is found and
 * also <code>false</code> if no roles are given
 *
 * @param grantedRoles a comma seperated list of roles
 * @return true if any of the given roles are granted to the current user, false otherwise
 *///from w  ww.  ja  va 2 s.c o  m
public static boolean ifAnyGranted(final String grantedRoles) {
    Set<String> parsedAuthorities = parseAuthorities(grantedRoles);
    if (parsedAuthorities.isEmpty())
        return false;

    GrantedAuthority[] authorities = getUserAuthorities();

    for (GrantedAuthority authority : authorities) {
        if (parsedAuthorities.contains(authority.getAuthority()))
            return true;
    }
    return false;
}