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:org.graylog2.inputs.twitter.TwitterTransport.java

@Override
public void launch(final MessageInput input) throws MisfireException {
    final ConfigurationBuilder cb = new ConfigurationBuilder()
            .setOAuthConsumerKey(configuration.getString(CK_OAUTH_CONSUMER_KEY))
            .setOAuthConsumerSecret(configuration.getString(CK_OAUTH_CONSUMER_SECRET))
            .setOAuthAccessToken(configuration.getString(CK_OAUTH_ACCESS_TOKEN))
            .setOAuthAccessTokenSecret(configuration.getString(CK_OAUTH_ACCESS_TOKEN_SECRET))
            .setJSONStoreEnabled(true);//w  ww.  jav  a  2 s.  com

    final StatusListener listener = new StatusListener() {
        public void onStatus(final Status status) {
            try {
                input.processRawMessage(createMessageFromStatus(status));
            } catch (IOException e) {
                LOG.debug("Error while processing tweet status", e);
            }
        }

        private RawMessage createMessageFromStatus(final Status status) throws IOException {
            return new RawMessage(TwitterObjectFactory.getRawJSON(status).getBytes(StandardCharsets.UTF_8));
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onException(final Exception ex) {
            LOG.error("Error while reading Twitter stream", ex);
        }

        @Override
        public void onScrubGeo(long lon, long lat) {
        }

        @Override
        public void onStallWarning(StallWarning stallWarning) {
            LOG.info("Stall warning: {} ({}% full)", stallWarning.getMessage(), stallWarning.getPercentFull());
        }
    };

    final String[] track = Iterables.toArray(
            Splitter.on(',').omitEmptyStrings().trimResults().split(configuration.getString(CK_KEYWORDS)),
            String.class);
    final FilterQuery filterQuery = new FilterQuery();
    filterQuery.track(track);

    if (twitterStream == null) {
        twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    }

    twitterStream.addListener(listener);
    twitterStream.filter(filterQuery);
}

From source file:org.polymap.rhei.um.ui.UsersTableViewer.java

public void reload() {
    //        super.remove( elements );
    setInput(Iterables.toArray(content, User.class));
}

From source file:ru.org.linux.user.UserEventDao.java

public void insertTopicNotification(final int topicId, Iterable<Integer> userIds) {
    @SuppressWarnings("unchecked")
    Map<String, Object>[] batch = Iterables
            .toArray(Iterables.transform(userIds, new Function<Integer, Map<String, Object>>() {
                @Nullable/* www. j  av a  2  s.co m*/
                @Override
                public Map<String, Object> apply(Integer userId) {
                    return ImmutableMap.<String, Object>of("topic", topicId, "userid", userId);
                }
            }), Map.class);

    insertTopicUsersNotified.executeBatch(batch);
}

From source file:it.sayservice.platform.smartplanner.utils.LegGenerator.java

private static List<String[]> readFileGetLines(String fileName) throws IOException {
    FileInputStream fis = new FileInputStream(new File(fileName));
    UnicodeReader ur = new UnicodeReader(fis, "UTF-8");

    List<String[]> lines = new ArrayList<String[]>();
    for (CSVRecord record : CSVFormat.DEFAULT.parse(ur)) {
        String[] line = Iterables.toArray(record, String.class);
        lines.add(line);/* ww  w  .  jav a  2  s.com*/
    }
    lines.get(0)[0] = lines.get(0)[0].replaceAll(UTF8_BOM, "");
    return lines;
}

From source file:org.eclipse.sirius.business.internal.movida.registry.StatusUpdater.java

private void checkAllActualDependenciesAreAvailable(Entry entry) {
    Set<URI> actualPhysical = ImmutableSet
            .copyOf(Iterables.transform(entry.getActualDependencies(), new Function<URI, URI>() {
                @Override//  ww  w.  ja v a  2  s  .  c o  m
                public URI apply(URI from) {
                    return resourceSet.getURIConverter().normalize(from);
                }
            }));
    Set<URI> availablePhysical = ImmutableSet
            .copyOf(Iterables.transform(entries.values(), new Function<Entry, URI>() {
                @Override
                public URI apply(Entry from) {
                    return from.getResource().getURI();
                };
            }));
    Set<URI> unavailable = Sets.difference(actualPhysical, availablePhysical);
    if (!unavailable.isEmpty()) {
        entry.setState(ViewpointState.INVALID);
        Object[] data = Iterables.toArray(Iterables.transform(unavailable, Functions.toStringFunction()),
                String.class);
        addDiagnostic(entry, Diagnostic.ERROR, PHYSICAL_DEPENDENCY_UNAVAILABLE,
                "Sirius definition depends on resources not available.", data); //$NON-NLS-1$
    }
}

From source file:edu.mayo.cts2.framework.core.xml.DelegatingMarshaller.java

/**
 * Instantiates a new delgating marshaller.
 *
 * @throws Exception the exception//from www.j  a v a2  s. c  om
 */
public DelegatingMarshaller(boolean validate, ModelXmlPropertiesHandler modelXmlPropertiesHandler) {
    super();
    this.modelXmlPropertiesHandler = modelXmlPropertiesHandler;
    this.castorBuilderProperties = this.modelXmlPropertiesHandler.getCastorBuilderProperties();
    this.namespaceLocationProperties = this.modelXmlPropertiesHandler.getNamespaceLocationProperties();
    this.namespaceMappingProperties = this.modelXmlPropertiesHandler.getNamespaceMappingProperties();

    this.populateNamespaceMaps(this.namespaceMappingProperties, this.namespaceLocationProperties);

    String proxyInterfaces = this.createMapFromProperties(this.modelXmlPropertiesHandler.getCastorProperties())
            .get(PROXY_INTERFACES_PROP);

    this.marshallSuperClasses = new HashSet<String>(Arrays.asList(StringUtils.split(proxyInterfaces, ',')));

    String nsMappings = (String) this.castorBuilderProperties.get(NS_PROP);

    String[] nsAndPackage = StringUtils.split(nsMappings, ",");

    List<String> allPackages = new ArrayList<String>();

    Map<String, String> namespacePackageMapping = new HashMap<String, String>();

    for (String entry : nsAndPackage) {
        String ns = StringUtils.substringBefore(entry, "=");
        String pkg = StringUtils.substringAfter(entry, "=");

        packageToMarshallerMap.put(pkg, createNewMarshaller(ns, validate));
        allPackages.add(pkg);

        namespacePackageMapping.put(ns, pkg);
    }

    this.defaultMarshaller = new PatchedCastorMarshaller();
    this.defaultMarshaller.setNamespaceMappings(this.namespaceMap);
    this.defaultMarshaller.setTargetPackages(Iterables.toArray(allPackages, String.class));
    this.defaultMarshaller.setNamespaceToPackageMapping(namespacePackageMapping);
    this.defaultMarshaller.setValidating(validate);

    try {
        this.defaultMarshaller.afterPropertiesSet();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.whirr.actions.ConfigureClusterAction.java

private Map<String, ? extends NodeMetadata> getNodesForInstanceIdsInCluster(Cluster cluster,
        ComputeService computeService) {
    Iterable<String> ids = Iterables.transform(cluster.getInstances(), new Function<Instance, String>() {

        @Override//from  w  w  w.j  a  va2s.c  o  m
        public String apply(Instance arg0) {
            return arg0.getId();
        }

    });

    Set<? extends NodeMetadata> nodes = computeService
            .listNodesDetailsMatching(NodePredicates.withIds(Iterables.toArray(ids, String.class)));

    return Maps.uniqueIndex(nodes, getNodeId);
}

From source file:org.hibernate.ejb.ConfigurableListenerBeansHibernatePersistence.java

public <L> L[] concatListeners(Class<L> listenerClass, List<L> eventListeners, L[] extantListeners) {
    if (eventListeners == null) {
        eventListeners = Lists.newArrayList();
    }//  w w  w  .  j a v  a 2s  .  c  om
    if (extantListeners == null) {
        return Iterables.toArray(eventListeners, listenerClass);
    }
    return Iterables.toArray(Iterables.concat(Arrays.asList(extantListeners), eventListeners), listenerClass);
}

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

/**
 * Sets a list of theme names separated by comma or spaces.
 * //from ww w.ja  v a  2  s.co m
 * @param themes Comma-separated or space-separated theme names.
 */
// TODO Should this do string-splitting? setEnumeration() and setStates() don't.
public void setThemes(final String themes) {
    if (themes == null) {
        this.themes = new String[0];
    } else {
        final Iterable<String> split = Splitter.onPattern("[,\\s]") // comma or space
                .trimResults().omitEmptyStrings().split(themes);
        this.themes = Iterables.toArray(split, String.class);
    }
}

From source file:org.jclouds.chef.filters.SignedHeaderAuth.java

@VisibleForTesting
HttpRequest calculateAndReplaceAuthorizationHeaders(HttpRequest request, String toSign) throws HttpException {
    String signature = sign(toSign);
    if (signatureWire.enabled())
        signatureWire.input(Strings2.toInputStream(signature));
    String[] signatureLines = Iterables.toArray(Splitter.fixedLength(60).split(signature), String.class);

    Multimap<String, String> headers = ArrayListMultimap.create();
    for (int i = 0; i < signatureLines.length; i++) {
        headers.put("X-Ops-Authorization-" + (i + 1), signatureLines[i]);
    }//from www.j a  va 2  s.c  o  m
    return request.toBuilder().replaceHeaders(headers).build();
}