Example usage for com.google.common.collect Collections2 transform

List of usage examples for com.google.common.collect Collections2 transform

Introduction

In this page you can find the example usage for com.google.common.collect Collections2 transform.

Prototype

public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function) 

Source Link

Document

Returns a collection that applies function to each element of fromCollection .

Usage

From source file:org.openengsb.ui.common.usermanagement.UserEditPanel.java

public UserEditPanel(String id, String username) throws UserNotFoundException {
    super(id);//  ww w  . j a  va  2 s. c  om
    input.setUsername(username);
    Collection<Permission> userPermissions = userManager.getPermissionsForUser(username);
    Collection<PermissionInput> permissionInput = Collections2.transform(userPermissions,
            new Function<Permission, PermissionInput>() {
                @Override
                public PermissionInput apply(Permission input) {
                    Map<String, String> values = BeanUtilsExtended.buildStringAttributeMap(input);
                    return new PermissionInput(input.getClass(), values);
                }
            });
    input.setPermissions(Lists.newLinkedList(permissionInput));
    createMode = false;
    initContent();
}

From source file:org.peletomi.vax.impl.StringArrayExtractorFrontEnd.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from  w  ww.  ja  va 2 s .  c om*/
public void addValue(final String[] key, final Object value) {
    final Collection<Object> valueList;
    if (value != null && value.getClass().isArray()) {
        valueList = newArrayList((Object[]) value);
    } else if (value instanceof Collection) {
        valueList = (Collection) value;
    } else {
        valueList = newArrayList(value);
    }
    List<String> resultList = newArrayList(Collections2.transform(valueList, TO_STRING));
    if (skipBlanks) {
        resultList = newArrayList(filter(resultList, IS_NOT_BLANK));
    }
    if ((skipBlanks && !resultList.isEmpty()) || !skipBlanks) {
        final ImmutableList<String> keys = ImmutableList.copyOf(key);
        add(values, keys, resultList);
    }
}

From source file:dynamicrefactoring.util.MOONTypeLister.java

/**
* Obtiene la lista de clases MOON y de su extension para Java
* con sus nombres completamente cualificados.
* 
* @return un lista con los nombres de las clases.
*//*from www. j av  a 2 s  . co  m*/
public java.util.List<String> getInputTypeNames() {
    java.util.List<String> proposals = new ArrayList<String>(Collections2
            .transform(MOONTypeLister.getInstance().getTypeNameList(), new Function<String, String>() {

                @Override
                public String apply(String fullyQualifiedName) {
                    return PluginStringUtils.getClassName(fullyQualifiedName);
                }
            }));
    return proposals;
}

From source file:com.payu.ratel.client.RemoteAutowireCandidateResolver.java

private Collection<String> getAnnotationsTypes(DependencyDescriptor descriptor) {
    Function<Annotation, String> function = new Function<Annotation, String>() {

        @Override/*from  www.  ja va  2s .  c o m*/
        public String apply(Annotation annotation) {
            return annotation.annotationType().getName();
        }
    };

    return Collections2.transform(Arrays.asList(descriptor.getAnnotations()), function);
}

From source file:net.sourceforge.ganttproject.io.ViewSaver.java

/**
 * Writes tasks explicitly shown in the timeline as comma-separated list of task identifiers in CDATA section
 * of <timeline> element./*from ww w . j ava2s . c o m*/
 */
private void writeTimelineTasks(UIFacade facade, TransformerHandler handler) throws SAXException {
    AttributesImpl attrs = new AttributesImpl();
    Set<Task> timelineTasks = facade.getCurrentTaskView().getTimelineTasks();
    if (timelineTasks.isEmpty()) {
        return;
    }
    Function<Task, String> getId = new Function<Task, String>() {
        @Override
        public String apply(Task t) {
            return String.valueOf(t.getTaskID());
        }
    };
    cdataElement("timeline", Joiner.on(',').join(Collections2.transform(timelineTasks, getId)), attrs, handler);
}

From source file:org.sosy_lab.cpachecker.core.reachedset.UnmodifiableReachedSetView.java

@Override
public Collection<AbstractState> getWaitlist() {
    return Collections2.transform(underlying.getWaitlist(), mapStateFunction);
}

