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:org.alfresco.bm.dataload.RMBaseEventProcessor.java

/**
 * Obtains all record folders underneath specified parent if the parent is a category or the parent itself if it is a record folder
 *
 * @param parentFolder - the parent folder to retrieve children folders from
 * @return all record folders underneath specified parent if the parent is a category or the parent itself if it is a record folder
 *///from  w  ww .j  a va 2  s . c o m
protected Set<FolderData> getRecordFolders(FolderData parentFolder) {
    LinkedHashSet<FolderData> result = new LinkedHashSet<FolderData>();
    String context = parentFolder.getContext();
    if (RECORD_CATEGORY_CONTEXT.equals(context)) {
        List<FolderData> directCategoryChildren = getDirectChildrenByContext(parentFolder,
                RECORD_CATEGORY_CONTEXT);
        if (directCategoryChildren.size() > 0) {
            for (FolderData childFolder : directCategoryChildren) {
                result.addAll(getRecordFolders(childFolder));
            }
        }

        List<FolderData> directRecordFolderChildren = getDirectChildrenByContext(parentFolder,
                RECORD_FOLDER_CONTEXT);
        if (directRecordFolderChildren.size() > 0) {
            result.addAll(directRecordFolderChildren);
        }
    } else if (RECORD_FOLDER_CONTEXT.equals(context)) {
        result.add(parentFolder);
    }
    return result;
}

From source file:org.broadinstitute.gatk.utils.commandline.ParsingEngine.java

/**
 * Gets a collection of the container instances of the given type stored within the given target.
 * @param source Argument source.//from  w  ww.ja  v  a 2 s  .c  om
 * @param instance Container.
 * @return A collection of containers matching the given argument source.
 */
private Collection<Object> findTargets(ArgumentSource source, Object instance) {
    LinkedHashSet<Object> targets = new LinkedHashSet<Object>();
    for (Class clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
        for (Field field : clazz.getDeclaredFields()) {
            if (field.equals(source.field)) {
                targets.add(instance);
            } else if (field.isAnnotationPresent(ArgumentCollection.class)) {
                targets.addAll(findTargets(source, JVMUtils.getFieldValue(field, instance)));
            }
        }
    }
    return targets;
}

From source file:com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.java

@SuppressWarnings("unchecked")
public void replaceItem(T item) {
    checkNotNullArgument(item, "item is null");
    Collection<T> collection = getCollection();
    if (collection != null) {
        for (T t : collection) {
            if (t.equals(item)) {
                detachListener(t);// w w  w. jav  a  2s  .  co  m
                if (collection instanceof List) {
                    List list = (List) collection;
                    int itemIdx = list.indexOf(t);
                    list.set(itemIdx, item);
                } else if (collection instanceof LinkedHashSet) {
                    LinkedHashSet set = (LinkedHashSet) collection;

                    List list = new ArrayList(set);
                    int itemIdx = list.indexOf(t);
                    list.set(itemIdx, item);

                    set.clear();
                    set.addAll(list);
                } else {
                    collection.remove(t);
                    collection.add(item);
                }
                attachListener(item);

                if (item.equals(this.item)) {
                    this.item = item;
                }
                break;
            }
        }
        if (sortInfos != null)
            doSort();

        fireCollectionChanged(Operation.UPDATE, Collections.singletonList(item));
    }
}

From source file:org.topazproject.otm.impl.SessionFactoryImpl.java

public LinkedHashSet<SubClassResolver> listEffectiveSubClassResolvers(String entity) {
    LinkedHashSet<SubClassResolver> resolvers = new LinkedHashSet<SubClassResolver>();
    gatherSub(entity, resolvers);/*from  ww w .  java2s.c o m*/
    gatherSup(entity, resolvers);
    // add the root as the last
    Set<SubClassResolver> r = subClassResolvers.get(null);
    if (r != null)
        resolvers.addAll(r);
    return resolvers;
}

From source file:org.starnub.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  w w  .ja v  a2  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);
}

