Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

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

Prototype

default <T> T[] toArray(IntFunction<T[]> generator) 

Source Link

Document

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

Usage

From source file:com.nextep.designer.synch.services.impl.ReverseSynchronizationService.java

/**
 * Recursively look for any deletion in the comparison item tree and checks whether we can or
 * cannot remove this element./*ww  w .java  2  s. c  om*/
 * 
 * @param items comparison items to check
 * @param deletedReferencers referencers which are removed with this item
 * @return a collection of all {@link IReferencer} which would still reference the elements if
 *         the reverse synchronization is performed
 */
@SuppressWarnings("unchecked")
private Collection<IReferencer> checkRecursiveDeletions(IReverseSynchronizationContext context,
        IComparisonItem... items) {
    final Collection<IReferencer> referencers = new HashSet<IReferencer>();
    if (items == null) {
        final Collection<IComparisonItem> itemsToSynchronize = context.getItemsToSynchronize();
        items = itemsToSynchronize.toArray(new IComparisonItem[itemsToSynchronize.size()]);
    }
    Collection<IReferencer> deletedReferencers = context.getDeletedReferencers();
    MultiValueMap invRefMap = context.getReverseDependenciesMap();

    for (IComparisonItem item : items) {
        if (item.getDifferenceType() == DifferenceType.MISSING_SOURCE
                && item.getTarget() instanceof IReferenceable
                && item.getMergeInfo().getMergeProposal() == null) {
            Collection<IReferencer> invDeps = invRefMap.getCollection(item.getTarget().getReference());
            if (invDeps == null) {
                invDeps = Collections.emptyList();
            }
            referencers.addAll(dependencyService.getReferencersAfterDeletion((IReferenceable) item.getTarget(),
                    invDeps, deletedReferencers));
            continue;
        }
        final Collection<IComparisonItem> subItems = item.getSubItems();
        referencers.addAll(
                checkRecursiveDeletions(context, subItems.toArray(new IComparisonItem[subItems.size()])));
    }
    return referencers;
}

From source file:de.akquinet.innovation.play.maven.Play2PackageMojo.java

private File moveDistributionArtifactToTarget() throws MojoExecutionException {
    // The artifact is in dist.
    File dist = new File(project.getBasedir(), "dist");
    if (!dist.exists()) {
        throw new MojoExecutionException("Can't find the 'dist' directory");
    }/*from  w  w  w.  j a  v a 2  s  .c  o m*/

    Collection<File> found = FileUtils.listFiles(dist, new String[] { "zip" }, false);
    if (found.size() == 0) {
        throw new MojoExecutionException("The distribution file was not found in " + dist.getAbsolutePath());
    } else if (found.size() > 1) {
        throw new MojoExecutionException(
                "Too many match for the distribution file in " + dist.getAbsolutePath());
    }

    // 1 file
    File file = found.toArray(new File[0])[0];

    getLog().info("Distribution file found : " + file.getAbsolutePath());

    File target = new File(project.getBasedir(), "target");
    File out = null;
    if (classifier == null) {
        out = new File(target, project.getBuild().getFinalName() + ".zip");
    } else {
        out = new File(target, project.getBuild().getFinalName() + "-" + classifier + ".zip");
    }

    try {
        getLog().info("Copying " + file.getName() + " to " + out.getName());
        FileUtils.copyFile(file, out, true);
    } catch (IOException e) {
        throw new MojoExecutionException("Can't copy the distribution file to the target folder", e);
    }

    // Delete the dist folder if enabled.
    if (deleteDist) {
        getLog().debug("Deleting " + dist.getAbsolutePath());
        FileUtils.deleteQuietly(dist);
    }

    return out;
}

From source file:common.DataNode.java

/** Instantiate a single datanode object. This must be run by invoking
 *  {@link DataNode#runDatanodeDaemon(DataNode)} subsequently. 
 *//* ww w  . j av  a 2 s  . c  om*/
public static DataNode instantiateDataNode(String args[], Configuration conf) throws IOException {
    if (conf == null)
        conf = new HdfsConfiguration();

    if (args != null) {
        // parse generic hadoop options
        GenericOptionsParser hParser = new GenericOptionsParser(conf, args);
        args = hParser.getRemainingArgs();
    }

    if (!parseArguments(args, conf)) {
        printUsage();
        return null;
    }
    if (conf.get("dfs.network.script") != null) {
        LOG.error("This configuration for rack identification is not supported"
                + " anymore. RackID resolution is handled by the NameNode.");
        System.exit(-1);
    }
    Collection<URI> dataDirs = getStorageDirs(conf);
    dnThreadName = "DataNode: [" + StringUtils.uriToString(dataDirs.toArray(new URI[0])) + "]";
    return makeInstance(dataDirs, conf);
}

