Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

In this page you can find the example usage for java.util Set 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.tuplejump.stargate.cassandra.CassandraUtils.java

public static Options getOptions(Properties mapping, ColumnFamilyStore baseCfs, String colName) {
    Properties primary = mapping;
    String defaultField = colName;
    Map<String, NumericConfig> numericFieldOptions = new HashMap<>();
    Map<String, FieldType> fieldDocValueTypes = new TreeMap<>();
    Map<String, FieldType> collectionFieldDocValueTypes = new TreeMap<>();

    Map<String, FieldType> fieldTypes = new TreeMap<>();
    Map<String, FieldType[]> collectionFieldTypes = new TreeMap<>();
    Map<String, AbstractType> validators = new TreeMap<>();
    Map<Integer, Pair<String, ByteBuffer>> clusteringKeysIndexed = new LinkedHashMap<>();
    Map<Integer, Pair<String, ByteBuffer>> partitionKeysIndexed = new LinkedHashMap<>();
    Map<String, Analyzer> perFieldAnalyzers;
    Set<String> indexedColumnNames;

    //getForRow all the fields options.
    indexedColumnNames = new TreeSet<>();
    indexedColumnNames.addAll(mapping.getFields().keySet());

    Set<String> added = new HashSet<>(indexedColumnNames.size());
    List<ColumnDefinition> partitionKeys = baseCfs.metadata.partitionKeyColumns();
    List<ColumnDefinition> clusteringKeys = baseCfs.metadata.clusteringKeyColumns();

    for (ColumnDefinition colDef : partitionKeys) {
        String columnName = CFDefinition.definitionType.getString(colDef.name);
        if (Options.logger.isDebugEnabled()) {
            Options.logger.debug("Partition key name is {} and index is {}", colName, colDef.componentIndex);
        }//  w ww  . j a  v  a  2s. co  m
        validators.put(columnName, colDef.getValidator());
        if (indexedColumnNames.contains(columnName)) {
            int componentIndex = colDef.componentIndex == null ? 0 : colDef.componentIndex;
            partitionKeysIndexed.put(componentIndex, Pair.create(columnName, colDef.name));
            Properties properties = mapping.getFields().get(columnName.toLowerCase());
            addFieldType(columnName, colDef.getValidator(), properties, numericFieldOptions, fieldDocValueTypes,
                    collectionFieldDocValueTypes, fieldTypes, collectionFieldTypes);
            added.add(columnName.toLowerCase());
        }
    }

    for (ColumnDefinition colDef : clusteringKeys) {
        String columnName = CFDefinition.definitionType.getString(colDef.name);
        if (Options.logger.isDebugEnabled()) {
            Options.logger.debug("Clustering key name is {} and index is {}", colName,
                    colDef.componentIndex + 1);
        }
        validators.put(columnName, colDef.getValidator());
        if (indexedColumnNames.contains(columnName)) {
            clusteringKeysIndexed.put(colDef.componentIndex + 1, Pair.create(columnName, colDef.name));
            Properties properties = mapping.getFields().get(columnName.toLowerCase());
            addFieldType(columnName, colDef.getValidator(), properties, numericFieldOptions, fieldDocValueTypes,
                    collectionFieldDocValueTypes, fieldTypes, collectionFieldTypes);
            added.add(columnName.toLowerCase());
        }
    }

    for (String columnName : indexedColumnNames) {
        if (added.add(columnName.toLowerCase())) {
            Properties options = mapping.getFields().get(columnName);
            ColumnDefinition colDef = getColumnDefinition(baseCfs, columnName);
            if (colDef != null) {
                validators.put(columnName, colDef.getValidator());
                addFieldType(columnName, colDef.getValidator(), options, numericFieldOptions,
                        fieldDocValueTypes, collectionFieldDocValueTypes, fieldTypes, collectionFieldTypes);
            } else {
                throw new IllegalArgumentException(
                        String.format("Column Definition for %s not found", columnName));
            }
            if (options.getType() == Properties.Type.object) {
                mapping.getFields().putAll(options.getFields());
            }
        }

    }
    Set<ColumnDefinition> otherColumns = baseCfs.metadata.regularColumns();
    for (ColumnDefinition colDef : otherColumns) {
        String columnName = CFDefinition.definitionType.getString(colDef.name);
        validators.put(columnName, colDef.getValidator());
    }

    numericFieldOptions.putAll(primary.getDynamicNumericConfig());

    Analyzer defaultAnalyzer = mapping.getLuceneAnalyzer();
    perFieldAnalyzers = mapping.perFieldAnalyzers();
    Analyzer analyzer = new PerFieldAnalyzerWrapper(defaultAnalyzer, perFieldAnalyzers);
    Map<String, Properties.Type> types = new TreeMap<>();
    Set<String> nestedFields = new TreeSet<>();
    for (Map.Entry<String, AbstractType> entry : validators.entrySet()) {
        CQL3Type cql3Type = entry.getValue().asCQL3Type();
        AbstractType inner = getValueValidator(cql3Type.getType());
        if (cql3Type.isCollection()) {
            types.put(entry.getKey(), fromAbstractType(inner.asCQL3Type()));
            nestedFields.add(entry.getKey());
        } else {
            types.put(entry.getKey(), fromAbstractType(cql3Type));
        }

    }

    return new Options(primary, numericFieldOptions, fieldDocValueTypes, collectionFieldDocValueTypes,
            fieldTypes, collectionFieldTypes, types, nestedFields, clusteringKeysIndexed, partitionKeysIndexed,
            perFieldAnalyzers, indexedColumnNames, analyzer, defaultField);
}