From source file:org.topazproject.otm.impl.SessionFactoryImpl.java

private void gatherSub(String entity, LinkedHashSet<SubClassResolver> resolvers) {
    Set<ClassMetadata> subs = subClasses.get(entity);
    if (subs != null)
        for (ClassMetadata cm : subClasses.get(entity))
            gatherSub(cm.getName(), resolvers);

    Set<SubClassResolver> r = subClassResolvers.get(entity);
    if (r != null)
        resolvers.addAll(r);
}

From source file:org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.AbstractMDXDataFactory.java

public String[] getReferencedFields(final String queryName, final DataRow parameters)
        throws ReportDataFactoryException {
    final boolean isNewConnection = connection == null;
    try {// w  w  w . j  a  v a2 s.  co m
        if (connection == null) {
            connection = mondrianConnectionProvider.createConnection(computeProperties(parameters),
                    dataSourceProvider.getDataSource());
        }
    } catch (SQLException e) {
        logger.error(e);
        throw new ReportDataFactoryException("Failed to create DataSource (SQL Exception - error code: "
                + e.getErrorCode() + "):" + e.toString(), e);
    } catch (MondrianException e) {
        logger.error(e);
        throw new ReportDataFactoryException("Failed to create DataSource (Mondrian Exception):" + e.toString(),
                e);
    }

    try {
        if (connection == null) {
            throw new ReportDataFactoryException("Factory is closed.");
        }
        final LinkedHashSet<String> parameter = new LinkedHashSet<String>();

        final MDXCompiler compiler = new MDXCompiler(parameters, getLocale());
        final String computedQuery = computedQuery(queryName, parameters);
        final String mdxQuery = compiler.translateAndLookup(computedQuery, parameters);
        parameter.addAll(compiler.getCollectedParameter());
        // Alternatively, JNDI is possible. Maybe even more ..
        final Query query = connection.parseQuery(mdxQuery);
        final Parameter[] queryParameters = query.getParameters();
        for (int i = 0; i < queryParameters.length; i++) {
            final Parameter queryParameter = queryParameters[i];
            parameter.add(queryParameter.getName());
        }
        if (jdbcUserField != null) {
            parameter.add(jdbcUserField);
        }
        if (roleField != null) {
            parameter.add(roleField);
        }
        parameter.add(DataFactory.QUERY_LIMIT);
        return parameter.toArray(new String[parameter.size()]);
    } catch (MondrianException e) {
        throw new ReportDataFactoryException("Failed to create datasource:" + e.getLocalizedMessage(), e);
    } finally {
        if (isNewConnection) {
            close();
        }
    }
}

From source file:org.dozer.MappingProcessor.java

private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) {
    // create a list here so we can keep track of which elements we have mapped, and remove all others if removeOrphans = true
    Set<Object> mappedElements = new HashSet<Object>();

    LinkedHashSet<Object> result = new LinkedHashSet<Object>();
    // don't want to create the set if it already exists.
    Object field = fieldMap.getDestValue(destObj);
    if (field != null) {
        result.addAll((Collection<?>) field);
    }/*from w  w  w  .  j a  v a  2s.  com*/
    Object destValue;

    Class<?> destEntryType = null;
    Class<?> prevDestEntryType = null;
    for (Object srcValue : srcCollectionValue) {
        if (destEntryType == null || (fieldMap.getDestHintContainer() != null
                && fieldMap.getDestHintContainer().hasMoreThanOneHint())) {
            destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType);
        }

        CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences();
        if (srcValue != null && copyByReferences.contains(srcValue.getClass())) {
            destValue = srcValue;
        } else {
            destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj);
        }
        prevDestEntryType = destEntryType;

        if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType())
                && result.contains(destValue)) {
            List<Object> resultAsList = new ArrayList<Object>(result);
            int index = resultAsList.indexOf(destValue);
            // perform an update if complex type - can't map strings
            Object obj = resultAsList.get(index);
            // make sure it is not a String
            if (!obj.getClass().isAssignableFrom(String.class)) {
                mapToDestObject(null, srcValue, obj, false, null);
                mappedElements.add(obj);
            }
        } else {
            if (destValue != null || fieldMap.isDestMapNull()) {
                result.add(destValue);
            }
            mappedElements.add(destValue);
        }
    }

    // If remove orphans - we only want to keep the objects we've mapped from the src collection
    // so we'll clear result and replace all entries with the ones in mappedElements
    if (fieldMap.isRemoveOrphans()) {
        result.clear();
        result.addAll(mappedElements);
    }

    if (field == null) {
        Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap
                .getDestFieldType(destObj.getClass());
        return CollectionUtils.createNewSet(destSetType, result);
    } else {
        // Bug #1822421 - Clear first so we don't end up with the removed orphans again
        ((Set) field).clear();
        ((Set) field).addAll(result);
        return (Set<?>) field;
    }
}