From source file:com.algoTrader.entity.marketData.BarDaoBase.java

/**
 * {@inheritDoc}/*from w  ww.  j ava 2 s. c o m*/
 */
@Override
@SuppressWarnings({ "unchecked" })
public final BarVO[] toBarVOArray(Collection<?> entities) {
    BarVO[] result = null;
    if (entities != null) {
        // Unchecked transformation: reuses entities Collection
        final Collection collection = new ArrayList(entities);
        this.toBarVOCollection(collection);
        result = (BarVO[]) collection.toArray(new BarVO[collection.size()]);
    }
    return result;
}

From source file:fr.pasteque.pos.ticket.TicketInfo.java

public TicketTaxInfo[] getTaxLines() {

    Map<String, TicketTaxInfo> m = new HashMap<String, TicketTaxInfo>();

    TicketLineInfo oLine;/*from   ww  w  .j  av  a 2s .  co  m*/
    for (Iterator<TicketLineInfo> i = m_aLines.iterator(); i.hasNext();) {
        oLine = i.next();

        TicketTaxInfo t = m.get(oLine.getTaxInfo().getId());
        if (t == null) {
            t = new TicketTaxInfo(oLine.getTaxInfo());
            m.put(t.getTaxInfo().getId(), t);
        }
        t.add(oLine.getSubValue());
    }

    // return dSuma;       
    Collection<TicketTaxInfo> avalues = m.values();
    return avalues.toArray(new TicketTaxInfo[avalues.size()]);
}

From source file:com.github.os72.protocjar.maven.ProtocJarMojo.java

