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

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

Introduction

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

Prototype

@GwtIncompatible("Class.isInstance")
@CheckReturnValue
public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType) 

Source Link

Document

Returns all elements in unfiltered that are of the type desiredType .

Usage

From source file:org.eclipse.sirius.diagram.sequence.business.internal.operation.ShiftDirectSubExecutionsOperation.java

@Override
public Void execute() {

    for (View view : Iterables.filter(Iterables.filter(parent.getNotationView().getChildren(), View.class),
            AbstractNodeEvent.notationPredicate())) {
        Option<AbstractNodeEvent> execution = ISequenceElementAccessor.getAbstractNodeEvent(view);
        if (execution.some()) {
            AbstractNodeEvent ise = execution.get();
            Range rg = ise.getVerticalRange();
            Range nrg = new Range(rg.getLowerBound() + deltaY, rg.getUpperBound() + deltaY);
            ise.setVerticalRange(nrg);//from ww w  .  j  a  v a2s .c om
        }
    }
    return null;
}

From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.InstanceRoleMoveValidator.java

/**
 * {@inheritDoc}//w w  w  . j av a  2  s.c om
 */
@Override
public boolean isValid(ChangeBoundsRequest request) {
    boolean valid = super.isValid(request);

    if (instanceRoles.size() != 0) {
        SequenceDiagram sequenceDiagram = instanceRoles.get(0).getDiagram();
        List<InstanceRole> allInstanceRoles = sequenceDiagram.getSortedInstanceRole();

        RequestQuery query = new RequestQuery(request);
        Point moveDelta = query.getLogicalDelta().getLocation();

        Collections.sort(instanceRoles, comparator);

        // if move request is constrained then it's a explicit user move
        // request
        // otherwise it's a indirect request from ConnectionCreationTool for
        // a
        // Create Message for example
        if (!request.isConstrainedMove()) {
            moveDelta.y = 0;
        }

        Iterable<Rectangle> notMovedIRBounds = Iterables.transform(
                Iterables.filter(allInstanceRoles, Predicates.not(Predicates.in(instanceRoles))),
                ISequenceElement.PROPER_LOGICAL_BOUNDS);

        // Iterate on all instanceRoles to move from the request
        for (InstanceRole instanceRole : instanceRoles) {
            moveDeltas.put(instanceRole, moveDelta.getCopy());

            Rectangle boundBeforeResizing = instanceRole.getBounds();
            Rectangle boundAfterResizing = boundBeforeResizing.getTranslated(moveDelta);

            for (Rectangle notMovedBounds : notMovedIRBounds) {
                int nmbLeftX = notMovedBounds.getLeft().x;
                int nmbRightX = notMovedBounds.getRight().x;
                int mLeftX = boundAfterResizing.getLeft().x;
                boolean leftOverlapFixIR = nmbLeftX <= mLeftX && mLeftX <= nmbRightX;

                if (leftOverlapFixIR) {
                    valid = false;
                    break;
                }
            }
        }
    }
    return valid;
}

From source file:com.github.pmerienne.cf.testing.dataset.DatasetUtils.java

public static List<Rating> removeRandomRatings(final long user, int count, List<Rating> allRatings) {
    List<Rating> userRatings = Lists.newArrayList(Iterables.filter(allRatings, new Predicate<Rating>() {
        @Override//from   www  .j  ava 2  s  . c o m
        public boolean apply(Rating input) {
            return input.i == user;
        }
    }));
    List<Rating> removedRatings = ListUtils.randomSubList(userRatings, count);

    allRatings.removeAll(removedRatings);
    return removedRatings;
}

From source file:org.eclipse.sirius.diagram.ui.business.api.helper.graphicalfilters.CompositeFilterApplicationBuilder.java

/**
 * Compute composite filters application (hide and collapse) for diagram
 * elements of the current diagram./*  w w  w  .j  av a2 s .  c  om*/
 */
public void computeCompositeFilterApplications() {
    ICollapseUpdater collapseUpdater = CollapseUpdater.getICollapseUpdater(diagram);

    for (DDiagramElement element : diagram.getDiagramElements()) {
        List<CompositeFilterDescription> appliedHideFilters = Lists.newArrayList(Iterables
                .filter(FilterService.getAppliedFilters(diagram, element), CompositeFilterDescription.class));
        handleHideCompositeFilters(element, appliedHideFilters);

        boolean isDirectlycollapsed = FilterService.isCollapsed(diagram, element);
        handleCollapseCompositeFilters(element, isDirectlycollapsed, collapseUpdater);
    }
}

From source file:org.apache.brooklyn.core.location.access.BrooklynAccessUtils.java

