Example usage for java.util Collection addAll

List of usage examples for java.util Collection addAll

Introduction

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

Prototype

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

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:gool.generator.common.CodePrinter.java

public Collection<File> print(Collection<ClassDef> generatedClassDefs, boolean isGool)
        throws FileNotFoundException {
    Collection<File> result = new ArrayList<File>();
    for (ClassDef classDef : generatedClassDefs) {
        result.addAll(print(classDef));
    }//  w  w  w.  j  a  va 2s  .co m

    return result;
}

From source file:com.eviware.soapui.plugins.PluginLoader.java

private Collection<SoapUIFactory> loadPluginFactories(Plugin plugin, boolean autoDetect,
        Reflections jarFileScanner) throws IllegalAccessException, InstantiationException {
    Collection<SoapUIFactory> factories = new HashSet<SoapUIFactory>(plugin.getFactories());
    if (!factories.isEmpty())
        registerFactories(factories);//from  w  w  w.  j a  va  2 s  . co m

    if (autoDetect) {
        factories.addAll(loadFactories(jarFileScanner));
    }

    return factories;
}

From source file:de.qaware.chronix.importer.csv.FileImporter.java

/**
 * Reads the given file / folder and calls the bi consumer with the extracted points
 *
 * @param points/*w  ww .  ja  va 2 s  . co m*/
 * @param folder
 * @param databases
 * @return
 */
public Pair<Integer, Integer> importPoints(Map<Attributes, Pair<Instant, Instant>> points, File folder,
        BiConsumer<List<ImportPoint>, Attributes>... databases) {

    final AtomicInteger pointCounter = new AtomicInteger(0);
    final AtomicInteger tsCounter = new AtomicInteger(0);
    final File metricsFile = new File(METRICS_FILE_PATH);

    LOGGER.info("Writing imported metrics to {}", metricsFile);
    LOGGER.info("Import supports csv files as well as gz compressed csv files.");

    try {
        final FileWriter metricsFileWriter = new FileWriter(metricsFile);

        Collection<File> files = new ArrayList<>();
        if (folder.isFile()) {
            files.add(folder);
        } else {
            files.addAll(FileUtils.listFiles(folder, new String[] { "gz", "csv" }, true));
        }

        AtomicInteger counter = new AtomicInteger(0);

        files.parallelStream().forEach(file -> {
            SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
            NumberFormat nf = DecimalFormat.getInstance(numberLocal);

            InputStream inputStream = null;
            BufferedReader reader = null;
            try {
                inputStream = new FileInputStream(file);

                if (file.getName().endsWith("gz")) {
                    inputStream = new GZIPInputStream(inputStream);
                }
                reader = new BufferedReader(new InputStreamReader(inputStream));

                //Read the first line
                String headerLine = reader.readLine();

                if (headerLine == null || headerLine.isEmpty()) {
                    boolean deleted = deleteFile(file, inputStream, reader);
                    LOGGER.debug("File is empty {}. File {} removed {}", file.getName(), deleted);
                    return;
                }

                //Extract the attributes from the file name
                //E.g. first_second_third_attribute.csv
                String[] fileNameMetaData = file.getName().split("_");

                String[] metrics = headerLine.split(csvDelimiter);

                Map<Integer, Attributes> attributesPerTimeSeries = new HashMap<>(metrics.length);

                for (int i = 1; i < metrics.length; i++) {
                    String metric = metrics[i];
                    String metricOnlyAscii = Normalizer.normalize(metric, Normalizer.Form.NFD);
                    metricOnlyAscii = metric.replaceAll("[^\\x00-\\x7F]", "");
                    Attributes attributes = new Attributes(metricOnlyAscii, fileNameMetaData);

                    //Check if meta data is completely set
                    if (isEmpty(attributes)) {
                        boolean deleted = deleteFile(file, inputStream, reader);
                        LOGGER.info("Attributes contains empty values {}. File {} deleted {}", attributes,
                                file.getName(), deleted);
                        continue;
                    }

                    if (attributes.getMetric().equals(".*")) {
                        boolean deleted = deleteFile(file, inputStream, reader);
                        LOGGER.info("Attributes metric{}. File {} deleted {}", attributes.getMetric(),
                                file.getName(), deleted);
                        continue;
                    }
                    attributesPerTimeSeries.put(i, attributes);
                    tsCounter.incrementAndGet();

                }

                Map<Integer, List<ImportPoint>> dataPoints = new HashMap<>();

                String line;
                while ((line = reader.readLine()) != null) {
                    String[] splits = line.split(csvDelimiter);
                    String date = splits[0];

                    Instant dateObject;
                    if (instantDate) {
                        dateObject = Instant.parse(date);
                    } else if (sdfDate) {
                        dateObject = sdf.parse(date).toInstant();
                    } else {
                        dateObject = Instant.ofEpochMilli(Long.valueOf(date));
                    }

                    for (int column = 1; column < splits.length; column++) {

                        String value = splits[column];
                        double numericValue = nf.parse(value).doubleValue();

                        ImportPoint point = new ImportPoint(dateObject, numericValue);

                        if (!dataPoints.containsKey(column)) {
                            dataPoints.put(column, new ArrayList<>());
                        }
                        dataPoints.get(column).add(point);
                        pointCounter.incrementAndGet();
                    }

                }

                dataPoints.values().forEach(Collections::sort);

                IOUtils.closeQuietly(reader);
                IOUtils.closeQuietly(inputStream);

                dataPoints.forEach((key, importPoints) -> {
                    for (BiConsumer<List<ImportPoint>, Attributes> database : databases) {
                        database.accept(importPoints, attributesPerTimeSeries.get(key));
                    }
                    points.put(attributesPerTimeSeries.get(key), Pair.of(importPoints.get(0).getDate(),
                            importPoints.get(importPoints.size() - 1).getDate()));
                    //write the stats to the file
                    Instant start = importPoints.get(0).getDate();
                    Instant end = importPoints.get(importPoints.size() - 1).getDate();

                    try {
                        writeStatsLine(metricsFileWriter, attributesPerTimeSeries.get(key), start, end);
                    } catch (IOException e) {
                        LOGGER.error("Could not write stats line", e);
                    }
                    LOGGER.info("{} of {} time series imported", counter.incrementAndGet(), tsCounter.get());
                });

            } catch (Exception e) {
                LOGGER.info("Exception while reading points.", e);
            } finally {
                //close all streams
                IOUtils.closeQuietly(reader);
                IOUtils.closeQuietly(inputStream);
            }

        });
    } catch (Exception e) {
        LOGGER.error("Exception occurred during reading points.");
    }
    return Pair.of(tsCounter.get(), pointCounter.get());
}

