List of usage examples for com.google.common.collect Collections2 transform
public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function)
From source file:org.easyrec.controller.aop.LoggedInCheckAspect.java
private void initPath(HttpServletRequest request) { localName = request.getLocalName();//ww w . j a v a 2s . co m localName = localName.equals("0.0.0.0") ? "localhost" : localName; this.webappPath = request.getContextPath(); this.extendedWebAppPath = request.getScheme() + "://" + localName + ":" + request.getLocalPort() + webappPath; PUBLIC_SITES = Sets.newHashSet(Collections2.transform(PUBLIC_SITES, new Function<String, String>() { public String apply(@Nullable String input) { StringBuilder result = new StringBuilder(webappPath); result.append('/'); result.append(input); return result.toString(); } })); }
From source file:com.hortonworks.streamline.streams.layout.storm.WindowRuleBoltFluxComponent.java
private String addWindowConfig() { String windowId = "window" + UUID_FOR_COMPONENTS; String windowClassName = "com.hortonworks.streamline.streams.layout.component.rule.expression.Window"; ObjectMapper mapper = new ObjectMapper(); String windowJson = null;/*from w w w . j a v a 2 s . com*/ try { Set<Window> windows = new HashSet<>( Collections2.transform(rulesProcessor.getRules(), new Function<Rule, Window>() { @Override public Window apply(Rule input) { return input.getWindow(); } })); if (windows.size() != 1) { throw new IllegalArgumentException( "All the rules in a windowed rule bolt should have the same window config."); } windowJson = mapper.writeValueAsString(windows.iterator().next()); } catch (JsonProcessingException e) { log.error("Error creating json config string for RulesProcessor", e); } List<String> constructorArgs = new ArrayList<>(); constructorArgs.add(windowJson); this.addToComponents(this.createComponent(windowId, windowClassName, null, constructorArgs, null)); return windowId; }
From source file:org.eclipse.smarthome.core.common.registry.AbstractManagedProvider.java
@Override public Collection<E> getAll() { final Function<String, E> toElementList = new Function<String, E>() { @Override// www . j ava 2 s.co m public E apply(String elementKey) { PE persistableElement = storage.get(elementKey); if (persistableElement != null) { return toElement(elementKey, persistableElement); } else { return null; } } }; Collection<String> keys = storage.getKeys(); Collection<E> elements = Collections2.filter(Collections2.transform(keys, toElementList), Predicates.notNull()); return ImmutableList.copyOf(elements); }
From source file:blue.lapis.pore.impl.PoreChunk.java
@Override public Entity[] getEntities() { Collection<org.spongepowered.api.entity.Entity> entities = getHandle().getEntities(); Entity[] bukkitEntities = new Entity[entities.size()]; Collections2.transform(entities, new Function<org.spongepowered.api.entity.Entity, Entity>() { @Override//from ww w.j a v a 2 s . c o m public Entity apply(org.spongepowered.api.entity.Entity input) { return PoreEntity.of(input); } }).toArray(bukkitEntities); return bukkitEntities; }
From source file:com.payu.ratel.client.inmemory.RatelServerFetcher.java
@Override public Collection<String> getServiceNames() { return Collections2.transform(getAllServiceInstances(), new Function<ServiceDescriptor, String>() { @Override// ww w. j a v a 2s.c o m public String apply(ServiceDescriptor input) { return input.getName(); } }); }
From source file:com.ning.billing.invoice.api.svcs.DefaultInvoiceInternalApi.java
@Override public Collection<Invoice> getInvoicesByAccountId(final UUID accountId, final InternalTenantContext context) { return Collections2.transform(dao.getInvoicesByAccount(accountId, context), new Function<InvoiceModelDao, Invoice>() { @Override/*from w ww .j av a 2s.c om*/ public Invoice apply(final InvoiceModelDao input) { return new DefaultInvoice(input); } }); }
From source file:org.zanata.model.HPerson.java
@Transient public Set<HProject> getMaintainerProjects() { Set<HProjectMember> maintainerMemberships = Sets.filter(getProjectMemberships(), HProjectMember.IS_MAINTAINER); Collection<HProject> projects = Collections2.transform(maintainerMemberships, HProjectMember.TO_PROJECT); return ImmutableSet.copyOf(projects); }
From source file:org.apache.marmotta.kiwi.ehcache.util.CacheMap.java
@Override public Set<Entry<K, V>> entrySet() { return ImmutableSet.copyOf(Collections2.transform(delegate.getKeys(), new Function<K, Entry<K, V>>() { @Override// w ww . j av a2s. com public Entry<K, V> apply(final K input) { final Element e = delegate.get(input); return new Entry<K, V>() { @Override public K getKey() { return input; } @Override public V getValue() { return (V) e.getObjectValue(); } @Override public V setValue(V v) { delegate.put(new Element(input, v)); return (V) e.getObjectValue(); } }; } })); }
From source file:com.netflix.raigad.identity.EurekaHostsSupplier.java
@Override public Supplier<List<Host>> getSupplier(final String clusterName) { return new Supplier<List<Host>>() { @Override//from w w w .ja v a 2 s .c om public List<Host> get() { if (discoveryClient == null) { LOG.error("Discovery client cannot be null"); throw new RuntimeException("EurekaHostsSupplier needs a non-null DiscoveryClient"); } LOG.info("Raigad fetching instance list for app: " + clusterName); Application app = discoveryClient.getApplication(clusterName.toUpperCase()); List<Host> hosts = new ArrayList<Host>(); if (app == null) { LOG.warn("Cluster '{}' not found in eureka", clusterName); return hosts; } List<InstanceInfo> ins = app.getInstances(); if (ins == null || ins.isEmpty()) { LOG.warn("Cluster '{}' found in eureka but has no instances", clusterName); return hosts; } hosts = Lists.newArrayList( Collections2.transform(Collections2.filter(ins, new Predicate<InstanceInfo>() { @Override public boolean apply(InstanceInfo input) { return input.getStatus() == InstanceInfo.InstanceStatus.UP; } }), new Function<InstanceInfo, Host>() { @Override public Host apply(InstanceInfo info) { String[] parts = StringUtils.split(StringUtils.split(info.getHostName(), ".")[0], '-'); Host host = new Host(info.getHostName(), info.getPort()) .addAlternateIpAddress(StringUtils .join(new String[] { parts[1], parts[2], parts[3], parts[4] }, ".")) .addAlternateIpAddress(info.getIPAddr()).setId(info.getId()); try { if (info.getDataCenterInfo() instanceof AmazonInfo) { AmazonInfo amazonInfo = (AmazonInfo) info.getDataCenterInfo(); host.setRack(amazonInfo.get(MetaDataKey.availabilityZone)); } } catch (Throwable t) { LOG.error("Error getting rack for host " + host.getName(), t); } return host; } })); LOG.info("Raigad found hosts from eureka - num hosts: " + hosts.size()); return hosts; } }; }
From source file:edu.umn.msi.tropix.client.directory.impl.UserIterableImpl.java
public Iterator<GridUser> iterator() { final Collection<GridUser> users = new LinkedList<GridUser>(); final Multimap<String, Person> persons = personSupplier.get(); for (String institution : persons.keySet()) { Iterables.addAll(users,//from ww w. ja v a 2s .c om Iterables.filter( Collections2.transform(persons.get(institution), new PersonFunction(institution)), Predicates.not(Predicates.isNull()))); } for (final GridUser user : users) { gridUserMap.put(user.getGridId(), user); } return users.iterator(); }