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.interedition.collatex.util.GreedyStringTilingAlgorithm.java

@Override
public void collate(VariantGraph graph, Iterable<Token> witness) {
    final VariantGraph.Vertex[][] vertices = VariantGraphRanking.of(graph).asArray();
    final Token[] tokens = Iterables.toArray(witness, Token.class);

    final SortedSet<SortedSet<VertexMatch.WithTokenIndex>> matches = new TreeSet<SortedSet<VertexMatch.WithTokenIndex>>(
            VertexMatch.<VertexMatch.WithTokenIndex>setComparator());
    for (Match match : match(vertices, tokens, equality, minimumTileLength)) {
        final SortedSet<VertexMatch.WithTokenIndex> phrase = new TreeSet<VertexMatch.WithTokenIndex>();
        for (int mc = 0, ml = match.length; mc < ml; mc++) {
            final int rank = match.left + mc;
            phrase.add(new VertexMatch.WithTokenIndex(vertices[rank][0], rank, match.right + mc));
        }/*w w w.j a v a  2 s . co  m*/
        matches.add(phrase);
    }

    merge(graph, vertices, tokens, matches);
}

From source file:com.squareup.javapoet.JavaPoet.java

public void writeTo(Filer filer) throws IOException {
    for (JavaFile javaFile : javaFiles) {
        JavaFileObject filerSourceFile = filer.createSourceFile(
                javaFile.packageName + "." + javaFile.typeSpec.name,
                Iterables.toArray(javaFile.typeSpec.originatingElements, Element.class));
        try (Writer writer = filerSourceFile.openWriter()) {
            javaFile.emit(writer);/*from w ww  .ja v a  2  s  .c o m*/
        } catch (Exception e) {
            try {
                filerSourceFile.delete();
            } catch (Exception ignored) {
            }
            throw e;
        }
    }
}

From source file:com.google.devtools.build.lib.analysis.test.InstrumentedFileManifestAction.java

@Override
public DeterministicWriter newDeterministicWriter(ActionExecutionContext ctx) {
    return new DeterministicWriter() {
        @Override/*from  w w w. ja v a 2s. c  o  m*/
        public void writeOutputFile(OutputStream out) throws IOException {
            // Sort the exec paths before writing them out.
            String[] fileNames = Iterables.toArray(Iterables.transform(files, TO_EXEC_PATH), String.class);
            Arrays.sort(fileNames);
            try (Writer writer = new OutputStreamWriter(out, ISO_8859_1)) {
                for (String name : fileNames) {
                    writer.write(name);
                    writer.write('\n');
                }
            }
        }
    };
}

From source file:org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper.java

@Override
public IHyperlink[] createHyperlinksByOffset(XtextResource resource, int offset,
        boolean createMultipleHyperlinks) {
    List<IHyperlink> links = Lists.newArrayList();
    IHyperlinkAcceptor acceptor = new HyperlinkAcceptor(links);

    createHyperlinksByOffset(resource, offset, acceptor);
    if (!links.isEmpty())
        return Iterables.toArray(links, IHyperlink.class);
    return null;/*from w w w  . j av a  2s . c  o  m*/
}

From source file:com.android.tools.idea.npw.template.components.PackageComboProvider.java

@NotNull
@Override/*ww w  .  j  a va 2  s .  co  m*/
protected EditorComboBox createComponent(@NotNull Parameter parameter) {
    Document doc = JavaReferenceEditorUtil.createDocument(myInitialPackage, myProject, false,
            JavaCodeFragment.VisibilityChecker.PROJECT_SCOPE_VISIBLE);
    assert doc != null;
    final EditorComboBox classComboBox = new EditorComboBox(doc, myProject, StdFileTypes.JAVA);

    // Make sure our suggested package is in the recents list and at the top
    RecentsManager.getInstance(myProject).registerRecentEntry(myRecentsKey, myInitialPackage);
    List<String> recents = RecentsManager.getInstance(myProject).getRecentEntries(myRecentsKey);
    assert recents != null; // We just added at least one entry!

    classComboBox.setHistory(Iterables.toArray(recents, String.class));
    return classComboBox;
}

From source file:com.querydsl.core.types.path.PathInits.java

public PathInits(String... initStrs) {
    boolean _initAllProps = false;
    PathInits _defaultValue = DEFAULT;/* ww w . j a va 2 s . c  om*/

    Map<String, Collection<String>> properties = Maps.newHashMap();
    for (String initStr : initStrs) {
        if (initStr.equals("*")) {
            _initAllProps = true;
        } else if (initStr.startsWith("*.")) {
            _initAllProps = true;
            _defaultValue = new PathInits(initStr.substring(2));
        } else {
            String key = initStr;
            List<String> inits = Collections.emptyList();
            if (initStr.contains(".")) {
                key = initStr.substring(0, initStr.indexOf('.'));
                inits = ImmutableList.of(initStr.substring(key.length() + 1));
            }
            Collection<String> values = properties.get(key);
            if (values == null) {
                values = new ArrayList<String>();
                properties.put(key, values);
            }
            values.addAll(inits);
        }
    }

    for (Map.Entry<String, Collection<String>> entry : properties.entrySet()) {
        PathInits inits = new PathInits(Iterables.toArray(entry.getValue(), String.class));
        propertyToInits.put(entry.getKey(), inits);
    }

    initAllProps = _initAllProps;
    defaultValue = _defaultValue;
}

