Example usage for com.google.common.collect Iterables toArray

List of usage examples for com.google.common.collect Iterables toArray

Introduction

In this page you can find the example usage for com.google.common.collect Iterables toArray.

Prototype

static <T> T[] toArray(Iterable<? extends T> iterable, T[] array) 

Source Link

Usage

From source file:eu.esdihumboldt.hale.ui.common.definition.viewer.TypeIndexContentProvider.java

/**
 * @see ITreeContentProvider#getElements(Object)
 *//*from   www.j  av a 2  s .  c o  m*/
@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof TypeIndex) {
        return ((TypeIndex) inputElement).getMappingRelevantTypes().toArray();
    } else if (inputElement instanceof Iterable<?>) {
        return Iterables.toArray((Iterable<?>) inputElement, Object.class);
    } else {
        throw new IllegalArgumentException("Content provider only applicable for type indexes.");
    }
}

From source file:com.inmobi.grill.cli.commands.GrillFactCommands.java

@CliCommand(value = "create fact", help = "create a fact table")
public String createFact(@CliOption(key = { "",
        "table" }, mandatory = true, help = "<fact spec path> <storage spec path>") String tableFilePair) {
    Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(tableFilePair);
    String[] pair = Iterables.toArray(parts, String.class);
    if (pair.length != 2) {
        return "Syntax error, please try in following "
                + "format. create fact <fact spec path> <storage spec path>";
    }/*from   w  ww. j a  va2 s  .c  o m*/

    File f = new File(pair[0]);

    if (!f.exists()) {
        return "Fact spec path" + f.getAbsolutePath() + " does not exist. Please check the path";
    }
    f = new File(pair[1]);
    if (!f.exists()) {
        return "Storage spech path " + f.getAbsolutePath() + " does not exist. Please check the path";
    }

    APIResult result = client.createFactTable(pair[0], pair[1]);
    if (result.getStatus() == APIResult.Status.SUCCEEDED) {
        return "Fact table Successfully completed";
    } else {
        return "Fact table creation failed";
    }
}

From source file:com.opera.core.systems.runner.inprocess.OperaInProcessRunner.java

public void startOpera() throws OperaRunnerException {
    lock.lock();//from  w w  w.j a v a 2 s  . c o  m

    try {
        if (isOperaRunning()) {
            return;
        }

        process = new CommandLine(settings.getBinary().getCanonicalPath(),
                Iterables.toArray(settings.arguments().getArgumentsAsStringList(), String.class));
        logger.config(String.format("runner arguments: %s", process));

        // TODO(andreastt): Do we need to forward the environment to CommandLine?
        //process.setEnvironmentVariables(environment);
        process.copyOutputTo(System.out);
        process.executeAsync();

        boolean startedProperly = new ImplicitWait(OperaIntervals.PROCESS_START_TIMEOUT.getValue())
                .until(new Callable<Boolean>() {
                    public Boolean call() {
                        try {
                            process.getExitCode();

                            // Process exited within process execute timeout, meaning it exited immediately
                            return false;
                        } catch (IllegalStateException e) {
                            // getExitCode() throws when process has not yet been executed... patience!
                        }

                        return true;
                    }
                });

        if (!startedProperly) {
            throw new IOException(
                    "Opera exited immediately; possibly incorrect arguments?  Command: " + process);
        }
    } catch (IOException e) {
        throw new OperaRunnerException("Could not start Opera: " + e.getMessage());
    } finally {
        lock.unlock();
    }
}

From source file:org.apache.solr.analytics.statistics.PercentileStatsCollector.java

public void compute() {
    delegate.compute();//from  w w w  . j a  v a 2 s.  com
    if (values.size() > 0) {
        results = Iterables.toArray(getPercentiles(), Comparable.class);
    } else {
        results = null;
    }
}

From source file:edu.umn.msi.tropix.galaxy.service.GalaxyConverterImpl.java