From source file:org.jboss.arquillian.graphene.javascript.JSInterface.java

/**
 * Returns all JavaScript interfaces which are dependencies of this interface as specified by {@link Dependency#interfaces()}.
 *///from  ww w .ja v  a2  s . c om
@SuppressWarnings("unchecked")
public Collection<JSInterface> getJSInterfaceDependencies() {
    if (dependecyAnnotation == null) {
        return (Collection<JSInterface>) Collections.EMPTY_LIST;
    }
    return Collections2.transform(Arrays.asList(dependecyAnnotation.interfaces()),
            new Function<Class<?>, JSInterface>() {
                @Override
                public JSInterface apply(Class<?> input) {
                    return new JSInterface(input);
                }
            });
}

From source file:org.killbill.billing.jaxrs.json.RefundJson.java

public RefundJson(final Refund refund, @Nullable final List<InvoiceItem> adjustments,
        @Nullable final List<AuditLog> auditLogs) {
    this(refund.getId().toString(), refund.getPaymentId().toString(), refund.getRefundAmount(),
            refund.getCurrency().toString(), refund.getRefundStatus().toString(), refund.isAdjusted(),
            refund.getEffectiveDate(), refund.getEffectiveDate(),
            adjustments == null ? null/*from   w w  w  .ja  v a  2  s .  c  o m*/
                    : ImmutableList.<InvoiceItemJson>copyOf(
                            Collections2.transform(adjustments, new Function<InvoiceItem, InvoiceItemJson>() {
                                @Override
                                public InvoiceItemJson apply(@Nullable final InvoiceItem input) {
                                    return new InvoiceItemJson(input);
                                }
                            })),
            toAuditLogJson(auditLogs));
}

From source file:com.ning.billing.junction.dao.DefaultBlockingStateDao.java

@Override
public List<BlockingState> getBlockingHistoryFor(final UUID blockableId, final InternalTenantContext context) {
    return transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<List<BlockingState>>() {
        @Override//  www  .  j  a  v a2  s .co  m
        public List<BlockingState> inTransaction(
                final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception {
            final List<BlockingStateModelDao> models = entitySqlDaoWrapperFactory
                    .become(BlockingStateSqlDao.class).getBlockingHistoryFor(blockableId, context);
            return new ArrayList<BlockingState>(
                    Collections2.transform(models, new Function<BlockingStateModelDao, BlockingState>() {
                        @Override
                        public BlockingState apply(@Nullable final BlockingStateModelDao src) {
                            return BlockingStateModelDao.toBlockingState(src);
                        }
                    }));
        }
    });
}

From source file:com.infosupport.ellison.core.archive.WARApplicationArchive.java

/**
 * {@inheritDoc}/*  w w w .j a  v  a  2s.  co m*/
 */
@Override
public ClassLoader getClassLoader() {
    ClassLoader warClassLoader = null;
    Collection<URI> libFiles = null;

    if (cachedClassLoader != null) {
        return cachedClassLoader;
    }

    Collection<URL> urlList = new ArrayList<>();
    URL mainURL = null;
    URL classesURL = null;

    try {
        mainURL = getUnpackedPath().toURI().toURL();
        classesURL = new URL(mainURL, "WEB-INF/classes/");
    } catch (MalformedURLException e) {
        // This should never happen, as long as unpackJar() returns a valid path
        LOGGER.warn("Somehow, a malformed URL got into WARApplicationArchive.getClassLoader().", e);
    }

    if (mainURL != null && classesURL != null) {
        urlList.add(mainURL);
        urlList.add(classesURL);
        try {
            libFiles = findFilesByGlobPattern("WEB-INF/lib", "*.jar", false);
        } catch (FileNotFoundException e) {
            LOGGER.info("No libraries in this application archive.");
        }

        if (libFiles != null) {
            Collection<URL> jarURLS = Collections2.transform(libFiles, new JarURIToURLTransform());
            urlList.addAll(jarURLS);
        }

        warClassLoader = new URLClassLoader(urlList.toArray(new URL[urlList.size()]),
                this.getClass().getClassLoader());
    }

    cachedClassLoader = warClassLoader;

    return warClassLoader;
}