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

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

Introduction

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

Prototype

public static <T> int indexOf(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns the index in iterable of the first element that satisfies the provided predicate , or -1 if the Iterable has no such elements.

Usage

From source file:com.replaymod.replaystudio.pathing.change.RemoveKeyframe.java

@NonNull
public static RemoveKeyframe create(@NonNull Path path, @NonNull Keyframe keyframe) {
    return new RemoveKeyframe(path.getTimeline().getPaths().indexOf(path),
            Iterables.indexOf(path.getKeyframes(), Predicates.equalTo(keyframe)));
}

From source file:com.madvay.tools.android.perf.common.TraceTransformers.java

public static TT pruneAbove(final Predicate<StackTraceElement> spec) {
    return new TT() {
        @Override//from w w w .ja va 2s  . c om
        public List<StackTraceElement> apply(List<StackTraceElement> input) {
            int matchIdx = Iterables.indexOf(input, spec);
            if (matchIdx == -1) {
                return Lists.newArrayList();
            }
            return Lists.newArrayList(Iterables.skip(input, matchIdx));
        }
    };
}

From source file:org.opendaylight.protocol.bgp.rib.impl.IdentifierUtils.java

private static YangInstanceIdentifier firstIdentifierOf(final YangInstanceIdentifier id,
        final Predicate<PathArgument> match) {
    final int idx = Iterables.indexOf(id.getPathArguments(), match);
    Preconditions.checkArgument(idx != -1, "Failed to find %s in %s", match, id);
    // we want the element at index idx to be included in the list
    return YangInstanceIdentifier.create(Iterables.limit(id.getPathArguments(), idx + 1));
}

From source file:org.gradle.platform.base.internal.registry.ModelMapBasedRule.java

public ModelMapBasedRule(ModelReference<C> subject, final Class<? extends T> baseType,
        MethodRuleDefinition<R, ?> ruleDefinition, ModelReference<?>... additionalInputs) {
    super(subject, ruleDefinition.getDescriptor(),
            calculateInputs(baseType,/*from   www  . j  a va2s. co  m*/
                    ruleDefinition.getReferences().subList(1, ruleDefinition.getReferences().size()),
                    Arrays.asList(additionalInputs)));
    this.ruleDefinition = ruleDefinition;
    this.baseTypeParameterIndex = 1 + Iterables.indexOf(
            ruleDefinition.getReferences().subList(1, ruleDefinition.getReferences().size()),
            new Predicate<ModelReference<?>>() {
                @Override
                public boolean apply(ModelReference<?> element) {
                    return element.getType().equals(ModelType.of(baseType));
                }
            });
}

From source file:edu.mit.streamjit.util.bytecode.insts.PhiInst.java

public Value get(BasicBlock b) {
    int bbi = Iterables.indexOf(operands(), Predicates.<Value>equalTo(b));
    return bbi != -1 ? getOperand(bbi + 1) : null;
}

From source file:com.madvay.tools.android.perf.common.TraceTransformers.java

public static TT keepAbove(final Predicate<StackTraceElement> spec) {
    return new TT() {
        @Override//from ww w.j  av a  2s  . c o  m
        public List<StackTraceElement> apply(List<StackTraceElement> input) {
            int matchIdx = Iterables.indexOf(input, spec);
            if (matchIdx == -1) {
                return input;
            }
            return Lists.newArrayList(Iterables.limit(input, matchIdx));
        }
    };
}

From source file:org.apache.druid.server.http.security.RulesResourceFilter.java

@Override
public ContainerRequest filter(ContainerRequest request) {
    final String dataSourceName = request.getPathSegments()
            .get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {
                @Override/*w w w.ja  v  a2s.  co  m*/
                public boolean apply(PathSegment input) {
                    return "rules".equals(input.getPath());
                }
            }) + 1).getPath();
    Preconditions.checkNotNull(dataSourceName);

    final ResourceAction resourceAction = new ResourceAction(
            new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));

    final Access authResult = AuthorizationUtils.authorizeResourceAction(getReq(), resourceAction,
            getAuthorizerMapper());

    if (!authResult.isAllowed()) {
        throw new ForbiddenException(authResult.toString());
    }

    return request;
}

