Example usage for java.util LinkedHashSet addAll

List of usage examples for java.util LinkedHashSet addAll

Introduction

In this page you can find the example usage for java.util LinkedHashSet addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.CubaGroupTable.java

@Override
protected LinkedHashSet<Object> getItemIdsInRange(Object startItemId, final int length) {
    Set<Object> rootIds = super.getItemIdsInRange(startItemId, length);
    LinkedHashSet<Object> ids = new LinkedHashSet<>();
    for (Object itemId : rootIds) {
        if (itemId instanceof GroupInfo) {
            if (!isExpanded(itemId)) {
                Collection<?> itemIds = getGroupItemIds(itemId);
                ids.addAll(itemIds);
                expand(itemId, true);//from  w w w  .  j a va 2  s . c  o m
            }

            List<GroupInfo> children = (List<GroupInfo>) getChildren(itemId);
            for (GroupInfo groupInfo : children) {
                if (!isExpanded(groupInfo)) {
                    expand(groupInfo, true);
                }
            }
        } else {
            ids.add(itemId);
        }
    }
    return ids;
}

From source file:net.sourceforge.sqlexplorer.connections.ConnectionsView.java

/**
 * Returns a list of selected Users; if recurse is true, indirectly selected users are included also (eg a session's
 * user)//from   w  w  w . j a v a 2  s  .co m
 * 
 * @param recurse
 * @return Set of Users, never returns null
 */
public Set<User> getSelectedUsers(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_USERS;
    }

    LinkedHashSet<User> result = new LinkedHashSet<User>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof User) {
            result.add((User) obj);
        } else if (recurse) {
            if (obj instanceof Alias) {
                Alias alias = (Alias) obj;
                result.addAll(alias.getUsers());
            } else if (obj instanceof SQLConnection) {
                SQLConnection connection = (SQLConnection) obj;
                result.add(connection.getUser());
            }
        }
    }

    return result;
}

From source file:com.datatorrent.stram.StramClient.java

public static LinkedHashSet<String> findJars(LogicalPlan dag, Class<?>[] defaultClasses) {
    List<Class<?>> jarClasses = new ArrayList<Class<?>>();

    for (String className : dag.getClassNames()) {
        try {/*  w  ww  . jav a 2s.c  om*/
            Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
            jarClasses.add(clazz);
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Failed to load class " + className, e);
        }
    }

    for (Class<?> clazz : Lists.newArrayList(jarClasses)) {
        // process class and super classes (super does not require deploy annotation)
        for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass()) {
            //LOG.debug("checking " + c);
            jarClasses.add(c);
            jarClasses.addAll(Arrays.asList(c.getInterfaces()));
        }
    }

    jarClasses.addAll(Arrays.asList(defaultClasses));

    if (dag.isDebug()) {
        LOG.debug("Deploy dependencies: {}", jarClasses);
    }

    LinkedHashSet<String> localJarFiles = new LinkedHashSet<String>(); // avoid duplicates
    HashMap<String, String> sourceToJar = new HashMap<String, String>();

    for (Class<?> jarClass : jarClasses) {
        if (jarClass.getProtectionDomain().getCodeSource() == null) {
            // system class
            continue;
        }
        String sourceLocation = jarClass.getProtectionDomain().getCodeSource().getLocation().toString();
        String jar = sourceToJar.get(sourceLocation);
        if (jar == null) {
            // don't create jar file from folders multiple times
            jar = JarFinder.getJar(jarClass);
            sourceToJar.put(sourceLocation, jar);
            LOG.debug("added sourceLocation {} as {}", sourceLocation, jar);
        }
        if (jar == null) {
            throw new AssertionError("Cannot resolve jar file for " + jarClass);
        }
        localJarFiles.add(jar);
    }

    String libJarsPath = dag.getValue(LogicalPlan.LIBRARY_JARS);
    if (!StringUtils.isEmpty(libJarsPath)) {
        String[] libJars = StringUtils.splitByWholeSeparator(libJarsPath, LIB_JARS_SEP);
        localJarFiles.addAll(Arrays.asList(libJars));
    }

    LOG.info("Local jar file dependencies: " + localJarFiles);

    return localJarFiles;
}

From source file:org.tdar.core.service.ReflectionService.java

/**
 * Find all @link BulkImportField annotations on all resource classes.
 * //from   w  ww . ja va  2  s . co m
 * @param class2
 * @param stack
 * @param prefix
 * @return
 */