public void populateJobDescription(final JobDescriptionType jobDescription, final Tool tool) {
    final Command command = tool.getCommand();
    Preconditions.checkNotNull(command);
    final String executable;
    final List<String> arguments;
    if (StringUtils.hasText(command.getInterpreter())) {
        // If no interpreter is specified, then all
        executable = command.getInterpreter();
        arguments = splitCommandLine(command.getValue());
    } else {//  w  w w  . ja v  a  2 s .c  o  m
        final List<String> splitCommandLine = splitCommandLine(command.getValue());
        // Rip executable out of line and leave arguments.
        executable = splitCommandLine.remove(0);
        arguments = splitCommandLine;
    }
    jobDescription.setExecutable(executable);
    jobDescription.setArgument(Iterables.toArray(arguments, String.class));
}

From source file:org.cloudsmith.geppetto.graph.catalog.CatalogGraphProducer.java

private StyleSet labelStyleForResource(CatalogResource r, final IPath root) {

    // Produce a sorted list of parameters (that skips parameters that are really dependencies)
    List<LabelRow> labelRows = Lists.newArrayList();
    CatalogResourceParameter[] sortedProperties = Iterables.toArray(
            Iterables.filter(getParameterIterable(r), regularParameterPredicate),
            CatalogResourceParameter.class);

    Arrays.sort(sortedProperties, new Comparator<CatalogResourceParameter>() {

        @Override//www  .j  ava2  s  .c  o  m
        public int compare(CatalogResourceParameter o1, CatalogResourceParameter o2) {
            return o1.getName().compareTo(o2.getName());
        }

    });

    // Add a labelRow for the type[id]
    StringBuilder builder = new StringBuilder();
    builder.append(r.getType());
    builder.append("[");
    builder.append(r.getTitle());
    builder.append("]");

    int width = 0;
    boolean hasParameters = sortedProperties.length > 0;
    boolean hasFooter = r.getFile() != null;
    if (hasParameters || hasFooter)
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));

    labelRows.add(getStyles().labelRow(STYLE_ResourceTitleRow, //
            getStyles().labelCell(STYLE_ResourceTitleCell, builder.toString(), Span.colSpan(3))));
    width += builder.length();

    // Rendering of separator line fails in graphviz 2.28 with an error
    // labelRows.add(getStyles().rowSeparator());
    if (hasParameters || hasFooter) {
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
        labelRows.add(
                getStyles().labelRow("RowSeparator", getStyles().labelCell("HRCell", "", Span.colSpan(3))));
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
    }
    // parameters
    for (CatalogResourceParameter a : sortedProperties) {
        final String aName = a.getName();

        // output file contents as "DATA" as we can't fit the entire contents into a cell.
        List<String> values = "content".equals(aName) ? Lists.newArrayList("DATA") : a.getValue();
        builder = new StringBuilder();
        for (String v : values) {
            builder.append(v);
            builder.append(" ");
        }
        // remove trailing space
        builder.deleteCharAt(builder.length() - 1);
        String value = builder.toString();

        labelRows.add(getStyles().labelRow(STYLE_ResourcePropertyRow, //
                getStyles().labelCell(STYLE_ResourcePropertyName, a.getName()), //
                getStyles().labelCell(STYLE_ResourcePropertyValue, DOUBLE_RIGHT_ARROW + value, Span.colSpan(2)) //
        ));

        int tmpWidth = a.getName().length() + value.length() + 2;
        if (tmpWidth > width)
            width = tmpWidth;
    }

    // A footer with filename[line]
    // (is not always present)
    if (hasFooter) {
        builder = new StringBuilder();
        // shorten the text by making it relative to root if possible
        if (root != null)
            builder.append(new Path(r.getFile()).makeRelativeTo(root).toString());
        else
            builder.append(r.getFile());
        if (r.getLine() != null) {
            builder.append("[");
            builder.append(r.getLine());
            builder.append("]");
        }
        String tooltip = builder.toString();
        if (builder.length() > width) {
            builder.delete(0, builder.length() - width);
            builder.insert(0, "[...]");
        }

        if (hasParameters)
            labelRows.add(getStyles().labelRow("RowSeparator",
                    getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
        int line = -1;
        try {
            line = Integer.valueOf(r.getLine());
        } catch (NumberFormatException e) {
            line = -1;
        }

        labelRows.add(getStyles().labelRow(STYLE_ResourceFileInfoRow, //
                getStyles().labelCell(STYLE_ResourceFileInfoCell, builder.toString(), Span.colSpan(3))
                        .withStyles(//
                                getStyles().tooltip(tooltip), //
                                getStyles().href(
                                        getHrefProducer().hrefToManifest(new Path(r.getFile()), root, line)) //
                )) //
        );
    } else if (hasParameters) {
        // add a bit of padding at the bottom if there is no footer
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
    }

    return StyleSet.withStyle(//
            getStyles().labelFormat(//
                    getStyles().labelTable(STYLE_ResourceTable, //
                            labelRows.toArray(new LabelRow[labelRows.size()]))));

}

From source file:eu.numberfour.n4js.ui.workingsets.internal.HideWorkingSetAction.java

@Override
public void run() {
    final IStructuredSelection selection = getStructuredSelection();
    final Object[] selectionElements = selection.toArray();
    final WorkingSet[] selectedWorkingSets = Arrays2.filter(selectionElements, WorkingSet.class);

    final WorkingSetManager manager = selectedWorkingSets[0].getWorkingSetManager();
    final WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(manager);
    final WorkingSet[] newAllItems = manager.getAllWorkingSets();
    final List<WorkingSet> newItems = newArrayList(manager.getWorkingSets());
    for (final WorkingSet toHide : selectedWorkingSets) {
        newItems.remove(toHide);/*  w w  w.  j  a v  a 2 s.c  om*/
    }
    final Diff<WorkingSet> diff = builder.build(Iterables.toArray(newItems, WorkingSet.class), newAllItems);
    if (!diff.isEmpty()) {
        manager.updateState(diff);
        manager.saveState(new NullProgressMonitor());
        manager.getWorkingSetManagerBroker().refreshNavigator();
    }
}

From source file:com.inmobi.grill.cli.commands.GrillDimensionCommands.java

@CliCommand(value = "create dimension", help = "Create a new dimension table")
public String createDimension(@CliOption(key = { "",
        "dimension" }, mandatory = true, help = "<dim-spec> <storage-spec>") String dimPair) {

    Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(dimPair);
    String[] pair = Iterables.toArray(parts, String.class);
    if (pair.length != 2) {
        return "Syntax error, please try in following "
                + "format. create fact <fact spec path> <storage spec path>";
    }//from www.  ja v  a 2  s .  co  m

    File f = new File(pair[0]);
    if (!f.exists()) {
        return "dim spec path" + f.getAbsolutePath() + " does not exist. Please check the path";
    }

    f = new File(pair[1]);
    if (!f.exists()) {
        return "storage spec path" + f.getAbsolutePath() + " does not exist. Please check the path";
    }
    APIResult result = client.createDimension(pair[0], pair[1]);
    if (result.getStatus() == APIResult.Status.SUCCEEDED) {
        return "create dimension table succeeded";
    } else {
        return "create dimension table failed";
    }
}

From source file:org.eclipse.sirius.common.acceleo.interpreter.SiriusContentAssistProcessor.java

/**
 * {@inheritDoc}/*from   w w  w .jav a2s .  co m*/
 * 
 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
 *      int)
 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    if (viewer instanceof SiriusInterpreterSourceViewer) {
        final Iterable<ContentProposal> vpProposals = ((SiriusInterpreterSourceViewer) viewer)
                .getComputedProposals();
        if (vpProposals != null) {
            final Iterable<ICompletionProposal> proposals = Iterables.transform(vpProposals,
                    new CompletionProposalConverter(viewer.getSelectedRange()));
            return Iterables.toArray(proposals, ICompletionProposal.class);
        }
    }
    return null;
}

From source file:org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.LatencyContentProvider.java

@Override
public void inputChanged(@Nullable Viewer viewer, @Nullable Object oldInput, @Nullable Object newInput) {
    fTableViewer = (TableViewer) viewer;
    if (newInput instanceof ISegmentStore<?>) {
        ISegmentStore<?> segmentStore = (ISegmentStore<?>) newInput;
        fSegmentArray = Iterables.toArray(segmentStore, ISegment.class);
        if (fComparator != null) {
            Arrays.sort(fSegmentArray, fComparator);
        }/*  w w  w.  j a v  a  2 s .c o  m*/
    } else {
        fSegmentArray = null;
    }
}