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:com.dssmp.agent.metrics.CompositeMetricsFactory.java

/**
 * @return a {@link CompositeMetricsScope} containing a scope for each
 *         of the factories backing this composite.
 *///from  w ww  .  ja v a2  s . c  o  m
@Override
public IMetricsScope createScope() {
    Collection<IMetricsScope> scopes = Collections2.transform(this.factories,
            new Function<IMetricsFactory, IMetricsScope>() {
                @Override
                public IMetricsScope apply(IMetricsFactory input) {
                    return input.createScope();
                }
            });
    return new CompositeMetricsScope(scopes);

}

From source file:de.uniulm.omi.cloudiator.visor.rest.controllers.MonitorController.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*from w ww .  j a  v  a 2 s .co  m*/
@Path("/monitors")
public Collection<MonitorEntity> getMonitors() {
    return Collections2.transform(monitoringService.getMonitors(), new MonitorToMonitorJsonConverter());
}

From source file:org.mandarax.dsl.verification.CheckReferencesInObjectDeclarations.java

@Override
public void verify(Collection<CompilationUnit> cus, VerificationErrorReporter errorHandler)
        throws VerificationException {
    for (CompilationUnit cu : cus) {
        List<ObjectDeclaration> objDecls = cu.getObjectDeclarations();
        for (int i = 0; i < objDecls.size(); i++) {
            ObjectDeclaration objDecl = objDecls.get(i);
            Collection<String> varNames = Collections2.transform(
                    objDecl.getDefaultValueDeclaration().getVariables(), new Function<Variable, String>() {
                        @Override
                        public String apply(Variable var) {
                            return var.getName();
                        }/*from   www  . j ava 2 s . c o m*/
                    });
            // copy in mutable coll
            Set<String> varNames2 = new HashSet<String>(varNames);
            for (int j = 0; j < i; j++) {
                varNames2.remove(objDecls.get(j).getName());
            }

            if (!varNames2.isEmpty()) {
                errorHandler.reportError(cu, "The object declaration at ", objDecl.getPosition(),
                        " references undefined object(s) " + Joiner.on(",").skipNulls().join(varNames2));
            }

        }
    }
}

From source file:org.gradle.api.tasks.diagnostics.internal.dependencies.RenderableModuleResult.java

public Set<RenderableDependency> getChildren() {
    return new LinkedHashSet(Collections2.transform(module.getDependencies(),
            new Function<ResolvedDependencyResult, RenderableDependency>() {
                public RenderableDependency apply(ResolvedDependencyResult input) {
                    return new RenderableDependencyResult(input);
                }//from  www. j a v a2 s  .  c  o m
            }));
}

From source file:org.polymap.biotop.model.GefahrComposite.java

public static void updateEntity(BiotopComposite biotop, Collection<GefahrComposite> coll) {
    biotop.gefahr().set(Collections2.transform(coll, new Function<GefahrComposite, GefahrValue>() {
        public GefahrValue apply(GefahrComposite input) {
            return input.value();
        }/*from w  ww  . ja  va 2s . co  m*/
    }));
}

From source file:org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil.java

public static Collection<String> extractCapabilitiesFromHello(Document doc) throws NetconfDocumentedException {
    XmlElement responseElement = XmlElement.fromDomDocument(doc);
    XmlElement capabilitiesElement = responseElement
            .getOnlyChildElementWithSameNamespace(XmlNetconfConstants.CAPABILITIES);
    List<XmlElement> caps = capabilitiesElement.getChildElements(XmlNetconfConstants.CAPABILITY);
    return Collections2.transform(caps, new Function<XmlElement, String>() {

        @Override// w  w  w. j a v  a  2  s .  c  om
        public String apply(@Nonnull XmlElement input) {
            // Trim possible leading/tailing whitespace
            try {
                return input.getTextContent().trim();
            } catch (NetconfDocumentedException e) {
                LOG.trace("Error fetching input text content", e);
                return null;
            }
        }
    });

}

From source file:xbdd.webapp.resource.feature.DBObjectComparator.java

