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

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

Introduction

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

Prototype

public static String toString(Iterable<?> iterable) 

Source Link

Document

Returns a string representation of iterable , with the format [e1, e2, ..., en] (that is, identical to java.util.Arrays Arrays .toString(Iterables.toArray(iterable)) ).

Usage

From source file:edu.umn.msi.tropix.common.jobqueue.execution.DelegatingExecutionJobQueueImpl.java

public void setExecutionJobQueues(final Iterable<ExecutionJobQueue<JobDescription>> executionJobQueues) {
    LOG.debug("Setting delegate job queues to " + Iterables.toString(executionJobQueues));
    for (final ExecutionJobQueue<JobDescription> executionJobQueue : executionJobQueues) {
        final ExecutionType executionType = AnnotationUtils.findAnnotation(executionJobQueue.getClass(),
                ExecutionType.class);
        executionJobQueueMap.put(executionType.value(), executionJobQueue);
    }/*from w w w .  ja v  a 2s .c  om*/
}

From source file:com.enonic.cms.core.content.RegenerateIndexBatcher.java

public void regenerateIndex(ContentTypeEntity contentType, int batchSize, List<String> logEntries) {

    if (contentType == null) {
        throw new IllegalArgumentException("Given contentType cannot be null");
    }//w  w w. j  a  v  a2 s.c om
    if (batchSize <= 0) {
        throw new IllegalArgumentException("Given batchSize must be larger that zero");
    }

    List<ContentKey> allContentKeys = contentService.findContentKeysByContentType(contentType);

    int currentIndex = 0;

    while (currentIndex < allContentKeys.size()) {
        List<ContentKey> nextContentKeys = getNextContentKeys(allContentKeys, currentIndex, batchSize);

        if (nextContentKeys != null && nextContentKeys.size() > 0) {

            if (logEntries != null) {
                logEntries.add("Regenerating indexes, (batch: " + (currentIndex + 1) + " -> "
                        + (currentIndex + nextContentKeys.size()) + " of total " + allContentKeys.size()
                        + ") of content type '" + contentType.getName() + "'");
            }

            LOG.info("Regenerating indexes, (batch: " + (currentIndex + 1) + " -> "
                    + (currentIndex + nextContentKeys.size()) + " of total " + allContentKeys.size()
                    + ") of content type '" + contentType.getName() + "'");

            long start = System.currentTimeMillis();

            int retry = 0;
            boolean indexSuccess = false;
            do {
                try {
                    indexService.reindex(nextContentKeys);
                    indexSuccess = true;
                } catch (IndexException e) {
                    retry++;
                    if (retry > this.maxRetries) {
                        throw e;
                    } else {
                        LOG.warn("Unexpected error indexing batch with keys: "
                                + Iterables.toString(nextContentKeys), e);
                        LOG.warn("Retrying (" + retry + ") ...");
                    }
                }
            } while (!indexSuccess);
            //indexService.regenerateIndexBatched( nextContentKeys );

            long end = System.currentTimeMillis();

            LOG.info("Last batch took: " + ((end - start) / 1000) + " sec");

            currentIndex = currentIndex + batchSize;
        }
    }

}

From source file:clocker.docker.location.strategy.basic.LabelPlacementStrategy.java

@Override
public boolean apply(DockerHostLocation input) {
    Set<String> labels = MutableSet.copyOf(config().get(LABELS));
    if (labels.isEmpty())
        return true;
    SshMachineLocation ssh = input.getMachine();
    if (ssh instanceof JcloudsSshMachineLocation) {
        JcloudsSshMachineLocation jclouds = (JcloudsSshMachineLocation) ssh;
        NodeMetadata metadata = jclouds.getOptionalNode().get();
        Set<String> tags = MutableSet
                .copyOf(Iterables.transform(metadata.getTags(), new Function<String, String>() {
                    @Override/*from  w ww  .j ava 2s  .  co m*/
                    public String apply(String input) {
                        return Iterables.get(Splitter.on("=").split(input), 0);
                    }
                }));
        tags.addAll(metadata.getUserMetadata().keySet());
        labels.removeAll(tags);
        LOG.debug("Host {} : Tags {} : Remaining {}", new Object[] { input, Iterables.toString(tags),
                labels.isEmpty() ? "none" : Iterables.toString(labels) });
        return labels.isEmpty();
    } else {
        return false;
    }
}

From source file:edu.umn.msi.tropix.jobs.activities.ActivityContext.java

public String toString() {
    return "ActivityContext[credential=" + credentialStr + ",descriptions=["
            + Iterables.toString(activityDescriptions) + "]]";
}

From source file:brooklyn.entity.waratek.cloudvm.WaratekNodePlacementStrategy.java

