List of usage examples for com.google.common.collect Iterables indexOf
public static <T> int indexOf(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:edu.mit.streamjit.util.bytecode.insts.PhiInst.java
public Value put(BasicBlock b, Value v) { checkNotNull(b);/* ww w . j a v a 2 s .c om*/ checkNotNull(v); checkArgument(v.getType().isSubtypeOf(getType()), "%s not a %s", v, getType()); int bbi = Iterables.indexOf(operands(), Predicates.<Value>equalTo(b)); Value oldVal = get(b); if (bbi != -1) setOperand(bbi + 1, v); else { addOperand(getNumOperands(), b); addOperand(getNumOperands(), v); } return oldVal; }
From source file:io.druid.server.http.security.DatasourceResourceFilter.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// w w w . java 2 s . co m public boolean apply(PathSegment input) { return input.getPath().equals("datasources"); } }) + 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; }
From source file:io.druid.indexing.overlord.http.security.SupervisorResourceFilter.java
@Override public ContainerRequest filter(ContainerRequest request) { final String supervisorId = Preconditions.checkNotNull(request.getPathSegments() .get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() { @Override// www . j a v a2 s .co m public boolean apply(PathSegment input) { return input.getPath().equals("supervisor"); } }) + 1).getPath()); Optional<SupervisorSpec> supervisorSpecOptional = supervisorManager.getSupervisorSpec(supervisorId); if (!supervisorSpecOptional.isPresent()) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) .entity(StringUtils.format("Cannot find any supervisor with id: [%s]", supervisorId)).build()); } final SupervisorSpec spec = supervisorSpecOptional.get(); Preconditions.checkArgument(spec.getDataSources() != null && spec.getDataSources().size() > 0, "No dataSources found to perform authorization checks"); Function<String, ResourceAction> resourceActionFunction = getAction(request) == Action.READ ? AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR : AuthorizationUtils.DATASOURCE_WRITE_RA_GENERATOR; Access authResult = AuthorizationUtils.authorizeAllResourceActions(getReq(), Iterables.transform(spec.getDataSources(), resourceActionFunction), getAuthorizerMapper()); if (!authResult.isAllowed()) { throw new ForbiddenException(authResult.toString()); } return request; }
From source file:edu.mit.streamjit.util.bytecode.insts.SwitchInst.java
public BasicBlock get(Constant<Integer> cst) { int ci = Iterables.indexOf(operands(), Predicates.<Value>equalTo(cst)); return ci != -1 ? (BasicBlock) getOperand(ci + 1) : null; }
From source file:com.replaymod.replaystudio.pathing.change.AddKeyframe.java
@Override public void apply(Timeline timeline) { Preconditions.checkState(!applied, "Already applied!"); Path path = timeline.getPaths().get(this.path); Keyframe keyframe = path.insert(time); index = Iterables.indexOf(path.getKeyframes(), Predicates.equalTo(keyframe)); applied = true;// w ww .ja v a 2s.c o m }
From source file:org.apache.druid.indexing.overlord.http.security.SupervisorResourceFilter.java
@Override public ContainerRequest filter(ContainerRequest request) { final String supervisorId = Preconditions.checkNotNull(request.getPathSegments() .get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() { @Override/*from w ww. java2 s . c o m*/ public boolean apply(PathSegment input) { return "supervisor".equals(input.getPath()); } }) + 1).getPath()); Optional<SupervisorSpec> supervisorSpecOptional = supervisorManager.getSupervisorSpec(supervisorId); if (!supervisorSpecOptional.isPresent()) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) .entity(StringUtils.format("Cannot find any supervisor with id: [%s]", supervisorId)).build()); } final SupervisorSpec spec = supervisorSpecOptional.get(); Preconditions.checkArgument(spec.getDataSources() != null && spec.getDataSources().size() > 0, "No dataSources found to perform authorization checks"); Function<String, ResourceAction> resourceActionFunction = getAction(request) == Action.READ ? AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR : AuthorizationUtils.DATASOURCE_WRITE_RA_GENERATOR; Access authResult = AuthorizationUtils.authorizeAllResourceActions(getReq(), Iterables.transform(spec.getDataSources(), resourceActionFunction), getAuthorizerMapper()); if (!authResult.isAllowed()) { throw new ForbiddenException(authResult.toString()); } return request; }
From source file:org.netbeans.modules.android.project.configs.ConfigGroup.java
public void updateCurrentConfig(Config config) { int idx = Iterables.indexOf(configs, Predicates.equalTo(currentConfig)); if (idx >= 0) { configs.set(idx, config);//ww w. j a va 2s . c om } }
From source file:org.richfaces.model.SwingTreeNodeImpl.java
public int getIndex(TreeNode node) { return Iterables.indexOf(children, Predicates.equalTo(node)); }
From source file:edu.mit.streamjit.util.bytecode.insts.SwitchInst.java
public BasicBlock put(Constant<Integer> cst, BasicBlock bb) { BasicBlock oldVal = get(cst);//from w w w . jav a 2s . c om int ci = Iterables.indexOf(operands(), Predicates.<Value>equalTo(cst)); if (ci != -1) setOperand(ci + 1, bb); else { addOperand(Iterables.size(operands()), cst); addOperand(Iterables.size(operands()), bb); } return oldVal; }
From source file:io.druid.indexing.overlord.http.security.TaskResourceFilter.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 taskId = Preconditions.checkNotNull(request.getPathSegments() .get(Iterables.indexOf(request.getPathSegments(), new Predicate<PathSegment>() { @Override/*from w ww . j a va 2s.c om*/ public boolean apply(PathSegment input) { return input.getPath().equals("task"); } }) + 1).getPath()); Optional<Task> taskOptional = taskStorageQueryAdapter.getTask(taskId); if (!taskOptional.isPresent()) { throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) .entity(String.format("Cannot find any task with id: [%s]", taskId)).build()); } final String dataSourceName = Preconditions.checkNotNull(taskOptional.get().getDataSource()); 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; }