public static HostAndPort getBrooklynAccessibleAddress(Entity entity, int port) {
    String host;/*from   w w  w .j av  a 2 s .  com*/

    // look up port forwarding
    PortForwardManager pfw = entity.getConfig(PORT_FORWARDING_MANAGER);
    if (pfw != null) {
        Collection<Location> ll = entity.getLocations();

        synchronized (BrooklynAccessUtils.class) {
            // TODO finer-grained synchronization

            for (MachineLocation machine : Iterables.filter(ll, MachineLocation.class)) {
                HostAndPort hp = pfw.lookup(machine, port);
                if (hp != null) {
                    log.debug(
                            "BrooklynAccessUtils found port-forwarded address {} for entity {}, port {}, using machine {}",
                            new Object[] { hp, entity, port, machine });
                    return hp;
                }
            }

            Maybe<SupportsPortForwarding> supportPortForwardingLoc = Machines.findUniqueElement(ll,
                    SupportsPortForwarding.class);
            if (supportPortForwardingLoc.isPresent()) {
                Cidr source = entity.getConfig(MANAGEMENT_ACCESS_CIDR);
                SupportsPortForwarding loc = supportPortForwardingLoc.get();
                if (source != null) {
                    log.debug("BrooklynAccessUtils requesting new port-forwarding rule to access " + port
                            + " on " + entity + " (at " + loc + ", enabled for " + source + ")");
                    // TODO discuss, is this the best way to do it
                    // (will probably _create_ the port forwarding rule!)
                    HostAndPort hp = loc.getSocketEndpointFor(source, port);
                    if (hp != null) {
                        log.debug(
                                "BrooklynAccessUtils created port-forwarded address {} for entity {}, port {}, using {}",
                                new Object[] { hp, entity, port, loc });
                        return hp;
                    }
                } else {
                    log.warn("No " + MANAGEMENT_ACCESS_CIDR.getName() + " configured for " + entity
                            + ", so cannot forward " + "port " + port + " " + "even though "
                            + PORT_FORWARDING_MANAGER.getName() + " was supplied, and "
                            + "have location supporting port forwarding " + loc);
                }
            }
        }
    }

    host = entity.getAttribute(Attributes.HOSTNAME);
    if (host != null)
        return HostAndPort.fromParts(host, port);

    throw new IllegalStateException(
            "Cannot find way to access port " + port + " on " + entity + " from Brooklyn (no host.name)");
}

From source file:org.obiba.opal.web.project.permissions.ProjectReportTemplatePermissionsResource.java

/**
 * Get all table-level permissions of a table in the project.
 *
 * @param domain/*from  www.j  av a2  s .c o  m*/
 * @param type
 * @return
 */
@GET
public Iterable<Opal.Acl> getTablePermissions(@QueryParam("type") SubjectType type) {

    // make sure project exists
    validateTemplate();

    Iterable<SubjectAclService.Permissions> permissions = subjectAclService.getNodePermissions(DOMAIN,
            getNode(), type);

    return Iterables.transform(Iterables.filter(permissions, new MagmaPermissionsPredicate()),
            PermissionsToAclFunction.INSTANCE);
}

From source file:org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier.java

@Override
public Set<? extends Location> get() {
    Builder<Location> locations = ImmutableSet.builder();
    Iterable<DataCenter> list = Iterables
            .filter(Iterables.transform(sync.getPricingPlanList(), new Function<PricingPlan, DataCenter>() {

                @Override//from w  w  w  .  j a  va2 s  .  c o m
                public DataCenter apply(PricingPlan arg0) {
                    return arg0.getDataCenter();
                }

            }), Predicates.<DataCenter>notNull());
    Location provider = Iterables.getOnlyElement(super.get());
    if (Iterables.size(list) == 0)
        locations.add(provider);
    else
        for (DataCenter from : list) {
            LocationBuilder builder = new LocationBuilder().scope(LocationScope.ZONE).id(from.getId())
                    .description(from.getName()).parent(provider);
            if (isoCodesById.containsKey(from.getId()))
                builder.iso3166Codes(isoCodesById.get(from.getId()));
            locations.add(builder.build());
        }
    return locations.build();
}

From source file:org.sonar.server.issue.IssueBulkChangeQuery.java

private static List<String> sanitizeList(@Nullable List<String> list) {
    if (list == null || list.isEmpty()) {
        return Collections.emptyList();
    }/*from  w w  w.java  2s .co m*/
    return newArrayList(Iterables.filter(list, StringIsNotNull.INSTANCE));
}

From source file:org.isisaddons.app.kitchensink.dom.dependent.NflTeams.java

@Programmatic
public List<NflTeamEntity> thoseFor(final NflRegion leagueRegion) {
    final List<NflTeamEntity> nflTeamEntities = listAll();
    return Lists.newArrayList(Iterables.filter(nflTeamEntities, new Predicate<NflTeamEntity>() {
        @Override/*from www.ja va2  s  . c  o m*/
        public boolean apply(NflTeamEntity input) {
            return input.getRegion() == leagueRegion;
        }
    }));
}