From source file:com.idega.bedework.presentation.BedeworkPersonalCalendarView.java

private Collection<BwCalendar> getCalendars(IWContext iwc) {
    if (iwc == null) {
        return null;
    }//from ww w  .  j  a v  a 2  s.co m

    Collection<BwCalendar> calendars = new ArrayList<BwCalendar>();

    Collection<BwCalendar> calendarsFromdatabase = getBedeworkCalendarManagementService()
            .getCalendars(iwc.getCurrentUser());

    if (!ListUtil.isEmpty(calendarsFromdatabase)) {
        calendars.addAll(calendarsFromdatabase);
    }

    Collection<CalendarEntity> calendarsEntytiesFromDatabase = getBedeworkCalendarManagementService()
            .getSubscriptions(iwc.getCurrentUser());

    if (!ListUtil.isEmpty(calendarsEntytiesFromDatabase)) {
        calendars.addAll(calendarsEntytiesFromDatabase);
    }

    return calendars;
}

From source file:com.qualogy.qafe.presentation.EventHandlerImpl.java

public Collection<BuiltInFunction> handle(ApplicationContext context, Event event, DataIdentifier dataId,
        EventData eventData) throws ExternalException {
    Collection<BuiltInFunction> builtInList = new ArrayList<BuiltInFunction>();
    if (event != null) {
        Collection<BuiltInFunction> eventBuiltInList = handleEventItems(event.getEventItems(), context, event,
                dataId, eventData);/*from  www.  ja  v a2s . c  o  m*/
        builtInList.addAll(eventBuiltInList);
    }
    return builtInList;
}

From source file:com.reprezen.swagedit.core.assist.JsonProposalProvider.java

protected Collection<ProposalDescriptor> getProposals(TypeDefinition type, AbstractNode node, String prefix) {
    if (type instanceof ReferenceTypeDefinition) {
        type = ((ReferenceTypeDefinition) type).resolve();
    }//from w  ww . ja  v a 2s  .c om

    ContentAssistExt ext = findExtension(type);
    if (ext != null) {
        return ext.getProposals(type, node, prefix);
    }

    switch (type.getType()) {
    case STRING:
    case INTEGER:
    case NUMBER:
        return createPrimitiveProposals(type);
    case BOOLEAN:
        return createBooleanProposals(type);
    case ENUM:
        return createEnumProposals(type, node);
    case ARRAY:
        return createArrayProposals((ArrayTypeDefinition) type, node);
    case OBJECT:
        return createObjectProposals((ObjectTypeDefinition) type, node, prefix);
    case ALL_OF:
    case ANY_OF:
    case ONE_OF:
        return createComplextTypeProposals((ComplexTypeDefinition) type, node, prefix);
    case UNDEFINED:
        Collection<ProposalDescriptor> proposals = new LinkedHashSet<>();
        if (type instanceof MultipleTypeDefinition) {
            for (TypeDefinition currentType : ((MultipleTypeDefinition) type).getMultipleTypes()) {
                proposals.addAll(getProposals(currentType, node, prefix));
            }
        }
        return proposals;
    }
    return Collections.emptyList();
}

