Example usage for com.google.common.collect FluentIterable from

List of usage examples for com.google.common.collect FluentIterable from

Introduction

In this page you can find the example usage for com.google.common.collect FluentIterable from.

Prototype

@Deprecated
@CheckReturnValue
public static <E> FluentIterable<E> from(FluentIterable<E> iterable) 

Source Link

Document

Construct a fluent iterable from another fluent iterable.

Usage

From source file:com.greensopinion.finance.services.web.CategoryWebService.java

@GET
public List<CategoryModel> list() {
    return FluentIterable.from(categoriesService.retrieve().getCategories())
            .transform(new Function<Category, CategoryModel>() {

                @Override//from   w  w  w.j a v a 2s. com
                public CategoryModel apply(Category category) {
                    return new CategoryModel(category.getName());
                }
            }).toSortedList(Ordering.natural());
}

From source file:com.b2international.snowowl.core.domain.DelegatingContext.java

@Override
public final void dispose() {
    if (disposed.compareAndSet(false, true)) {
        doDispose();/*w ww  .j a  v  a  2 s  .c  o m*/
        FluentIterable.from(registry.values()).filter(IDisposableService.class)
                .forEach(IDisposableService::dispose);
    }
}

From source file:com.bazaarvoice.dropwizard.caching.CacheControlConfiguration.java

public Function<String, Optional<String>> buildMapper() {
    if (_items.size() == 0) {
        return new Function<String, Optional<String>>() {
            public Optional<String> apply(@Nullable String input) {
                return Optional.absent();
            }//from  ww  w .jav a  2s  .  c o m
        };
    }

    final List<CacheControlMap> maps = FluentIterable.from(_items)
            .transform(new Function<CacheControlConfigurationItem, CacheControlMap>() {
                public CacheControlMap apply(CacheControlConfigurationItem input) {
                    return new CacheControlMap(input);
                }
            }).toList();

    return CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<String, Optional<String>>() {
        @Override
        public Optional<String> load(String key) throws Exception {
            for (CacheControlMap map : maps) {
                if (map.groupMatcher.apply(key)) {
                    return Optional.of(map.options);
                }
            }

            return Optional.absent();
        }
    });
}

From source file:com.lyndir.omicron.api.Game.java

@Override
public ImmutableList<Player> getPlayers() {
    return FluentIterable.from(thrift().getPlayers()).transform(Player::new).toList();
}

From source file:com.google.api.tools.framework.aspects.naming.NameAbbreviationRule.java

@Override
public void run(ProtoElement element) {
    // This rule applies to all ProtoElements except file names.
    if (!(element instanceof ProtoFile)) {
        final String simpleName = element.getSimpleName();
        if (!Strings.isNullOrEmpty(simpleName)) {
            FluentIterable<String> usedLongNames = FluentIterable.from(NAME_ABBREVIATION_MAP.keySet())
                    .filter(new Predicate<String>() {
                        @Override
                        public boolean apply(String longName) {
                            return simpleName.toLowerCase().contains(longName);
                        }//w  w w .ja v a2  s  .c  o m
                    });
            if (!usedLongNames.isEmpty()) {
                FluentIterable<String> abbreviationsToUse = usedLongNames
                        .transform(new Function<String, String>() {
                            @Override
                            @Nullable
                            public String apply(@Nullable String longName) {
                                return NAME_ABBREVIATION_MAP.get(longName);
                            }
                        });
                warning(element, "Use of full name(s) '%s' in '%s' is not recommended, use '%s' instead.",
                        Joiner.on(",").join(usedLongNames), element.getSimpleName(),
                        Joiner.on(",").join(abbreviationsToUse));
            }
        }
    }
}

From source file:springfox.documentation.spring.data.rest.EntityAssociationsExtractor.java

@Override
public List<RequestHandler> extract(final EntityContext context) {
    final List<RequestHandler> handlers = newArrayList();
    final PersistentEntity<?, ?> entity = context.entity();
    final Associations associations = context.getAssociations();

    entity.doWithAssociations(new SimpleAssociationHandler() {

        @Override/*from   ww w  .j  a  v  a2  s.com*/
        public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
            PersistentProperty<?> property = association.getInverse();
            if (!associations.isLinkableAssociation(property)) {
                return;
            }
            final EntityAssociationContext associationContext = new EntityAssociationContext(context,
                    association);
            handlers.addAll(FluentIterable.from(context.getAssociationExtractors())
                    .transformAndConcat(extractHandlers(associationContext)).toList());
        }
    });
    return handlers;
}