@Override
public List<Location> locationsForAdditions(Multimap<Location, Entity> currentMembers,
        Collection<? extends Location> locs, int numToAdd) {
    if (locs.isEmpty() && numToAdd > 0) {
        throw new IllegalArgumentException(
                "No locations supplied, when requesting locations for " + numToAdd + " nodes");
    }/*from   ww  w.  ja v a  2s . c  o m*/

    List<WaratekMachineLocation> available = Lists
            .newArrayList(Iterables.filter(locs, WaratekMachineLocation.class));
    int remaining = numToAdd;
    for (WaratekMachineLocation machine : available) {
        remaining -= machine.getAvailableJvcCount();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requested {}, Need {} more from new JVMs, Current JVMs {}", new Object[] { numToAdd,
                remaining, Iterables.toString(Iterables.transform(locs, identity())) });
    }

    if (remaining > 0) {
        // FIXME what happens if there are no JVMs available?
        WaratekMachineLocation machine = Iterables.get(available, 0);

        // Grow the JVM cluster; based on max number of JVCs
        int maxSize = machine.getMaxSize();
        int delta = (remaining / maxSize) + (remaining % maxSize > 0 ? 1 : 0);
        Collection<Entity> added = machine.getWaratekInfrastructure().getVirtualMachineCluster()
                .resizeByDelta(delta);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Added {} JVMs: {}", delta, Iterables.toString(Iterables.transform(added, identity())));
        }

        // Add the newly created locations for each JVM
        // TODO wait until all JVMs have started up?
        Collection<WaratekMachineLocation> jvms = Collections2.transform(added,
                new Function<Entity, WaratekMachineLocation>() {
                    @Override
                    public WaratekMachineLocation apply(@Nullable Entity input) {
                        return ((JavaVirtualMachine) input).getDynamicLocation();
                    }
                });
        available.addAll(jvms);
    }

    // Logic from parent, with enhancements and types
    List<Location> result = Lists.newArrayList();
    Map<WaratekMachineLocation, Integer> sizes = toAvailableLocationSizes(available);
    for (int i = 0; i < numToAdd; i++) {
        WaratekMachineLocation smallest = null;
        int minSize = 0;
        for (WaratekMachineLocation loc : sizes.keySet()) {
            int size = sizes.get(loc);
            if (smallest == null || size < minSize) {
                smallest = loc;
                minSize = size;
            }
        }
        Preconditions.checkState(smallest != null, "smallest was null; locs=%s", sizes.keySet());
        result.add(smallest);

        // Update population in locations, removing if maximum reached
        int maxSize = smallest.getMaxSize();
        int currentSize = sizes.get(smallest) + 1;
        if (currentSize < maxSize) {
            sizes.put(smallest, currentSize);
        } else {
            sizes.remove(smallest);
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Placement for {} nodes: {}", numToAdd,
                Iterables.toString(Iterables.transform(result, identity())));
    }
    return result;
}

From source file:org.jclouds.vcloud.director.v1_5.predicates.TaskStatusEquals.java

@Override
public String toString() {
    return "taskStatusEquals(" + Iterables.toString(expectedStatuses) + ")";
}

From source file:com.torodb.mongowp.messages.request.InsertMessage.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();

    sb.append("InsertMessage{").append(super.toString()).append(", database='").append(database)
            .append("' , collection='").append(collection).append('\'');

    if (getDataContext().isValid()) {
        //TODO: This must be changed to preserve privacy on logs
        int docsLimit = 10;
        sb.append(", documents (limited to ").append(docsLimit).append(")=")
                .append(Iterables.toString(documents.getIterable(AllocationType.HEAP).limit(docsLimit)));
    } else {/*from   ww  w  .j av a2  s . com*/
        sb.append(", documents=<not available>");
    }
    return sb.append('}').toString();
}

From source file:com.palantir.lock.LockCollection.java

@Override
public String toString() {
    return "LockCollection " + Iterables.toString(entries());
}

From source file:com.github.jeluard.extend.PluginLoader.java

/**
 * Load the implementation of T.//  w ww .j  a v a  2s.co  m
 * Expects to detect a single {@link Plugin.Default} and a single alternative implementation.
 *
 * @param <T>
 * @param type
 * @return the implementation of T
 * @throws IllegalArgumentException if does not detect a single {@link Plugin.Default} and a single alternative implementation
 */
public <T extends Plugin.Alternative> T load(final Class<T> type) {
    Preconditions.checkNotNull(type, "null type");

    final List<T> plugins = Lists.newArrayList(this.loader.load(type));
    if (plugins.isEmpty()) {
        throw new IllegalArgumentException("No implementation for " + type);
    }
    final Predicate<T> defautPluginPredicate = new PluginLoader.DefaultPluginPredicate<T>();
    final Collection<T> defaults = Collections2.filter(plugins, defautPluginPredicate);
    final Collection<T> alternatives = Collections2.filter(plugins, Predicates.not(defautPluginPredicate));
    if (defaults.isEmpty()) {
        throw new IllegalArgumentException(
                "No default implementation for " + type + " among <" + Iterables.toString(plugins) + ">");
    }
    if (defaults.size() > 1) {
        throw new IllegalArgumentException("Found multiple default implementation for " + type + ": <"
                + Iterables.toString(defaults) + ">");
    }

    if (plugins.size() == 1) {
        //Plugins consist of a single default
        return defaults.iterator().next();
    } else if (alternatives.size() > 1) {
        throw new IllegalArgumentException("Found multiple non-default implementation for " + type + ": <"
                + Iterables.toString(alternatives) + ">");
    } else {
        //Only one alternative
        return alternatives.iterator().next();
    }
}

From source file:org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServerProvider.java

@Override
public String toString() {
    return "NodeStateSolrServerProvider{" + "nodeStateChildren="
            + Iterables.toString(nodeState.getChildNodeNames()) + ", provider=" + provider + '}';
}