From source file:com.chinamobile.bcbsp.bspcontroller.QueueManager.java

/**
 * get the jobs in all the waitqueues.//  ww  w .j a  v a  2 s . c o m
 * @return
 *        waitQueue jobs.
 */
public Collection<JobInProgress> getJobs() {
    int WaitQueuesTotal = 4;
    Collection<JobInProgress> jobs = new LinkedBlockingQueue<JobInProgress>();
    String[] waitQueues = { "HIGHER_WAIT_QUEUE", "HIGH_WAIT_QUEUE", "NORMAL_WAIT_QUEUE", "LOW_WAIT_QUEUE",
            "LOWER_WAIT_QUEUE" };
    for (int i = 0; i <= WaitQueuesTotal; i++) {
        jobs.addAll(findQueue(waitQueues[i]).getJobs());
    }
    return jobs;
}

From source file:ca.uhn.fhir.rest.method.OperationParameter.java

@SuppressWarnings("unchecked")
@Override/*ww  w  . j  a  va2s . co m*/
public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest,
        BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException {
    List<Object> matchingParamValues = new ArrayList<Object>();

    if (theRequest.getRequestType() == RequestTypeEnum.GET) {
        translateQueryParametersIntoServerArgumentForGet(theRequest, matchingParamValues);
    } else {
        translateQueryParametersIntoServerArgumentForPost(theRequest, matchingParamValues);
    }

    if (matchingParamValues.isEmpty()) {
        return null;
    }

    if (myInnerCollectionType == null) {
        return matchingParamValues.get(0);
    }

    Collection<Object> retVal = ReflectionUtil.newInstance(myInnerCollectionType);
    retVal.addAll(matchingParamValues);
    return retVal;
}

From source file:lu.softec.xwiki.macro.internal.ClassRunnerMacro.java

private ClassLoader getClassLoader(Collection<URL> pkgUrls, Collection<URL> dpkgUrls) {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    if (!dpkgUrls.isEmpty()) {
        pkgUrls.addAll(dpkgUrls);
    }// w  ww  .j a  v a 2 s .co  m
    if (!pkgUrls.isEmpty()) {
        loader = loaderf.getURLClassLoader(pkgUrls.toArray(new URL[0]), loader, !dpkgUrls.isEmpty());
    }
    return loader;
}

From source file:edu.ksu.cis.indus.staticanalyses.impl.ClassHierarchy.java

/**
 * Prunes the class hierarchy to only include the given classes. The transitive inheritance relationship between the
 * retained classes can be preserved via <code>retainTransitiveInheritanceRelation</code>.
 * /*from w  w  w  . java 2s.  c  o m*/
 * @param confineToClasses is the collection of classes to confine the hierarchy to.
 * @param retainTransitiveInheritanceRelation <code>true</code> indicates that the transitive inheritance relationship
 *            between classes via classes not mentined in <code>confiningClasses</code> should be retained;
 *            <code>false</code>, otherwise.
 * @pre confineToClasses != null and confineToClasses.oclIsKindOf(Collection(SootClass))
 */
public void confine(final Collection confineToClasses, final boolean retainTransitiveInheritanceRelation) {
    final Collection<SootClass> _classesToRemove = new HashSet<SootClass>();
    _classesToRemove.addAll(classes);
    _classesToRemove.addAll(interfaces);
    _classesToRemove.removeAll(confineToClasses);

    if (retainTransitiveInheritanceRelation) {
        removeClassesAndRetainInheritanceRelation(_classesToRemove);
    } else {
        final Iterator<SootClass> _i = _classesToRemove.iterator();
        final int _iEnd = _classesToRemove.size();

        for (int _iIndex = 0; _iIndex < _iEnd; _iIndex++) {
            final SootClass _sc = _i.next();
            final SimpleNode<SootClass> _node = classHierarchy.queryNode(_sc);
            classHierarchy.removeNode(_node);
        }
    }
    classes.retainAll(confineToClasses);
    interfaces.retainAll(confineToClasses);
}