From source file:com.amalto.core.storage.inmemory.InMemoryJoinResults.java

private static Set<Object> _evaluateConditions(Storage storage, InMemoryJoinNode node) {
    if (node.expression != null) {
        Set<Object> expressionIds = new HashSet<Object>();
        StorageResults results = storage.fetch(node.expression); // Expects an active transaction here
        try {// w ww  .ja  va 2s .c o  m
            for (DataRecord result : results) {
                for (FieldMetadata field : result.getSetFields()) {
                    expressionIds.add(result.get(field));
                }
            }
        } finally {
            results.close();
        }
        return expressionIds;
    } else {
        Executor executor = getExecutor(node);
        Set<Object> ids = new HashSet<Object>();
        switch (node.merge) {
        case UNION:
        case NONE:
            for (InMemoryJoinNode child : node.children.keySet()) {
                ids.addAll(executor.execute(storage, child));
            }
            break;
        case INTERSECTION:
            for (InMemoryJoinNode child : node.children.keySet()) {
                if (ids.isEmpty()) {
                    ids.addAll(executor.execute(storage, child));
                } else {
                    ids.retainAll(executor.execute(storage, child));
                }
            }
            break;
        default:
            throw new NotImplementedException("No support for '" + node.merge + "'.");
        }
        //
        Set<Object> returnIds = new HashSet<Object>();
        if (node.childProperty != null) {
            if (ids.isEmpty()) {
                return Collections.emptySet();
            }
            long execTime = System.currentTimeMillis();
            {
                UserQueryBuilder qb = from(node.type).selectId(node.type)
                        .where(buildConditionFromValues(null, node.childProperty, ids));
                node.expression = qb.getSelect();
                StorageResults results = storage.fetch(qb.getSelect()); // Expects an active transaction here
                try {
                    for (DataRecord result : results) {
                        for (FieldMetadata field : result.getSetFields()) {
                            returnIds.add(result.get(field));
                        }
                    }
                } finally {
                    results.close();
                }
            }
            node.execTime = System.currentTimeMillis() - execTime;
        }
        return returnIds;
    }
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

@SuppressWarnings("PMD.ExcessiveMethodLength")
private static void writeSampleSection(Hybridization h, PrintWriter out) {
    final Set<Source> sources = new TreeSet<Source>(ENTITY_COMPARATOR);
    final Set<Sample> samples = new TreeSet<Sample>(ENTITY_COMPARATOR);
    final Set<Extract> extracts = new TreeSet<Extract>(ENTITY_COMPARATOR);
    final Set<LabeledExtract> labeledExtracts = new TreeSet<LabeledExtract>(ENTITY_COMPARATOR);
    GeoSoftFileWriterUtil.collectBioMaterials(h, sources, samples, extracts, labeledExtracts);

    out.print("^SAMPLE=");
    out.println(h.getName());/*from www  . ja  v a 2  s  . co m*/
    out.print("!Sample_title=");
    out.println(h.getName());
    writeDescription(out, h, samples);
    writeData(h, out);
    writeSources(out, sources);
    writeOrganism(sources, samples, h.getExperiment(), out);
    final Set<ProtocolApplication> pas = new TreeSet<ProtocolApplication>(ENTITY_COMPARATOR);
    pas.addAll(h.getProtocolApplications());
    collectAllProtocols(labeledExtracts, pas);
    collectAllProtocols(extracts, pas);
    collectAllProtocols(samples, pas);
    collectAllProtocols(sources, pas);

    writeProtocol(pas, "Sample_treatment_protocol", PREDICATE_TREATMENT, out);
    writeProtocol(pas, "Sample_growth_protocol", PREDICATE_GROWTH, out);
    writeProtocol(pas, "Sample_extract_protocol", PREDICATE_EXTRACT, out);
    writeProtocol(getAllProtocols(extracts), "Sample_label_protocol", PREDICATE_LABELING, out);
    writeProtocol(getAllProtocols(labeledExtracts), "Sample_hyb_protocol", PREDICATE_HYB, out);
    writeProtocol(h.getProtocolApplications(), "Sample_scan_protocol", PREDICATE_SCAN, out);
    writeProtocolsForData(h.getRawDataCollection(), "Sample_data_processing", out);

    for (final LabeledExtract labeledExtract : labeledExtracts) {
        out.print("!Sample_label=");
        out.println(labeledExtract.getLabel().getValue());
    }
    writeProviders(sources, out);

    out.print("!Sample_platform_id=");
    out.println(h.getArray().getDesign().getGeoAccession());

    final Set<String> uniqueEntries = new HashSet<String>();
    for (final AbstractFactorValue fv : h.getFactorValues()) {
        writeCharacteristics(fv.getFactor().getName(), fv.getDisplayValue(), out, uniqueEntries);
    }
    writeCharacteristics(labeledExtracts, out, uniqueEntries);
    writeCharacteristics(extracts, out, uniqueEntries);
    writeCharacteristics(samples, out, uniqueEntries);
    writeCharacteristics(sources, out, uniqueEntries);

    writeMaterialTypes(extracts, labeledExtracts, out);
}

From source file:com.wineaccess.winery.WineryRepository.java

@SuppressWarnings("unchecked")
public static void updateWinery(WineryModel wineryModelTemp, WineryUpdatePO wineryUpdatePO) {

    GenericDAO<WineryModel> genericDao = (GenericDAO<WineryModel>) CoreBeanFactory.getBean("genericDAO");

    genericDao.update(wineryModelTemp);/*www. j  a va  2s .  com*/

    //WineryModel wineryModel = getWineryModelByWineryCode(wineryUpdatePO.getWineryCode());
    WineryModel wineryModel = getWineryById(wineryUpdatePO.getWineryId());

    GenericDAO<WineyImpoterModel> genericDao2 = (GenericDAO<WineyImpoterModel>) CoreBeanFactory
            .getBean("genericDAO");

    Set<ImporterModel> importerModels = wineryModel.getImporters();

    List<Long> importerIds = wineryUpdatePO.getImporterIds();

    if (importerIds == null) {
        importerIds = new ArrayList<Long>();
    }

    List<Long> existingImporterIds = new ArrayList<Long>();
    for (ImporterModel im : importerModels) {
        existingImporterIds.add(im.getId());
    }

    Set<Long> allids = new HashSet<Long>(existingImporterIds);
    allids.addAll(importerIds);
    List<Long> allidsList = new ArrayList<Long>(allids);

    for (Long importerId : allidsList) {

        WineyImpoterModel wineyImpoterModel = WineryRepository
                .getWineyImpoterModelByImporterIdAndWineryId(importerId, wineryModel.getId());

        if (wineyImpoterModel != null) {
            /*if(wineyImpoterModel.getIsDeleted())
            {
                       
            }
            else
            {*/
            if (importerIds.contains(wineyImpoterModel.getImporterId())) {
                //wineyImpoterModel.setIsActiveImpoter(true);
                if (wineyImpoterModel.getImporterId() == wineryUpdatePO.getActiveImporterId())
                    wineyImpoterModel.setIsActiveImpoter(true);

                wineyImpoterModel.setIsDeleted(false);
            } else {
                //wineyImpoterModel.setIsActiveImpoter(false);                  
                wineyImpoterModel.setIsDeleted(true);

                if (wineryModelTemp.getActiveImporterId() != null
                        && wineryModelTemp.getActiveImporterId().getId() == importerId) {
                    ImporterModel importerModel = ImporterRepository
                            .getImporterById(wineryUpdatePO.getActiveImporterId());
                    if (importerModel.getWineryCount() == 1) {
                        importerModel.setIsActive(false);
                        importerModel.setWineryCount(0L);
                        ImporterRepository.update(importerModel);
                    }

                }
            }
            genericDao2.update(wineyImpoterModel);
            //}

        } else {
            wineyImpoterModel = new WineyImpoterModel();

            wineyImpoterModel.setWineryId(wineryModel.getId());

            wineyImpoterModel.setImporterId(importerId);

            if (importerId == wineryUpdatePO.getActiveImporterId())
                wineyImpoterModel.setIsActiveImpoter(true);
            else
                wineyImpoterModel.setIsActiveImpoter(false);

            wineyImpoterModel.setIsDeleted(false);

            genericDao2.create(wineyImpoterModel);
        }

    }

}

From source file:com.wineaccess.winery.WineryRepository.java

@SuppressWarnings("unchecked")
public static void saveWinery(WineryModel wineryModelTemp, WineryPO wineryPO) {

    GenericDAO<WineryModel> genericDao = (GenericDAO<WineryModel>) CoreBeanFactory.getBean("genericDAO");

    wineryModelTemp = genericDao.update(wineryModelTemp);

    if (wineryModelTemp.getId() != null) {
        try {/*from ww  w. j  av a2 s. c o m*/

            Set<MasterData> wineryPermitMasterDataList = MasterDataTypeAdapterHelper
                    .getMasterDataListByMasterTypeName("WineryLicencePermit");

            for (MasterData masterDataFromDB : wineryPermitMasterDataList) {
                WineryLicensePermitAltStates wineryLicensePermitAltStates = new WineryLicensePermitAltStates();
                wineryLicensePermitAltStates.setWineryPermit(masterDataFromDB);
                wineryLicensePermitAltStates.setWineryId(wineryModelTemp);
                WineryPermitRepository.saveWineryLicensePermitAltStates(wineryLicensePermitAltStates);
            }
        }

        catch (Exception e) {
            logger.info("permit coudn't be created");
            logger.error(e);
        }
    }

    //WineryModel wineryModel = getWineryModelByWineryCode(wineryPO.getWineryCode());
    WineryModel wineryModel = getWineryModelByWineryName(wineryPO.getWineryName());

    GenericDAO<WineyImpoterModel> genericDao2 = (GenericDAO<WineyImpoterModel>) CoreBeanFactory
            .getBean("genericDAO");

    Set<ImporterModel> importerModels = wineryModel.getImporters();

    List<Long> importerIds = wineryPO.getImporterIds();

    if (importerIds == null) {
        importerIds = new ArrayList<Long>();
    }

    List<Long> existingImporterIds = new ArrayList<Long>();
    for (ImporterModel im : importerModels) {
        existingImporterIds.add(im.getId());
    }

    Set<Long> allids = new HashSet<Long>(existingImporterIds);
    allids.addAll(importerIds);
    List<Long> allidsList = new ArrayList<Long>(allids);

    for (Long importerId : allidsList) {

        WineyImpoterModel wineyImpoterModel = WineryRepository
                .getWineyImpoterModelByImporterIdAndWineryId(importerId, wineryModel.getId());

        if (wineyImpoterModel != null) {
            if (importerIds.contains(wineyImpoterModel.getImporterId())) {
                //wineyImpoterModel.setIsActiveImpoter(true);
                if (wineryModelTemp.getActiveImporterId() != null
                        && wineryModelTemp.getActiveImporterId().getId() == importerId) {
                    ImporterModel importerModel = ImporterRepository
                            .getImporterById(wineryPO.getActiveImporterId());
                    if (importerModel.getWineryCount() == 1) {
                        importerModel.setIsActive(false);
                        importerModel.setWineryCount(0L);
                        ImporterRepository.update(importerModel);
                    }

                }
                wineyImpoterModel.setIsDeleted(false);
            } else {
                //wineyImpoterModel.setIsActiveImpoter(false);                  
                wineyImpoterModel.setIsDeleted(true);
            }
            genericDao2.update(wineyImpoterModel);

        } else {
            wineyImpoterModel = new WineyImpoterModel();

            wineyImpoterModel.setWineryId(wineryModel.getId());

            wineyImpoterModel.setImporterId(importerId);

            if (importerId == wineryPO.getActiveImporterId())
                wineyImpoterModel.setIsActiveImpoter(true);
            else
                wineyImpoterModel.setIsActiveImpoter(false);

            wineyImpoterModel.setIsDeleted(false);

            genericDao2.create(wineyImpoterModel);
        }

    }

}

From source file:expansionBlocks.ProcessCommunities.java

private static void printTopologicalExtension(Query query, Map<Entity, Double> community)
        throws FileNotFoundException, UnsupportedEncodingException {

    File theDir = new File("images");
    if (!theDir.exists()) {
        boolean result = theDir.mkdir();
    }//from w ww .j  a v  a2s  . co m

    PrintWriter writer = FileManagement.Writer
            .getWriter("images/" + query.getId() + "TopologicalCommunity.txt");

    writer.println("strict digraph G{");
    Set<Entity> entitySet = community.keySet();
    Set<Long> categoriesSet = new HashSet<>();
    for (Entity e : entitySet) {
        categoriesSet.addAll(Article.getCategories(e.getId()));
    }
    Map<Long, Double> categoryWeightMap = new HashMap<>();
    Double maxW = 0.0;
    for (Entity entity : entitySet) {
        Long entityID = entity.getId();

        maxW = maxW < community.get(entityID) ? community.get(entityID) : maxW;

        Set<Long> neighbors = Article.getNeighbors(entityID, Graph.EDGES_OUT);
        Collection<Long> intersection = CollectionUtils.intersection(neighbors, entitySet);
        for (Long neighbourID : intersection) {
            if (!Article.isARedirect(entityID) && !Article.isARedirect(neighbourID)) {
                writer.println(entityID + " -> " + neighbourID + " [color=red];");
            }

        }

        Set<Long> categories = Article.getCategories(entityID);
        for (Long categoryID : categories) {
            writer.println(entityID + " -> " + categoryID + " [color=green];");
            Double w = categoryWeightMap.put(categoryID, community.get(entityID));
            if (w != null && w > community.get(entityID))
                categoryWeightMap.put(categoryID, w);

        }

        Set<Long> redirects = Article.getRedirections(entityID);
        /*
         for (Long redirectID : redirects)
         {
         if (!Article.isARedirect(articleID))
         {
         }
         }*/

    }
    for (Long categoryID : categoriesSet) {
        Set<Long> neighbors = Category.getNeigbors(categoryID, Graph.EDGES_OUT);
        Collection<Long> intersection = CollectionUtils.intersection(neighbors, categoriesSet);
        for (Long neighbourID : intersection) {
            writer.println(categoryID + " -> " + neighbourID + " [color=blue];");
        }
        neighbors = Category.getNeigbors(categoryID, Graph.EDGES_IN);
        intersection = CollectionUtils.intersection(neighbors, categoriesSet);
        for (Long neighbourID : intersection) {
            writer.println(neighbourID + " -> " + categoryID + " [color=blue];");
        }

    }

    for (Entity entity : entitySet) {
        String title = entity.getName();
        title = Normalizer.normalize(title, Normalizer.NFD);
        title = title.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
        title = title.replaceAll("[.]+", " ");

        //writer.println(id + "[label=\"" + title + "\"];");
        //         String  weight =  new BigDecimal(community.get(id)*10).toPlainString();
        BigDecimal weightDouble = new BigDecimal(2 / maxW * community.get(entity) + .5);
        String weight = weightDouble.toPlainString();
        writer.println(entity + "[label=\"" + title + "\", width=" + weight + ", height=" + weight
                + " fixedsize=true,style=filled,color=\"#c0c0c0\"];");
    }
    for (Long id : categoriesSet) {
        String title = (new Category(id)).getName();
        title = Normalizer.normalize(title, Normalizer.NFD);
        title = title.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
        title = title.replaceAll("[.]+", " ");

        BigDecimal weightDouble = new BigDecimal(2 / maxW * categoryWeightMap.get(id) + .5);
        String weight = weightDouble.toPlainString();
        writer.println(id + "[label=\"" + title + "\", width=" + weight + ", height=" + weight
                + " fixedsize=true,style=filled,color=\"#f0f0f0\"];");
    }

    writer.println("}");
    writer.close();

}

From source file:com.cangqu.gallery.server.base.utils.ReflectionUtils.java

/**
 * ?Set<br/>/*  w ww  . j a v  a2s .co  m*/
 * @param s ??<br/>
 * @param seperator <br/>
 * @return
 */
public static Set<String> makeSet(String s, String seperator) {
    Set<String> strSet = new LinkedHashSet<String>();
    if (s == null)
        return strSet;
    else {
        String[] ss = s.split(seperator);
        List<String> sList = Arrays.asList(ss);
        strSet.addAll(sList);
    }
    return strSet;
}

From source file:bioLockJ.Config.java

public static Set<String> getPropertyAsSet(final String propName) {
    final Set<String> set = new TreeSet<>();
    set.addAll(getList(propName));
    return set;//from  w w  w  .  j  a  va2 s. c om
}

From source file:hudson.plugins.trackplus.Updater.java

/**
 * Finds the strings that match Track+ issue ID patterns.
 *//*from www .  ja  va  2  s.com*/
private static Set<Integer> findIssueIdsRecursive(AbstractBuild<?, ?> build, String issuePrefix,
        BuildListener listener) {
    Set<Integer> ids = new HashSet<Integer>();

    // first, issues that were carried forward.
    Run<?, ?> prev = build.getPreviousBuild();
    if (prev != null) {
        TrackplusCarryOverAction a = prev.getAction(TrackplusCarryOverAction.class);
        if (a != null) {
            ids.addAll(a.getIDs());
        }
    }

    // then issues in this build
    findIssues(build, ids, issuePrefix, listener);

    // check for issues fixed in dependencies
    for (DependencyChange depc : build.getDependencyChanges(build.getPreviousBuild()).values())
        for (AbstractBuild<?, ?> b : depc.getBuilds())
            findIssues(b, ids, issuePrefix, listener);

    return ids;
}

From source file:com.netflix.subtitles.ttml.TtmlUtils.java

/**
 * Moves all style refs from boby and div to corresponding p element for easiest merging.
 *
 * @param tt root timed object/*from  w ww. j  a va2s .c  o  m*/
 */
public static void moveStyleRefToP(TtEltype tt) {
    Set<Object> styles = new HashSet<>(tt.getBody().getStyle());

    // set style to null, workaround for JAXB objects else style list will be just empty (invalid ttml)
    BodyEltype body = tt.getBody();
    body.getStyle().clear();
    setStyleListToNull(body);

    tt.getBody().getDiv().stream().peek((div) -> {
        styles.addAll(div.getStyle());
        div.getStyle().clear();
        setStyleListToNull(div);
    }).flatMap((div) -> div.getBlockClass().stream()).filter((o) -> o instanceof PEltype)
            .map((o) -> (PEltype) o).forEachOrdered((p) -> {
                Set<Object> pStyles = new HashSet<>(styles);
                pStyles.addAll(p.getStyle());
                p.getStyle().clear();
                p.getStyle().addAll(pStyles);
            });
}