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:ec.ui.ATsList.java

@Override
public InfoType[] getInformation() {
    return Iterables.toArray(information, InfoType.class);
}

From source file:com.jejking.hh.nord.gazetteer.osm.RelationWaysToPolygon.java

private LinearRing[] buildHoles(OsmRelation osmRelation) {
    Iterable<LinearRing> linearRings = Iterables.transform(getInners(osmRelation),
            new Function<OsmRelation.Member, LinearRing>() {

                @Override/*from  ww  w.  ja  v  a2 s  .c o  m*/
                public LinearRing apply(OsmRelation.Member member) {
                    return linearRingFromMember(member);
                }

            });
    return Iterables.toArray(linearRings, LinearRing.class);
}

From source file:chibill.DeobLoader.loader.Remappers.java

public void setupLoadOnly(String deobfFileName, boolean loadAll) {
    try {//  w w  w  .  jav a2 s. c om
        File mapData = new File(deobfFileName);
        LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
        CharSource srgSource = zis.asCharSource(Charsets.UTF_8);
        List<String> srgList = srgSource.readLines();
        rawMethodMaps = Maps.newHashMap();
        rawFieldMaps = Maps.newHashMap();
        Builder<String, String> builder = ImmutableBiMap.<String, String>builder();
        Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
        for (String line : srgList) {
            String[] parts = Iterables.toArray(splitter.split(line), String.class);
            String typ = parts[0];
            if ("CL".equals(typ)) {
                parseClass(builder, parts);
            } else if ("MD".equals(typ) && loadAll) {
                parseMethod(parts);
            } else if ("FD".equals(typ) && loadAll) {
                parseField(parts);
            }
        }
        classNameBiMap = builder.build();
    } catch (IOException ioe) {
    }
    methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
    fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());

}

From source file:org.apache.flex.compiler.internal.definitions.ClassDefinitionBase.java

@Override
public IClassDefinition[] resolveAncestry(ICompilerProject project) {
    return Iterables.toArray(classIterable(project, true), IClassDefinition.class);
}

From source file:com.google.errorprone.refaster.RefasterRuleCompiler.java

private String[] prepareCompilation(String[] argv, Context context) throws InvalidCommandLineOptionException {
    context.put(DiagnosticListener.class, new DiagnosticCollector<JavaFileObject>());
    List<String> newArgs = new ArrayList<>(Arrays.asList(argv));
    Iterator<String> itr = newArgs.iterator();
    String path = null;//from  www  .  ja  v a  2s .c  o  m
    while (itr.hasNext()) {
        if (itr.next().equals("--out")) {
            itr.remove();
            path = itr.next();
            itr.remove();
            break;
        }
    }
    checkArgument(path != null, "No --out specified");

    MaskedClassLoader.preRegisterFileManager(context);

    MultiTaskListener.instance(context)
            .add(new RefasterRuleCompilerAnalyzer(context, FileSystems.getDefault().getPath(path)));

    return Iterables.toArray(newArgs, String.class);
}

From source file:org.apache.lens.cli.commands.LensStorageCommands.java

/**
 * Update storage./*from  w w w  .  j  a  va  2s.c  o m*/
 *
 * @param specPair the spec pair
 * @return the string
 */
@CliCommand(value = "update storage", help = "update storage")
public String updateStorage(@CliOption(key = { "",
        "storage" }, mandatory = true, help = "<storage-name> <path to storage-spec>") String specPair) {
    Iterable<String> parts = Splitter.on(' ').trimResults().omitEmptyStrings().split(specPair);
    String[] pair = Iterables.toArray(parts, String.class);
    if (pair.length != 2) {
        return "Syntax error, please try in following "
                + "format. update storage <storage-name> <storage spec path>";
    }

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

    if (!f.exists()) {
        return "Storage spec path" + f.getAbsolutePath() + " does not exist. Please check the path";
    }

    APIResult result = getClient().updateStorage(pair[0], pair[1]);
    if (result.getStatus() == APIResult.Status.SUCCEEDED) {
        return "Update of " + pair[0] + " succeeded";
    } else {
        return "Update of " + pair[0] + " failed";
    }
}

From source file:org.kalypso.zml.ui.table.commands.toolbar.ZmlCommandHideColumns.java

private String[] getColumnTypes(final Map parameters) {
    final String types = (String) parameters.get("column.type"); //$NON-NLS-1$
    if (StringUtils.isEmpty(types))
        return new String[] {};

    final Iterable<String> columns = Splitter.on(";").trimResults().omitEmptyStrings().split(types); //$NON-NLS-1$

    return Iterables.toArray(columns, String.class);
}