public LinkedHashSet<CellMetadata> findBulkAnnotationsOnClass(Class<?> class2, Stack<List<Class<?>>> stack,
        String prefix) {
    Class<BulkImportField> annotationToFind = BulkImportField.class;
    LinkedHashSet<CellMetadata> set = new LinkedHashSet<>();
    if (class2.getSuperclass() != Object.class) {
        set.addAll(findBulkAnnotationsOnClass(class2.getSuperclass(), stack, prefix));
    }

    Field runMultiple = null;
    List<Class<?>> runWith = new ArrayList<Class<?>>();
    for (Field field : class2.getDeclaredFields()) {
        BulkImportField annotation = field.getAnnotation(annotationToFind);
        if ((annotation != null) && ArrayUtils.isNotEmpty(annotation.implementedSubclasses())) {
            runWith.addAll(Arrays.asList(annotation.implementedSubclasses()));
            runMultiple = field;
        }
    }
    List<Class<?>> classList = new ArrayList<Class<?>>();
    stack.add(classList);
    classList.add(class2);

    if (runMultiple == null) {
        set.addAll(handleClassAnnotations(class2, stack, annotationToFind, null, null, prefix));
    } else {
        for (Class<?> runAs : runWith) {
            classList.add(runAs);
            set.addAll(handleClassAnnotations(class2, stack, annotationToFind, runAs, runMultiple, prefix));
            classList.remove(runAs);
        }
    }
    stack.remove(classList);
    return set;
}

From source file:starnubserver.connections.player.session.PlayerSession.java

public void loadPermissions() {
    Account account = playerCharacter.getAccount();
    LinkedHashSet<String> permissions = new LinkedHashSet<>();
    if (account == null) {
        GroupsManagement.getInstance().getGROUPS().values().stream()
                .filter(group -> group.getType().equalsIgnoreCase("noaccount")).forEach(group -> {
                    permissions.addAll(group.getGROUP_PERMISSIONS());
                });/*from  w ww. ja  va2  s . co  m*/
    } else {
        List<AccountPermission> accountPermissions = AccountPermission.getAccountPermissionsByAccount(account);
        permissions.addAll(
                accountPermissions.stream().map(AccountPermission::getPermission).collect(Collectors.toList()));
        TreeMap<Integer, Group> allGroups = account.getAllGroupsOrderedByRank();
        NavigableMap<Integer, Group> navigableMap = allGroups.descendingMap();
        for (Group group : navigableMap.values()) {
            permissions.addAll(group.getGROUP_PERMISSIONS());
        }
    }
    permissions.forEach(this::addPermissionToMap);
    System.out.println(PERMISSIONS);
}

From source file:com.soulgalore.crawler.core.impl.DefaultCrawler.java

/**
 * Get the urls./* www  .  j  a  v  a  2 s .  c o  m*/
 * 
 * @param configuration how to perform the crawl
 * @return the result of the crawl
 */
public CrawlerResult getUrls(CrawlerConfiguration configuration) {

    final Map<String, String> requestHeaders = configuration.getRequestHeadersMap();
    final HTMLPageResponse resp = verifyInput(configuration.getStartUrl(), configuration.getOnlyOnPath(),
            requestHeaders);

    int level = 0;

    final Set<CrawlerURL> allUrls = new LinkedHashSet<CrawlerURL>();
    final Set<HTMLPageResponse> verifiedUrls = new LinkedHashSet<HTMLPageResponse>();
    final Set<HTMLPageResponse> nonWorkingResponses = new LinkedHashSet<HTMLPageResponse>();

    verifiedUrls.add(resp);

    final String host = resp.getPageUrl().getHost();

    if (configuration.getMaxLevels() > 0) {

        // set the start url
        Set<CrawlerURL> nextToFetch = new LinkedHashSet<CrawlerURL>();
        nextToFetch.add(resp.getPageUrl());

        while (level < configuration.getMaxLevels()) {

            final Map<Future<HTMLPageResponse>, CrawlerURL> futures = new HashMap<Future<HTMLPageResponse>, CrawlerURL>(
                    nextToFetch.size());

            for (CrawlerURL testURL : nextToFetch) {
                futures.put(service.submit(
                        new HTMLPageResponseCallable(testURL, responseFetcher, true, requestHeaders, false)),
                        testURL);
            }

            nextToFetch = fetchNextLevelLinks(futures, allUrls, nonWorkingResponses, verifiedUrls, host,
                    configuration.getOnlyOnPath(), configuration.getNotOnPath());
            level++;
        }
    } else {
        allUrls.add(resp.getPageUrl());
    }

    if (configuration.isVerifyUrls())
        verifyUrls(allUrls, verifiedUrls, nonWorkingResponses, requestHeaders);

    LinkedHashSet<CrawlerURL> workingUrls = new LinkedHashSet<CrawlerURL>();
    for (HTMLPageResponse workingResponses : verifiedUrls) {
        workingUrls.add(workingResponses.getPageUrl());
    }

    // TODO find a better fix for this
    // wow, this is a hack to fix if the first URL is redirected,
    // then we want to keep that original start url
    if (workingUrls.size() >= 1) {
        List<CrawlerURL> list = new ArrayList<CrawlerURL>(workingUrls);
        list.add(0, new CrawlerURL(configuration.getStartUrl()));
        list.remove(1);
        workingUrls.clear();
        workingUrls.addAll(list);
    }

    return new CrawlerResult(configuration.getStartUrl(), configuration.isVerifyUrls() ? workingUrls : allUrls,
            verifiedUrls, nonWorkingResponses);

}