From source file:edu.umn.msi.tropix.persistence.service.impl.SearchServiceImpl.java

private TropixObject[] filterSearchResults(final List<TropixObject> objects) {
    final Iterable<TropixObject> filteredObjects = Iterables.filter(objects, new Predicate<TropixObject>() {
        public boolean apply(final TropixObject object) {
            return !(object instanceof VirtualFolder);
        }//from w w w . j a v  a  2s  .  c o  m
    });
    return Iterables.toArray(filteredObjects, TropixObject.class);
}

From source file:de.csenk.gwt.commons.bean.rebind.observe.ObservableBeanModel.java

/**
 * @param logger /*  w  ww  .  ja va  2 s .c  om*/
 * @param methods
 * @param typeOracle 
 * @return
 * @throws UnableToCompleteException 
 */
private static Map<String, ObservableBeanPropertyModel> modelProperties(TreeLogger logger,
        Set<ObservableBeanMethodModel> methods, TypeOracle typeOracle) throws UnableToCompleteException {
    final Multimap<String, ObservableBeanMethodModel> associatedMethods = LinkedListMultimap.create();
    for (ObservableBeanMethodModel methodModel : methods) {
        final JBeanMethod action = methodModel.getAction();
        if (action != JBeanMethod.SET && action != JBeanMethod.GET)
            continue;

        final String propertyName = action.inferName(methodModel.getMethod());
        associatedMethods.put(propertyName, methodModel);
    }

    final Map<String, ObservableBeanPropertyModel> properties = Maps.newHashMap();
    for (String propertyName : associatedMethods.keySet()) {
        if (properties.containsKey(propertyName))
            die(logger, "Multiple getters/setters for property %s. Check spelling and for correct camel case.",
                    propertyName);

        final ObservableBeanMethodModel[] propertyAccessors = Iterables
                .toArray(associatedMethods.get(propertyName), ObservableBeanMethodModel.class);
        final JType propertyType = determinePropertyType(propertyAccessors[0], typeOracle);

        properties.put(propertyName,
                ObservableBeanPropertyModel.create(propertyName, propertyType, propertyAccessors));
    }

    return ImmutableMap.copyOf(properties);
}

From source file:npanday.nuget.NugetVersionSpec.java

public static NugetVersionSpec tryParse(String value) {
    Preconditions.checkNotNull(value);/*from  w  w  w . java2s  . c o m*/

    value = value.trim();
    NugetVersionSpec versionSpec = new NugetVersionSpec();

    // First, try to parse it as a plain version string
    NugetSemanticVersion version = NugetSemanticVersion.tryParse(value);
    if (version != null) {
        // A plain version is treated as an inclusive minimum range
        versionSpec.IsMinInclusive = true;
        versionSpec.MinVersion = version;
        return versionSpec;
    }

    // Fail early if the string is too short to be valid
    if (value.length() < 3) {
        return null;
    }

    // The first character must be [ ot (
    switch (value.charAt(0)) {
    case '[':
        versionSpec.IsMinInclusive = true;
        break;
    case '(':
        versionSpec.IsMinInclusive = false;
        break;
    default:
        return null;
    }

    // The last character must be ] ot )
    switch (value.charAt(value.length() - 1)) {
    case ']':
        versionSpec.IsMaxInclusive = true;
        break;
    case ')':
        versionSpec.IsMaxInclusive = false;
        break;
    default:
        return null;
    }

    // Get rid of the two brackets
    value = value.substring(1, value.length() - 1);

    // Split by comma, and make sure we don't get more than two pieces
    String[] parts = Iterables.toArray(VERSIONS_IN_RANGE.split(value), String.class);
    if (parts.length > 2 || parts.length == 0) {
        return null;
    }

    // If there is only one piece, we use it for both min and max
    String minVersionString = parts[0];
    String maxVersionString = (parts.length == 2) ? parts[1] : parts[0];

    NugetSemanticVersion minVersion = NugetSemanticVersion.tryParse(minVersionString);
    NugetSemanticVersion maxVersion = NugetSemanticVersion.tryParse(maxVersionString);

    if (minVersion == null || maxVersion == null) {
        return null;
    }

    versionSpec.MinVersion = minVersion;
    versionSpec.MaxVersion = maxVersion;

    return versionSpec;
}

From source file:edu.umn.msi.tropix.proteomics.idpicker.impl.IdPickerJobProcessorImpl.java

@Override
protected void doPreprocessing() {
    databaseContext.get(getStagingDirectory().getOutputContext(DATABASE_PATH));

    fileMaskCreator = new FileMaskCreator(parameters);

    writeSampleDirectories();//  w  w  w  .j a  v a  2 s.c om
    savePepXmlFiles();
    getStagingDirectory().getOutputContext("idpQonvert-files")
            .put(fileMaskCreator.getQonvertLines().getBytes());
    getStagingDirectory().getOutputContext("idpAssemble-files")
            .put(fileMaskCreator.getAssembleLines().getBytes());
    writeQonvertCfg();
    writeAssembleCfg();
    writeReportCfg();
    final JobDescriptionType jobDescription = getJobDescription().getJobDescriptionType();
    final List<String> arguments = Lists.newArrayList();
    jobDescription.setArgument(Iterables.toArray(arguments, String.class));
    jobDescription.setDirectory(getStagingDirectory().getAbsolutePath());
}