From source file:co.cask.hydrator.plugin.batch.spark.SparkUtils.java

/**
 * Get the feature list of the features that have to be used for training/prediction depending on the
 * featuresToInclude or featuresToInclude list.
 *
 * @param inputSchema       schema of the received record.
 * @param featuresToInclude features to be used for training/prediction.
 * @param featuresToExclude features to be excluded when training/predicting.
 * @param predictionField   field containing the prediction values.
 * @return feature list to be used for training/prediction.
 *///from  w ww  . j  a  v  a 2 s.c om
static Map<String, Integer> getFeatureList(Schema inputSchema, @Nullable String featuresToInclude,
        @Nullable String featuresToExclude, String predictionField) {
    if (!Strings.isNullOrEmpty(featuresToExclude) && !Strings.isNullOrEmpty(featuresToInclude)) {
        throw new IllegalArgumentException(
                "Cannot specify values for both featuresToInclude and featuresToExclude. "
                        + "Please specify fields for one.");
    }
    Map<String, Integer> fields = new HashMap<>();

    if (!Strings.isNullOrEmpty(featuresToInclude)) {
        Iterable<String> tokens = Splitter.on(',').trimResults().split(featuresToInclude);
        String[] features = Iterables.toArray(tokens, String.class);
        for (int i = 0; i < features.length; i++) {
            String field = features[i];
            Schema.Field inputField = inputSchema.getField(field);
            if (!field.equals(predictionField) && inputField != null) {
                fields.put(field, i);
            }
        }
        return fields;
    }

    Set<String> excludeFeatures = new HashSet<>();
    if (!Strings.isNullOrEmpty(featuresToExclude)) {
        excludeFeatures.addAll(Lists.newArrayList(Splitter.on(',').trimResults().split(featuresToExclude)));
    }
    Object[] inputSchemaFields = inputSchema.getFields().toArray();
    for (int i = 0; i < inputSchemaFields.length; i++) {
        String field = ((Schema.Field) inputSchemaFields[i]).getName();
        if (!field.equals(predictionField) && !excludeFeatures.contains(field)) {
            fields.put(field, i);
        }
    }
    return fields;
}

From source file:io.druid.indexer.path.StaticPathSpec.java

private static void addInputPath(Job job, Iterable<String> pathStrings,
        Class<? extends InputFormat> inputFormatClass) {
    Configuration conf = job.getConfiguration();
    StringBuilder inputFormats = new StringBuilder(Strings.nullToEmpty(conf.get(MultipleInputs.DIR_FORMATS)));

    String[] paths = Iterables.toArray(pathStrings, String.class);
    for (int i = 0; i < paths.length - 1; i++) {
        if (inputFormats.length() > 0) {
            inputFormats.append(',');
        }//from   w ww.j  a  v a  2  s .c om
        inputFormats.append(paths[i]).append(';').append(inputFormatClass.getName());
    }
    if (inputFormats.length() > 0) {
        conf.set(MultipleInputs.DIR_FORMATS, inputFormats.toString());
    }
    // add last one separately for possible initialization in MultipleInputs
    MultipleInputs.addInputPath(job, new Path(paths[paths.length - 1]), inputFormatClass);
}

From source file:org.eclipse.sirius.diagram.business.internal.migration.NoteAttachmentWithoutSourceOrTargetMigrationParticipant.java

private void deleteNoteAttachmentWithoutSourceOrTarget(Diagram gmfDiagram) {
    Iterable<Connector> noteAttachmentsToRemoveIter = Iterables
            .filter(Iterables.filter(gmfDiagram.getEdges(), Connector.class), new Predicate<Connector>() {
                @Override//w ww  . j  a  va2 s  .  com
                public boolean apply(Connector connector) {
                    if (ViewType.NOTEATTACHMENT.equals(connector.getType())) {
                        if (connector.getSource() == null || connector.getTarget() == null) {
                            return true;
                        }
                    }
                    return false;
                }
            });
    // Make a copy to avoid modification of edges list during the iteration
    // on it.
    Connector[] noteAttachmentsToRemove = Iterables.toArray(noteAttachmentsToRemoveIter, Connector.class);
    // Remove each invalid note attachments
    for (Connector connector : noteAttachmentsToRemove) {
        gmfDiagram.removeEdge(connector);
    }
}