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:com.viafirma.oauth.jersey.api.security.OAuthRequestFilter.java

private static boolean supportedOAuthParam(String value, Set<String> set) throws ApiException {
    if (!set.contains(value)) {
        return false;
    }// w w w . j  a  v a 2s. c o  m
    return true;
}

From source file:org.messic.server.facade.security.AuthenticationSessionManager.java

/**
 * @param token the session token//from  w w  w  . ja  v a 2 s . com
 * @param role the role to search for
 * @return true if the auth connected to the token has the given role
 */
public static boolean hasRole(String token, String role) {
    Set<String> auth = getRoles(token);
    return (auth != null && auth.contains(role));
}

From source file:com.minlia.cloud.framework.common.security.SpringSecurityUtil.java

/**
 * Check if current user has any role of specified.
 *
 * @param privileges/*from   w  w w .j  a  v a 2 s. c  om*/
 *            the array of roles.
 * @return true if has any role, otherwise false.
 */
public static boolean hasAnyPrivilege(final String... privileges) {
    final UserDetails userDetails = SpringSecurityUtil.getCurrentUserDetails();
    if (userDetails != null) {
        final Set<String> rolesSet = ImmutableSet.copyOf(privileges);
        for (final GrantedAuthority each : userDetails.getAuthorities()) {
            if (rolesSet.contains(each.getAuthority())) {
                return true;
            }
        }
    }

    return false;
}

From source file:ddf.catalog.transformer.csv.common.CsvTransformer.java

/**
 * Given a list of {@link Metacard}s and a string set of requested attributes, returns a set of
 * {@link AttributeDescriptor}s containing the requested attributes.
 *//*from www.j av a  2 s.  c o m*/
public static Set<AttributeDescriptor> getOnlyRequestedAttributes(final List<Metacard> metacards,
        final Set<String> requestedAttributes) {
    final Set<AttributeDescriptor> attributes = getAllCsvAttributeDescriptors(metacards);

    // Filter out attributes not requested.
    attributes.removeIf(attrDesc -> !requestedAttributes.contains(attrDesc.getName()));

    return attributes;
}

From source file:ezbake.deployer.impl.Files.java

public static int convertPosixFilePermissionsToTarArchiveEntryMode(Set<PosixFilePermission> permissions) {
    BitSet mode = new BitSet();

    if (permissions.contains(PosixFilePermission.OTHERS_EXECUTE)) {
        mode.set(PosixFilePermission.OTHERS_EXECUTE.ordinal());
    }//from   w w w  . j a v  a 2s.  c  om
    if (permissions.contains(PosixFilePermission.OTHERS_WRITE)) {
        mode.set(PosixFilePermission.OTHERS_WRITE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OTHERS_READ)) {
        mode.set(PosixFilePermission.OTHERS_READ.ordinal());
    }
    if (permissions.contains(PosixFilePermission.GROUP_EXECUTE)) {
        mode.set(PosixFilePermission.GROUP_EXECUTE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.GROUP_WRITE)) {
        mode.set(PosixFilePermission.GROUP_WRITE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.GROUP_READ)) {
        mode.set(PosixFilePermission.GROUP_READ.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OWNER_EXECUTE)) {
        mode.set(PosixFilePermission.OWNER_EXECUTE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OWNER_WRITE)) {
        mode.set(PosixFilePermission.OWNER_WRITE.ordinal());
    }
    if (permissions.contains(PosixFilePermission.OWNER_READ)) {
        mode.set(PosixFilePermission.OWNER_READ.ordinal());
    }

    return (int) mode.toLongArray()[0];
}

From source file:edu.umd.umiacs.clip.tools.scor.WordVectorUtils.java

public static void subset(String input, String output, Set<String> words, boolean loadOldVectorToMemory) {
    Set<String> allWords = new HashSet<>(words);
    allWords.add("</s>");
    List<String> lines = new ArrayList<>();
    (loadOldVectorToMemory ? readAllLines(input).parallelStream() : lines(input)).filter(line -> {
        String[] fields = line.split(" ");
        return fields.length > 2 && allWords.contains(fields[0]);
    }).forEach(lines::add);//from   w  w w .  j  av  a 2 s .  com
    lines.add(0, lines.size() + " " + (lines.get(0).split(" ").length - 1));
    write(output, lines, REMOVE_OLD_FILE);
}

From source file:Main.java

/**
 * Produce a new set// w  w  w  .  j  ava2  s . com
 * @param <T>
 * @param set1
 * @param set2
 * @return 
 */
public static <T> Set<T> intersect(Set<T> set1, Set<T> set2) {
    Set<T> a;
    Set<T> b;

    if (set1.size() <= set2.size()) {
        a = set1;
        b = set2;
    } else {
        a = set2;
        b = set1;
    }
    Set<T> intersection = new HashSet<>(a.size() * 4 / 3);
    for (T e : a) {
        if (b.contains(e)) {
            intersection.add(e);
        }
    }
    return intersection;
}

From source file:com.microsoft.tfs.core.clients.favorites.IdentityFavoritesStore.java

/**
 * Helper to clean up child entries in case a parent gets deleted
 *///  w w  w.  ja va  2s  .  c o  m
private static boolean fixTree(final FavoriteItem item, final Map<GUID, FavoriteItem> items,
        final Set<GUID> itemsToDelete) {
    boolean result = false;

    if (itemsToDelete.contains(item.getID())) {
        return result;
    }

    if (GUID.EMPTY.equals(item.getParentID())) {
        result = true;
    } else if (items.containsKey(item.getParentID())) {
        result = fixTree(items.get(item.getParentID()), items, itemsToDelete);
    }

    if (!result) {
        itemsToDelete.add(item.getID());
    }

    return result;
}

From source file:de.bund.bfr.knime.pmmlite.core.PmmUtils.java

public static <V extends Identifiable> List<V> getById(List<V> identifiables, Set<String> ids) {
    return identifiables.stream().filter(i -> ids.contains(i.getId())).collect(Collectors.toList());
}

From source file:gr.abiss.calipso.util.UserUtils.java

public static List<User> filterUsersAbleToTransitionFrom(List<UserSpaceRole> userSpaceRoles, Space space,
        int state, boolean uniqueUsers) {
    Set<String> set = space.getMetadata().getRolesAbleToTransitionFrom(state);
    List<User> list = new ArrayList<User>(userSpaceRoles.size());
    for (UserSpaceRole userSpaceRole : userSpaceRoles) {
        if (set.contains(userSpaceRole.getSpaceRole().getRoleCode())) {
            if (!list.contains(userSpaceRole.getUser())) {//must use unique users so check if a user is in the list
                list.add(userSpaceRole.getUser());
            }//from w  ww  .  j av a2  s. co  m
        }
    }
    return list;
}