From source file:org.kitodo.production.model.bibliography.course.Course.java

/**
 * The function getIndividualIssues() generates a list of IndividualIssue
 * objects, each of them representing a stamping of one physically appeared
 * issue./*from   w  ww.  j  a v a  2s  . c o  m*/
 *
 * @return a LinkedHashSet of IndividualIssue objects, each of them
 *         representing one physically appeared issue
 */
public Set<IndividualIssue> getIndividualIssues() {
    LinkedHashSet<IndividualIssue> result = new LinkedHashSet<>();
    LocalDate lastAppearance = getLastAppearance();
    LocalDate firstAppearance = getFirstAppearance();
    if (Objects.nonNull(firstAppearance)) {
        for (LocalDate day = firstAppearance; !day.isAfter(lastAppearance); day = day.plusDays(1)) {
            for (Block block : this) {
                result.addAll(block.getIndividualIssues(day));
            }
        }
    }
    return result;
}

From source file:ca.sqlpower.object.SPVariableHelper.java

public Collection<Object> resolveCollection(String key, Object defaultValue) {

    LinkedHashSet<Object> results = new LinkedHashSet<Object>();
    String namespace = getNamespace(key);

    try {//from ww w  .j  a v  a 2s .  c om
        if (namespace != null) {
            List<SPVariableResolver> resolvers = SPResolverRegistry.getResolvers(this.contextSource, namespace);
            for (SPVariableResolver resolver : resolvers) {
                if (resolver.resolves(key)) {
                    results.addAll(resolver.resolveCollection(key));
                    if (!globalCollectionResolve) {
                        break;
                    }
                }
            }
        } else {
            SPObject node = this.contextSource;
            while (true) {
                if (node instanceof SPVariableResolverProvider) {
                    SPVariableResolver resolver = ((SPVariableResolverProvider) node).getVariableResolver();
                    if (resolver.resolves(key)) {
                        results.addAll(resolver.resolveCollection(key));
                        if (!globalCollectionResolve) {
                            break;
                        }
                    }
                }
                node = node.getParent();
                if (node == null)
                    break;
            }
        }

        if (results.size() == 0) {
            if (defaultValue == null) {
                return Collections.emptySet();
            } else {
                return Collections.singleton(defaultValue);
            }
        } else {
            return results;
        }
    } catch (StackOverflowError soe) {
        throw new RecursiveVariableException();
    }

}

From source file:net.sourceforge.sqlexplorer.connections.ConnectionsView.java

/**
 * Returns a list of selected sessions; if recurse is true, then it includes indirectly selected sessions (eg a
 * selected user's sessions)//from  w ww .  ja  va  2  s  .  c  o  m
 * 
 * @param recurse
 * @return Set of Sessions, never returns null
 */
public Set<SQLConnection> getSelectedConnections(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_CONNECTIONS;
    }

    LinkedHashSet<SQLConnection> result = new LinkedHashSet<SQLConnection>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof SQLConnection) {
            result.add((SQLConnection) obj);
        } else if (recurse) {
            if (obj instanceof Alias) {
                Alias alias = (Alias) obj;
                for (User user : alias.getUsers()) {
                    result.addAll(user.getConnections());
                }
            } else if (obj instanceof User) {
                User user = (User) obj;
                result.addAll(user.getConnections());
            }
        }
    }

    return result;
}