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.nbdemetra.ui.nodes.Nodes.java

@Nonnull
public static Action[] actionsForPath(@Nonnull String path) {
    return Iterables.toArray(Utilities.actionsForPath(path), Action.class);
}

From source file:org.apache.isis.security.shiro.util.Util.java

public static Map<String, List<String>> parse(String permissionsByRoleStr) {
    Map<String, List<String>> perms = Maps.newHashMap();
    for (String roleAndPermsStr : Splitter.on(";").split(permissionsByRoleStr)) {
        final Iterable<String> split = Splitter.on("=").split(roleAndPermsStr);
        final String[] roleAndPerms = Iterables.toArray(split, String.class);
        if (roleAndPerms.length != 2) {
            continue;
        }/*ww  w.  j av a  2s.c  o  m*/
        final String role = roleAndPerms[0].trim();
        final String permStr = roleAndPerms[1].trim();
        perms.put(role, Lists.newArrayList(Iterables.transform(Splitter.on(",").split(permStr), TRIM)));
    }
    return perms;
}

From source file:com.cloudera.director.google.util.Urls.java

public static String getProject(String fullResourceUrl) {
    if (fullResourceUrl == null || fullResourceUrl.isEmpty()) {
        return null;
    }// w  w  w.  j a v a 2s  .c om

    List<String> pathParts = new GenericUrl(fullResourceUrl).getPathParts();

    if (pathParts == null) {
        throw new IllegalArgumentException(String.format(MALFORMED_RESOURCE_URL_MSG, fullResourceUrl));
    }

    String[] urlParts = Iterables.toArray(pathParts, String.class);

    // Resource urls look like so: https://www.googleapis.com/compute/v1/projects/rhel-cloud/global/images/rhel-6-v20150526
    // The path parts begin after the host and include a leading "" path part to force the leading slash.
    if (urlParts.length < 8) {
        throw new IllegalArgumentException(String.format(MALFORMED_RESOURCE_URL_MSG, fullResourceUrl));
    } else {
        return urlParts[urlParts.length - 4];
    }
}

From source file:org.lanternpowered.server.util.collect.Collections3.java

public static String toString(Iterable<?> iterable) {
    if (iterable instanceof Collection) {
        return toString((Collection<?>) iterable);
    }/*from   w ww.  j  ava2  s  .c  o  m*/
    return Arrays.toString(Iterables.toArray(iterable, Object.class));
}

From source file:com.enonic.cms.web.webdav.DavSessionImpl.java

@Override
public String[] getLockTokens() {
    return Iterables.toArray(this.lockTokens, String.class);
}

From source file:org.elasticsearch.search.aggregations.BucketCollector.java

/**
 * Wrap the given collectors into a single instance.
 *///w  w w  .j  a v  a 2 s.c  o m
public static BucketCollector wrap(Iterable<? extends BucketCollector> collectorList) {
    final BucketCollector[] collectors = Iterables.toArray(collectorList, BucketCollector.class);
    switch (collectors.length) {
    case 0:
        return NO_OP_COLLECTOR;
    case 1:
        return collectors[0];
    default:
        return new BucketCollector() {

            @Override
            public void collect(int docId, long bucketOrdinal) throws IOException {
                for (BucketCollector collector : collectors) {
                    collector.collect(docId, bucketOrdinal);
                }
            }

            @Override
            public void setNextReader(AtomicReaderContext reader) {
                for (BucketCollector collector : collectors) {
                    collector.setNextReader(reader);
                }
            }

            @Override
            public void postCollection() throws IOException {
                for (BucketCollector collector : collectors) {
                    collector.postCollection();
                }
            }

        };
    }
}

From source file:org.elasticsearch.search.aggregations.LeafBucketCollector.java

public static LeafBucketCollector wrap(Iterable<LeafBucketCollector> collectors) {
    final Iterable<LeafBucketCollector> actualCollectors = Iterables.filter(collectors,
            new Predicate<LeafBucketCollector>() {
                @Override/*from   w  w  w  . j a va 2s .  c om*/
                public boolean apply(LeafBucketCollector c) {
                    return c != NO_OP_COLLECTOR;
                }
            });
    final LeafBucketCollector[] colls = Iterables.toArray(actualCollectors, LeafBucketCollector.class);
    switch (colls.length) {
    case 0:
        return NO_OP_COLLECTOR;
    case 1:
        return colls[0];
    default:
        return new LeafBucketCollector() {

            @Override
            public void setScorer(Scorer s) throws IOException {
                for (LeafBucketCollector c : colls) {
                    c.setScorer(s);
                }
            }

            @Override
            public void collect(int doc, long bucket) throws IOException {
                for (LeafBucketCollector c : colls) {
                    c.collect(doc, bucket);
                }
            }

        };
    }
}

From source file:org.eclipse.che.inject.PairArrayConverter.java

@Override
public Object convert(String value, TypeLiteral<?> toType) {
    final String[] pairs = Iterables.toArray(Splitter.on(",").split(value), String.class);
    @SuppressWarnings("unchecked")
    final Pair<String, String>[] result = new Pair[pairs.length];
    for (int i = 0; i < pairs.length; i++) {
        result[i] = PairConverter.fromString(pairs[i]);
    }//from w  w w.  java  2s . c o  m
    return result;
}

From source file:org.eclipse.che.inject.StringArrayConverter.java

@Override
public Object convert(String value, TypeLiteral<?> toType) {
    return Iterables.toArray(Splitter.on(PATTERN).split(value), String.class);
}

From source file:com.isotrol.impe3.nr.api.NodeSort.java

/**
 * Create a sort criteria.//  w  w w. ja  va  2s .c  o  m
 * @param fields Sort field specifications.
 * @return The sort criteria.
 */
public static NodeSort of(Iterable<NRSortField> fields) {
    checkNotNull(fields, "The sort field specifications must be provided");
    return new NodeSort(Iterables.toArray(fields, NRSortField.class));
}