Example usage for java.util Set add

List of usage examples for java.util Set add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:Main.java

/**
 * Produce a new set//from   ww  w  . j  a  v  a 2 s . c  om
 * @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.kurtraschke.nyctrtproxy.ProxyModule.java

public static void addModuleAndDependencies(Set<Module> modules) {
    GtfsRealtimeExporterModule.addModuleAndDependencies(modules);
    JSR250Module.addModuleAndDependencies(modules);
    modules.add(new ProxyModule());
}

From source file:com.netflix.genie.client.sample.CommandServiceSampleClient.java

/**
 * Create a sample command and attach the the supplied applications.
 *
 * @param id The id to use or null if want one created.
 * @return The pig example command/*from   w ww. j  a v  a2 s .  c  om*/
 * @throws GenieException On configuration issue.
 */
public static Command createSampleCommand(final String id) throws GenieException {
    final Command command = new Command(CMD_NAME, "tgianos", CMD_VERSION, CommandStatus.ACTIVE,
            "/apps/pig/0.13/bin/pig");
    if (StringUtils.isNotBlank(id)) {
        command.setId(id);
    }
    command.setEnvPropFile("s3:/mybucket/envFile.sh");
    command.setVersion("0.13");

    final Set<String> tags = new HashSet<>();
    tags.add("tag0");
    command.setTags(tags);
    return command;
}

From source file:net.landora.video.filestate.DirectoryUUIDChecker.java

public static void setUUID(File directory, String uuid) {
    try {/*from   w w  w .j  ava 2s. com*/
        File uuidFile = new File(directory, UUID_FILE);
        Set<String> uuids = new LinkedHashSet<String>();

        if (uuidFile.exists()) {
            uuids.addAll(FileUtils.readLines(uuidFile));
        }
        uuids.add(uuid);
        FileUtils.writeLines(uuidFile, uuids);
    } catch (Exception e) {
        log.error("Error adding directory uuid: " + directory, e);

    }
}

From source file:net.maritimecloud.endorsement.controllers.TokenGenerator.java

/**
 * Helper function of build fake KeycloakAuthenticationToken
 * @param orgMrn/*from w  w  w  .  ja  v  a 2  s  . c om*/
 * @param roles
 * @param permissions
 * @return
 */
public static KeycloakAuthenticationToken generateKeycloakToken(String orgMrn, String roles,
        String permissions) {
    AccessToken accessToken = new AccessToken();
    if (orgMrn != null && !orgMrn.isEmpty()) {
        accessToken.setOtherClaims(AccessControlUtil.ORG_PROPERTY_NAME, orgMrn);
    }
    if (permissions != null && !permissions.isEmpty()) {
        accessToken.setOtherClaims(AccessControlUtil.PERMISSIONS_PROPERTY_NAME, permissions);
    }
    RefreshableKeycloakSecurityContext ksc = new RefreshableKeycloakSecurityContext(null, null,
            "accessTokenString", accessToken, "idTokenString", null, "refreshTokenString");
    Set<String> rolesSet = new HashSet<>();
    String[] roleArr = roles.split(",");
    for (String role : roleArr) {
        rolesSet.add(role.trim());
    }
    KeycloakPrincipal<RefreshableKeycloakSecurityContext> principal = new KeycloakPrincipal<>("name", ksc);
    SimpleKeycloakAccount account = new SimpleKeycloakAccount(principal, rolesSet, ksc);
    Collection<GrantedAuthority> authorities = generateGrantedAuthority(roles);
    return new KeycloakAuthenticationToken(account, authorities);
}

From source file:ch.ifocusit.plantuml.utils.ClassUtils.java

public static Set<Class> getConcernedTypes(Method method) {
    Set<Class> classes = new HashSet<>();
    // manage returned types
    classes.add(method.getReturnType());
    classes.addAll(getGenericTypes(method));
    // manage parameters types
    for (Parameter parameter : method.getParameters()) {
        classes.addAll(getConcernedTypes(parameter));
    }//from   w w  w. j a  va2s. co m
    return classes;
}

From source file:com.qwazr.QwazrConfiguration.java

private static Set<String> buildGroups(Collection<String> groupCollection) {
    if (groupCollection == null || groupCollection.isEmpty())
        return null;
    Set<String> groups = new HashSet<>();
    groupCollection.forEach((g) -> groups.add(g.trim()));
    return groups;
}

From source file:Main.java

public static <K, V> Set<V> valueToTreeSet(Map<K, V> map) {
    if (isNotNull(map)) {
        Set<V> set = new TreeSet<>();
        for (V v : map.values()) {
            System.out.println(v.hashCode());
            System.out.println(set.contains(v));
            set.add(v);
        }/*from  w  w w  . j  ava  2s .co m*/
        return set;
    }
    return null;
}

From source file:Main.java

public static <T> Set<Set<T>> extractSubSets(Set<T> initialSet, int subSetSize) {
    int nbSources = initialSet.size();
    int expectedNumberOfSets = expectedNumberOfSets(nbSources, subSetSize);
    Set<Set<T>> setOfSets = new HashSet<>(expectedNumberOfSets);
    if (nbSources == subSetSize) {
        // Already OK
        setOfSets.add(initialSet);
        return setOfSets;
    }/*from  ww w.j  a v a  2 s .  c  o m*/
    List<T> setAsList = new ArrayList<>(initialSet);
    int[] iterators = new int[subSetSize];
    for (int i = 0; i < iterators.length; i++) {
        iterators[i] = i;
    }
    while (setOfSets.size() != expectedNumberOfSets) {
        HashSet<T> result = new HashSet<>(subSetSize);
        for (int pos : iterators) {
            result.add(setAsList.get(pos));
        }
        if (result.size() != subSetSize) {
            throw new IllegalStateException("Hard!");
        }
        setOfSets.add(result);
        int maxPos = -1;
        for (int i = 0; i < iterators.length; i++) {
            int pos = iterators[i];
            if (pos == (nbSources - iterators.length + i)) {
                maxPos = i;
                break;
            }
        }
        if (maxPos == -1) {
            // Up last iterator
            iterators[iterators.length - 1]++;
        } else if (maxPos == 0) {
            // Finished
            if (setOfSets.size() != expectedNumberOfSets) {
                System.err.println("Something wrong!");
            }
        } else {
            // Up the one before maxPos and reinit the others
            iterators[maxPos - 1]++;
            for (int i = maxPos; i < iterators.length; i++) {
                iterators[i] = iterators[i - 1] + 1;
            }
        }
    }
    return setOfSets;
}

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

public static <T> Set<T> asSet(Iterable<T> items) {
    Set<T> result = new HashSet<T>();
    for (T item : items) {
        result.add(item);
    }/*from   w  w w.jav  a  2  s. c  o  m*/
    return result;
}