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:de.xwic.appkit.core.util.CollectionUtil.java

/**
 * if parameter is null, set won't contain anything
 *
 * @param set//  w w w  .jav  a2  s.  co m
 * @return
 */
public static <E> Set<E> newSet(final Collection<E> collection) {
    final Set<E> set = new LinkedHashSet<E>();
    if (!CollectionUtil.isEmpty(collection)) {
        set.addAll(collection);
    }
    return set;
}

From source file:io.apiman.gateway.engine.impl.DefaultPluginRegistry.java

private static Set<URI> getConfiguredPluginRepositories(Map<String, String> configMap) {
    Set<URI> rval = new HashSet<>();
    rval.addAll(PluginUtils.getDefaultMavenRepositories());
    String repositories = configMap.get("pluginRepositories"); //$NON-NLS-1$
    if (repositories != null) {
        String[] split = repositories.split(","); //$NON-NLS-1$
        for (String repository : split) {
            try {
                String trimmedRepo = repository.trim();
                if (!trimmedRepo.isEmpty()) {
                    if (trimmedRepo.startsWith("file:")) { //$NON-NLS-1$
                        trimmedRepo = trimmedRepo.replace('\\', '/');
                    }/*from  w  ww .jav a  2s  .  c o m*/
                    rval.add(new URI(trimmedRepo));
                }
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return rval;
}

From source file:com.serotonin.m2m2.module.ModuleRegistry.java

/**
 * @return a list of all available locale names in this instance.
 *//*from w  w  w .j a v  a  2s . c om*/
public static Set<String> getLocales() {
    Set<String> locales = new HashSet<String>();
    for (Module module : MODULES.values())
        locales.addAll(module.getLocales());
    return locales;
}

From source file:com.gtcgroup.jped.valid.helper.JpvValidationUtilHelper.java

/**
 * This method performs Java Bean validation.
 *
 * @param <PO>//from   w  w  w . ja v a  2s .c  o  m
 * @param <CO>
 * @param validatorPO
 * @return List<JpvErrorMessageTBD>
 */
public static <PO extends JpvBasicValidatorPO, CO extends JpvErrorMessagesTBD> CO validate(
        final PO validatorPO) {

    // Declare/Initialize
    final Set<ConstraintViolation<Object>> constraintViolationSet = new HashSet<ConstraintViolation<Object>>();
    final Object[] instancesToBeValidated = validatorPO.getInstancesToBeValidated();

    // Validate each instance... more than one error can occur.
    for (final Object instanceToBeValidated : instancesToBeValidated) {

        constraintViolationSet.addAll(
                JpvValidationUtilHelper.VALIDATOR.validate(instanceToBeValidated, validatorPO.getGroups()));

        // Check for stopping after the first error.
        if (validatorPO.isStopAfterFirstError() && constraintViolationSet.size() > 0) {
            break;
        }
    }

    @SuppressWarnings("unchecked")
    final CO errorMessagesCO = (CO) JpvValidationUtilHelper.convertConstraintViolationsToErrors(validatorPO,
            constraintViolationSet);

    return errorMessagesCO;
}

From source file:main.java.repartition.SimpleTr.java

static double getIncidentSpan(Transaction j, MigrationPlan m) {
    // Construct A -- for target transaction i
    Set<Integer> delta_i_A = new HashSet<Integer>();
    for (Integer s : m.fromSet)
        delta_i_A.addAll(m.serverDataSet.get(s));

    // Construct b -- for incident transaction j
    Set<Integer> delta_j_A = new HashSet<Integer>();
    for (Integer s : m.fromSet)
        if (j.getTr_serverSet().containsKey(s))
            delta_j_A.addAll(j.getTr_serverSet().get(s));

    // Set difference, delta = delta_j_A \ delta_i_A
    Set<Integer> delta = new HashSet<Integer>(delta_j_A);
    delta.removeAll(delta_i_A);/*  w w  w.  j  a va2s . com*/

    HashSet<Integer> psi_delta = new HashSet<Integer>();
    for (Entry<Integer, HashSet<Integer>> entry : j.getTr_serverSet().entrySet())
        if (!Collections.disjoint(delta, entry.getValue())) // Returns true if the two specified collections have no elements in common.
            psi_delta.add(entry.getKey());

    // Calculate net span improvement for incident transaction j
    int incident_span = m.fromSet.size() - psi_delta.size();

    if (!j.getTr_serverSet().containsKey(m.to))
        incident_span -= 1;

    return (double) (incident_span) * (1 / j.getTr_period());
}

From source file:org.paxml.launch.LaunchModelBuilder.java

public static Set<PaxmlResource> findResources(String base, Set<String> includes, Set<String> excludes) {
    if (includes == null) {
        includes = new HashSet<String>(1);
        includes.add("**/*.*");
    }/*from www.j ava  2 s  .  c  o  m*/
    if (excludes == null) {
        excludes = Collections.EMPTY_SET;
    }
    if (base == null) {
        base = ""; // the current working dir
    }
    File f = new File(base);
    if (f.isDirectory()) {
        f = new File(f, "fake.file");
    }
    Resource baseRes = new FileSystemResource(f).getSpringResource();
    Set<PaxmlResource> include = new LinkedHashSet<PaxmlResource>(0);
    Set<PaxmlResource> exclude = new LinkedHashSet<PaxmlResource>(0);
    ResourceMatcher matcher = new ResourceMatcher(includes, excludes);
    for (String pattern : matcher.include) {
        include.addAll(ResourceLocator.findResources(pattern, baseRes));
    }
    for (String pattern : matcher.exclude) {
        exclude.addAll(ResourceLocator.findResources(pattern, baseRes));
    }
    include.removeAll(exclude);

    return include;
}

From source file:jeeves.xlink.Processor.java

/**
 * Resolve all XLinks of the input XML document.
 *
 * @return All set of all the xlinks that failed to resolve.
 *//*from   w w  w.  ja v a 2  s  .  com*/
public static Set<String> processXLink(Element xml, ServiceContext srvContext) {
    Set<String> errors = Sets.newHashSet();
    errors.addAll(searchXLink(xml, ACTION_RESOLVE, srvContext));
    errors.addAll(searchLocalXLink(xml, ACTION_RESOLVE));
    return errors;
}

From source file:edu.ucsd.library.xdre.web.StatsCollectionsReportController.java

public synchronized static void generateReport() throws Exception {
    DAMSClient damsClient = null;//w w  w .  ja  v a  2  s.  c o m
    StringBuilder strBuf = new StringBuilder();
    strBuf.append("UCSD Library DAMS Collections Report - " + ReportFormater.getCurrentTimestamp() + "\n");
    strBuf.append(
            "Collection\tType\tUnit\tSearchable Items\tItems Count\tSize(MB)\tView\tPublic\tUCSD\tCurator\tRestricted\tCulturally Sensitive\tNotes"
                    + "\n");

    Map<String, String> unitsMap = null;
    Map<String, Set<String>> unitsRecordsMap = new HashMap<String, Set<String>>();
    Map<String, String> colRows = new TreeMap<String, String>();

    try {
        String colId = null;
        String colTitle = null;
        List<String> values = null;
        String visibility = "";
        String unit = "";
        String colType = "";
        String rowVal = null;
        Document doc = null;
        damsClient = DAMSClient.getInstance();
        Map<String, String> colMap = damsClient.listCollections();

        CollectionHandler colHandler = null;
        unitsMap = DAMSClient.reverseMap(damsClient.listUnits());
        for (Iterator<String> it = unitsMap.keySet().iterator(); it.hasNext();) {
            String unitId = it.next();
            Set<String> uRecords = new HashSet<String>();
            uRecords.addAll(damsClient.listUnitObjects(unitId));
            unitsRecordsMap.put(unitId, uRecords);
        }
        for (Iterator<String> iter = colMap.keySet().iterator(); iter.hasNext();) {
            visibility = "";
            unit = "";
            colTitle = iter.next();
            colId = colMap.get(colTitle);

            // Remove records from all units
            try {
                colHandler = new StatsCollectionQuantityHandler(damsClient, colId);
                if (unitsRecordsMap.size() > 0) {
                    for (Iterator<Set<String>> uit = unitsRecordsMap.values().iterator(); uit.hasNext();) {
                        Set<String> uRecords = uit.next();
                        uRecords.remove(colId);
                        uRecords.removeAll(colHandler.getItems());
                    }
                }
            } finally {
                if (colHandler != null) {
                    colHandler.release();
                    colHandler = null;
                }
            }

            colId = colId.substring(colId.lastIndexOf("/") + 1);
            int idx = colTitle.lastIndexOf("[");
            if (idx > 0) {
                colType = colTitle.substring(idx + 1, colTitle.lastIndexOf("]"));
                colTitle = colTitle.substring(0, idx).trim();
            }

            doc = damsClient.solrLookup("q=" + URLEncoder.encode("id:" + colId, "UTF-8"));
            values = getValues(doc, "//*[@name='visibility_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                visibility += (visibility.length() > 0 ? " " : "") + it.next();
            values = getValues(doc, "//*[@name='unit_code_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                unit += (unit.length() > 0 ? " " : "") + it.next();
            rowVal = getRow(damsClient, colTitle, colId, colType, unit, visibility, colMap, null);
            if (rowVal != null && rowVal.length() > 0)
                colRows.put(colTitle, rowVal + "\n");
        }

        // Orphans in each unit
        for (Iterator<String> uit = unitsRecordsMap.keySet().iterator(); uit.hasNext();) {
            colId = uit.next();
            colTitle = unitsMap.get(colId);
            Set<String> uRecords = unitsRecordsMap.get(colId);
            List<String> items = new ArrayList<String>();
            items.addAll(uRecords);
            colType = "Unit";
            colId = colId.substring(colId.lastIndexOf("/") + 1);

            doc = damsClient.solrLookup("q=" + URLEncoder.encode("id:" + colId, "UTF-8"));
            visibility = "";
            values = getValues(doc, "//*[@name='visibility_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                visibility += (visibility.length() > 0 ? " " : "") + it.next();

            unit = "";
            values = getValues(doc, "//*[@name='unit_code_tesim']/str");
            for (Iterator<String> it = values.iterator(); it.hasNext();)
                unit += (unit.length() > 0 ? " " : "") + it.next();
            rowVal = getRow(damsClient, colTitle, colId, colType, unit, visibility, colMap, items);
            if (rowVal != null && rowVal.length() > 0)
                colRows.put(colTitle, rowVal + "\n");
        }

        for (Iterator<String> iter = colRows.values().iterator(); iter.hasNext();) {
            strBuf.append(iter.next());
        }

        STATUSREPORT = strBuf.toString();
    } finally {
        if (damsClient != null) {
            damsClient.close();
            damsClient = null;
        }
    }
}

From source file:de.smartics.maven.plugin.buildmetadata.scm.maven.MavenScmRevisionNumberFetcher.java

private static Set<ScmFile> createSortedFiles(final List<ScmFile> changedFiles) {
    final Set<ScmFile> set = new TreeSet<ScmFile>(new Comparator<ScmFile>() {
        public int compare(final ScmFile o1, final ScmFile o2) {
            return o2.compareTo(o1);
        }//w w w  .  j  a v a  2s .  com
    });

    set.addAll(changedFiles);

    return set;
}

From source file:edu.stanford.epad.epadws.xnat.XNATCreationOperations.java

private static Collection<File> listDICOMFiles(File dir) {
    Set<File> files = new HashSet<File>();
    if (dir.listFiles() != null) {
        for (File entry : dir.listFiles()) {
            if (isDicomFile(entry))
                files.add(entry);/*  w  w  w  . j  a  v a  2  s  .com*/
            else
                files.addAll(listDICOMFiles(entry));
        }
    }
    return files;
}