From source file:org.obeonetwork.dsl.uml2.design.internal.listeners.UmlDesignerSessionListener.java

public void notify(int changeKind) {
    if (changeKind == SessionListener.OPENED || changeKind == SessionListener.SELECTED_VIEWS_CHANGE_KIND) {
        // The Reused viewpoint must not be disabled by the user as other viewpoints depend on it, so it
        // is re-enabled automatically at the session opening or when the user change the viewpoint
        // selection
        if (Iterables.any(session.getSelectedViewpoints(false), new Predicate<Viewpoint>() {
            public boolean apply(Viewpoint selectedViewpoint) {
                return UmlViewpoints.isUmlViewpoint(selectedViewpoint);
            }//from ww w  .j av a 2s  .  c o m
        })) {
            final Viewpoint reused = UmlViewpoints.fromViewpointRegistry().reused();
            if (Iterables.indexOf(session.getSelectedViewpoints(false), new Predicate<Viewpoint>() {
                public boolean apply(Viewpoint selectedViewpoint) {
                    return selectedViewpoint.getName().equals(reused.getName());
                }
            }) == -1) {
                UmlViewpoints.enableReused(session);
            }
        }
    }
}

From source file:org.obeonetwork.dsl.uml2.core.internal.listeners.UmlDesignerSessionListener.java

@Override
public void notify(int changeKind) {
    if (changeKind == SessionListener.OPENED || changeKind == SessionListener.SELECTED_VIEWS_CHANGE_KIND) {
        // The Reused viewpoint must not be disabled by the user as other
        // viewpoints depend on it, so it
        // is re-enabled automatically at the session opening or when the
        // user change the viewpoint
        // selection
        if (Iterables.any(session.getSelectedViewpoints(false), new Predicate<Viewpoint>() {
            @Override/*from   www.  jav  a  2 s . co m*/
            public boolean apply(Viewpoint selectedViewpoint) {
                return UmlCoreViewpoints.isUmlViewpoint(selectedViewpoint);
            }
        })) {
            if (Iterables.indexOf(session.getSelectedViewpoints(false), new Predicate<Viewpoint>() {
                @Override
                public boolean apply(Viewpoint selectedViewpoint) {
                    return UmlCoreViewpoints.isReusedViewpoint(selectedViewpoint);
                }
            }) == -1) {
                UmlCoreViewpoints.enableReused(session);
            }
        }

    }
}

From source file:io.druid.server.http.security.RulesResourceFilter.java

@Override
public ContainerRequest filter(ContainerRequest request) {
    if (getAuthConfig().isEnabled()) {
        // This is an experimental feature, see - https://github.com/druid-io/druid/pull/2424
        final String dataSourceName = request.getPathSegments()
                .get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() {
                    @Override//from  w  w  w .java2s.  com
                    public boolean apply(PathSegment input) {
                        return input.getPath().equals("rules");
                    }
                }) + 1).getPath();
        Preconditions.checkNotNull(dataSourceName);
        final AuthorizationInfo authorizationInfo = (AuthorizationInfo) getReq()
                .getAttribute(AuthConfig.DRUID_AUTH_TOKEN);
        Preconditions.checkNotNull(authorizationInfo,
                "Security is enabled but no authorization info found in the request");
        final Access authResult = authorizationInfo
                .isAuthorized(new Resource(dataSourceName, ResourceType.DATASOURCE), getAction(request));
        if (!authResult.isAllowed()) {
            throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN)
                    .entity(String.format("Access-Check-Result: %s", authResult.toString())).build());
        }
    }

    return request;
}