From source file:com.twitter.aurora.scheduler.storage.StorageBackfill.java

private static void guaranteeShardUniqueness(ScheduledTask task, TaskStore.Mutable taskStore, Clock clock) {

    if (Tasks.isActive(task.getStatus())) {
        // Perform a sanity check on the number of active shards.
        TaskConfig config = task.getAssignedTask().getTask();
        Query.Builder query = Query.instanceScoped(
                JobKeys.from(config.getOwner().getRole(), config.getEnvironment(), config.getJobName()),
                task.getAssignedTask().getInstanceId()).active();
        Set<String> activeTasksInShard = FluentIterable.from(taskStore.fetchTasks(query))
                .transform(Tasks.SCHEDULED_TO_ID).toSet();

        if (activeTasksInShard.size() > 1) {
            SHARD_SANITY_CHECK_FAILS.incrementAndGet();
            LOG.severe("Active shard sanity check failed when loading " + Tasks.id(task)
                    + ", active tasks found: " + activeTasksInShard);

            // We want to keep exactly one task from this shard, so sort the IDs and keep the
            // highest (newest) in the hopes that it is legitimately running.
            String newestTask = Iterables.getLast(Sets.newTreeSet(activeTasksInShard));
            if (!Tasks.id(task).equals(newestTask)) {
                task.setStatus(ScheduleStatus.KILLED);
                task.addToTaskEvents(new TaskEvent(clock.nowMillis(), ScheduleStatus.KILLED)
                        .setMessage("Killed duplicate shard."));
                // TODO(wfarner); Circle back if this is necessary.  Currently there's a race
                // condition between the time the scheduler is actually available without hitting
                // IllegalStateException (see DriverImpl).
                // driver.killTask(Tasks.id(task));
            } else {
                LOG.info("Retaining task " + Tasks.id(task));
            }/*w w w.j  ava  2  s  . c o m*/
        }
    }
}

From source file:io.urmia.md.model.job.JobDefinition.java

public List<Phase> getPhases(Phase.Type type) {
    return FluentIterable.from(phases).filter(phaseType(type)).toList();
}

From source file:info.archinnov.achilles.entity.operations.EntityInitializer.java

public <T, CONTEXT extends PersistenceContext> void initializeEntity(T entity, EntityMeta entityMeta,
        EntityInterceptor<CONTEXT, T> interceptor) {

    log.debug("Initializing lazy fields for entity {} of class {}", entity, entityMeta.getClassName());

    Set<PropertyMeta> alreadyLoadedMetas = FluentIterable.from(interceptor.getAlreadyLoaded())
            .transform(new AlreadyLoadedTransformer(entityMeta.getGetterMetas())).toImmutableSet();

    Set<PropertyMeta> allLazyMetas = FluentIterable.from(entityMeta.getPropertyMetas().values())
            .filter(lazyType).toImmutableSet();

    Set<PropertyMeta> toBeLoadedMetas = Sets.difference(allLazyMetas, alreadyLoadedMetas);

    for (PropertyMeta propertyMeta : toBeLoadedMetas) {
        Object value = propertyMeta.getValueFromField(entity);
        if (propertyMeta.isCounter()) {
            Counter counter = (Counter) value;
            Object realObject = proxifier.getRealObject(entity);
            propertyMeta.setValueToField(realObject, CounterBuilder.incr(counter.get()));
        }//  w  w w .j  av a 2 s . co m
    }

    for (PropertyMeta propertyMeta : alreadyLoadedMetas) {
        if (propertyMeta.isCounter()) {
            Object value = propertyMeta.getValueFromField(entity);
            Counter counter = (Counter) value;
            Object realObject = proxifier.getRealObject(entity);
            propertyMeta.setValueToField(realObject, CounterBuilder.incr(counter.get()));
        }
    }
}

From source file:google.registry.tools.server.ListHostsAction.java

@Override
public ImmutableSet<HostResource> loadObjects() {
    final DateTime now = clock.nowUtc();
    return FluentIterable.from(ofy().load().type(HostResource.class)).filter(new Predicate<HostResource>() {
        @Override/*from   w w  w.j  ava  2s.c o m*/
        public boolean apply(HostResource host) {
            return EppResourceUtils.isActive(host, now);
        }
    }).toSortedSet(comparator);
}