private void processFile(File file, String version, String type, String pluginPath, File outputDir,
        String outputOptions) throws MojoExecutionException {
    getLog().info("    Processing (" + type + "): " + file.getName());
    Collection<String> cmd = buildCommand(file, version, type, pluginPath, outputDir, outputOptions);
    try {/*from w w w.  j  a v  a2 s. co  m*/
        int ret = 0;
        if (protocCommand == null)
            ret = Protoc.runProtoc(cmd.toArray(new String[0]));
        else
            ret = Protoc.runProtoc(protocCommand, cmd.toArray(new String[0]));
        if (ret != 0)
            throw new MojoExecutionException("protoc-jar failed for " + file + ". Exit code " + ret);
    } catch (InterruptedException e) {
        throw new MojoExecutionException("Interrupted", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to execute protoc-jar for " + file, e);
    }
}

From source file:net.ostis.scpdev.debug.core.model.PMDebugTarget.java

private void refreshThreadsArray() {
    Collection<SCPProcess> values = SCPProcess.getAllCached();
    threads = (IThread[]) values.toArray(new IThread[values.size()]);
}

From source file:io.soabase.halva.processor.caseclass.PassCreateClass.java

private void processOneSpec(CaseClassSpec spec) {
    String packageName = environment.getPackage(spec.getAnnotatedElement());
    GeneratedClass generatedClass = environment.getGeneratedManager().resolve(spec.getAnnotatedElement());
    Settings settings = new Settings(spec);

    environment.log("Generating " + spec.getAnnotationReader().getName() + " for "
            + generatedClass.getOriginal() + " as " + generatedClass.getGenerated());

    Collection<Modifier> modifiers = environment.getModifiers(spec.getAnnotatedElement());
    TypeName baseType = TypeName.get(spec.getAnnotatedElement().asType());
    TypeSpec.Builder builder;//from   w  w  w .  j a v  a  2  s  .co m
    if (settings.asEnum) {
        builder = TypeSpec.enumBuilder(generatedClass.getGenerated())
                .addEnumConstant(generatedClass.getGenerated().simpleName());
    } else {
        builder = TypeSpec.classBuilder(generatedClass.getGenerated()).addSuperinterface(Serializable.class);
    }
    builder.addSuperinterface(baseType).addSuperinterface(Tuplable.class)
            .addModifiers(modifiers.toArray(new Modifier[modifiers.size()]));
    if (!settings.isCaseObject) {
        builder.addSuperinterface(ClassTuplable.class);
    }

    Optional<List<TypeVariableName>> typeVariableNames = environment
            .addTypeVariableNames(builder::addTypeVariables, spec.getAnnotatedElement().getTypeParameters());
    if (settings.json) {
        AnnotationSpec annotationSpec = AnnotationSpec
                .builder(ClassName.get("com.fasterxml.jackson.databind.annotation", "JsonDeserialize"))
                .addMember("builder", "$T.class",
                        templates.getBuilderClassName(generatedClass.getGenerated(), typeVariableNames))
                .build();
        builder.addAnnotation(annotationSpec);
    }
    spec.getItems().forEach(item -> templates.addItem(item, builder, settings));
    if (settings.isCaseObject) {
        if (!settings.asEnum) {
            templates.addObjectInstance(builder, generatedClass.getGenerated(), typeVariableNames);
        }
    } else {
        templates.addBuilder(spec, builder, generatedClass.getGenerated(), settings, typeVariableNames);
        templates.addCopy(builder, generatedClass.getGenerated(), typeVariableNames);
        templates.addApplyBuilder(spec, builder, generatedClass.getGenerated(), typeVariableNames);
        templates.addClassTuple(spec, builder, generatedClass.getGenerated(), settings, typeVariableNames);
    }
    if (!settings.asEnum) {
        templates.addConstructor(spec, builder);
        templates.addEquals(spec, builder, generatedClass.getGenerated());
        templates.addHashCode(spec, builder);
    }
    templates.addTuple(spec, builder);
    templates.addDebugString(spec, builder, generatedClass.getGenerated());
    templates.addToString(spec, builder, generatedClass.getGenerated());

    environment.createSourceFile(packageName, generatedClass.getOriginal(), generatedClass.getGenerated(),
            spec.getAnnotationReader().getFullName(), builder, spec.getAnnotatedElement());
}

From source file:net.ion.radon.cload.listeners.CompilingListener.java

public String[] getResourcesToCompile(final FileAlterationObserver pObserver) {
    final Collection<File> created = getCreatedFiles();
    final Collection<File> changed = getChangedFiles();

    final Collection<String> resourceNames = new ArrayList<String>();

    for (File createdFile : created) {
        if (createdFile.getName().endsWith(getSourceFileExtension())) {
            resourceNames.add(getSourceNameFromFile(pObserver, createdFile));
        }//  w w w.  j a va  2 s  .c  om
    }

    for (File changedFile : changed) {
        if (changedFile.getName().endsWith(getSourceFileExtension())) {
            resourceNames.add(getSourceNameFromFile(pObserver, changedFile));
        }
    }

    final String[] result = new String[resourceNames.size()];
    resourceNames.toArray(result);
    return result;
}

From source file:edu.washington.gs.skyline.model.quantification.FoldChangeDataSet.java

/**
 * Construct a new FoldChangeDataSet.  The first four collections must all have the same number of elements.
 * The "subjectControls" must have the same number of elements as the number of unique values of "subjects".
 * @param abundances log2 intensity//w w w. jav a2s.c o m
 * @param features identifiers of the transition that the abundance was measured for.  Note that Skyline always sums
 *                 the transition intensities before coming in here, the feature values should all be zero.
 * @param runs integers representing which replicate the value came from
 * @param subjects identifiers used for combining biological replicates.
 * @param subjectControls specifies which subject values belong to the control group.
 */
public FoldChangeDataSet(Collection<Double> abundances, Collection<Integer> features, Collection<Integer> runs,
        Collection<Integer> subjects, Collection<Boolean> subjectControls) {
    if (abundances.size() != features.size() || abundances.size() != subjects.size()
            || abundances.size() != runs.size()) {
        throw new IllegalArgumentException("Wrong number of rows");
    }
    this.abundances = abundances.stream().mapToDouble(Double::doubleValue).toArray();
    this.features = features.stream().mapToInt(Integer::intValue).toArray();
    this.runs = runs.stream().mapToInt(Integer::intValue).toArray();
    this.subjects = subjects.stream().mapToInt(Integer::intValue).toArray();
    this.subjectControls = ArrayUtils.toPrimitive(subjectControls.toArray(new Boolean[subjectControls.size()]));
    if (this.abundances.length == 0) {
        featureCount = 0;
        subjectCount = 0;
        runCount = 0;
    } else {
        if (Arrays.stream(this.features).min().getAsInt() < 0 || Arrays.stream(this.runs).min().getAsInt() < 0
                || Arrays.stream(this.subjects).min().getAsInt() < 0) {
            throw new IllegalArgumentException("Cannot be negative");
        }
        featureCount = Arrays.stream(this.features).max().getAsInt() + 1;
        subjectCount = Arrays.stream(this.subjects).max().getAsInt() + 1;
        runCount = Arrays.stream(this.runs).max().getAsInt() + 1;
    }
    if (this.subjectControls.length != subjectCount) {
        throw new IllegalArgumentException("Wrong number of subjects");
    }
}