/**
 * Construct a {@link Comparator} with the given set of expressions
 * //  w  w w . j a v a  2 s.co m
 * @param searchExpressions a list of regular expressions
 * @throws PatternSyntaxException if any of the expressions are not valid regex
 */
public DBObjectComparator(final Collection<String> searchExpressions) {
    final String regex = StringUtils
            .join(Collections2.transform(searchExpressions, new Function<String, String>() {
                @Override
                public String apply(final String input) {
                    return "(" + input + ")";
                }
            }), "|");
    this.pattern = Pattern.compile(regex);
}

From source file:org.polymap.biotop.model.WertComposite.java

public static void updateEntity(BiotopComposite biotop, Collection<WertComposite> coll) {
    biotop.werterhaltend().set(Collections2.transform(coll, new Function<WertComposite, WertValue>() {
        public WertValue apply(WertComposite input) {
            return input.value();
        }//from w  w  w .  j  a va 2  s  .c  o m
    }));
}

From source file:io.baku.teslate.BitmapPatcher.java

private List<Patch<Bitmap>> diff(final Bitmap orig, final Bitmap next) {
    final int colorThreshold = mSettings.getFrameColorThreshold();
    final PatchAccumulator p = new PatchAccumulator(RES * 3);

    for (int y = 0; y < orig.getHeight(); y += RES) {
        for (int x = 0; x < orig.getWidth(); x += RES) {
            if (diff(orig.getPixel(x, y), next.getPixel(x, y), colorThreshold)) {
                p.submit(x, y);//from   w  w  w. j  av  a 2  s .co m
            }
        }
    }

    for (Rect r : p.clusters) {
        //noinspection CheckResult
        r.intersect(0, 0, orig.getWidth() - 1, orig.getHeight() - 1);
    }
    return ImmutableList.copyOf(Collections2.transform(p.clusters, r -> new Patch<>(new Point(r.left, r.top),
            Bitmap.createBitmap(next, r.left, r.top, r.width() + 1, r.height() + 1))));
}

From source file:controllers.ArtifactsController.java

public static Result index() {
    List<Component> components = null;
    List<ServiceAssembly> sas = null;
    List<SharedLibrary> sls = null;

    try {//from  w  ww .j  a  va 2 s  .c  o m
        List<Artifact> artifacts = PetalsAdmin.getArtifactAdministration(getCurrentNode()).listArtifacts();

        components = Lists.newArrayList(Collections2
                .transform(Sets.newHashSet(Collections2.filter(artifacts, new Predicate<Artifact>() {
                    public boolean apply(Artifact input) {
                        return input != null && (input.getType().equalsIgnoreCase(ComponentType.BC.toString())
                                || input.getType().equalsIgnoreCase(ComponentType.SE.toString()));
                    }
                })), new Function<Artifact, Component>() {
                    public Component apply(Artifact input) {
                        return (Component) input;
                    }
                }));

        sas = Lists.newArrayList(Collections2
                .transform(Sets.newHashSet(Collections2.filter(artifacts, new Predicate<Artifact>() {
                    public boolean apply(Artifact input) {
                        return input != null && input.getType().equalsIgnoreCase("SA");
                    }
                })), new Function<Artifact, ServiceAssembly>() {
                    public ServiceAssembly apply(Artifact input) {
                        return (ServiceAssembly) input;
                    }
                }));

        sls = Lists.newArrayList(Collections2
                .transform(Sets.newHashSet(Collections2.filter(artifacts, new Predicate<Artifact>() {
                    public boolean apply(Artifact input) {
                        return input != null && input.getType().equalsIgnoreCase("SL");
                    }
                })), new Function<Artifact, SharedLibrary>() {
                    public SharedLibrary apply(Artifact input) {
                        return (SharedLibrary) input;
                    }
                }));

    } catch (Exception e) {
        Logger.error("Error while getting client", e);
        flash("error", String.format("Can not get client : %s", e.getMessage()));
    }

    return ok(index.render(components, sas, sls, play.data.Form.form(DeployArtifact.class)));
}