From source file:com.geewhiz.pacify.managers.FilterManager.java

private LinkedHashSet<Defect> filterPArchive(PArchive pArchive) {
    logger.info("      Customize Archive [{}]", pArchive.getRelativePath());

    LinkedHashSet<Defect> defects = new LinkedHashSet<Defect>();

    Map<PFile, File> replaceFiles = new HashMap<PFile, File>();

    for (PFile pFile : pArchive.getPFiles()) {
        logger.info("         Customize File [{}]", pFile.getRelativePath());
        logger.debug("             Filtering [{}] in archive [{}] using encoding [{}] and filter [{}]",
                pFile.getRelativePath(), pMarker.getAbsoluteFileFor(pArchive).getAbsolutePath(),
                pFile.getEncoding(), pFile.getFilterClass());

        File fileToFilter = extractFile(pArchive, pFile);
        PacifyFilter pacifyFilter = getFilterForPFile(pArchive, pFile);

        Map<String, String> propertyValues = new HashMap<String, String>();
        LinkedHashSet<Defect> propertyValueDefects = fillPropertyValuesFor(propertyValues, pFile);
        if (propertyValueDefects.size() > 0) {
            return propertyValueDefects;
        }//from   w  w  w .  j a v a 2s .c  om

        String beginToken = pMarker.getBeginTokenFor(pArchive, pFile);
        String endToken = pMarker.getEndTokenFor(pArchive, pFile);
        String encoding = pFile.getEncoding();

        defects.addAll(pacifyFilter.filter(propertyValues, beginToken, endToken, fileToFilter, encoding));

        replaceFiles.put(pFile, fileToFilter);
        logger.info("             [{}] placeholders replaced.", pFile.getPProperties().size());
    }

    try {
        FileUtils.replaceFilesInArchive(pMarker, pArchive, replaceFiles);
    } catch (ArchiveDefect e) {
        defects.add(e);
    }

    for (Entry<PFile, File> entry : replaceFiles.entrySet()) {
        entry.getValue().delete();
    }

    return defects;
}

From source file:org.apache.maven.plugin.resources.remote.ProcessRemoteResourcesMojo.java

private MavenFileFilterRequest setupRequest(Resource resource, File source, File file) {
    MavenFileFilterRequest req = new MavenFileFilterRequest();
    req.setFrom(source);// ww w . ja  va  2 s .  co  m
    req.setTo(file);
    req.setFiltering(resource.isFiltering());

    req.setMavenProject(project);
    req.setMavenSession(mavenSession);
    req.setInjectProjectBuildFilters(true);

    if (encoding != null) {
        req.setEncoding(encoding);
    }

    if (filterDelimiters != null && !filterDelimiters.isEmpty()) {
        LinkedHashSet<String> delims = new LinkedHashSet<String>();
        if (useDefaultFilterDelimiters) {
            delims.addAll(req.getDelimiters());
        }

        for (String delim : filterDelimiters) {
            if (delim == null) {
                delims.add("${*}");
            } else {
                delims.add(delim);
            }
        }

        req.setDelimiters(delims);
    }

    return req;
}