List of usage examples for com.google.common.base Predicates instanceOf
@GwtIncompatible("Class.isInstance") public static Predicate<Object> instanceOf(Class<?> clazz)
From source file:org.onos.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement.java
protected final <S extends DeclaredStatement<?>> S firstDeclared(Class<S> type) { return type.cast(Iterables.find(substatements, Predicates.instanceOf(type))); }
From source file:clocker.docker.entity.microservice.MicroserviceDockerfileImpl.java
@Override protected void doStart(Collection<? extends Location> locations) { Optional<Location> dockerLocation = Iterables.tryFind(getLocations(), Predicates.instanceOf(DockerLocation.class)); if (!dockerLocation.isPresent()) { String locationName = DOCKER_LOCATION_PREFIX + getId(); DockerInfrastructure dockerInfrastructure = addChild(EntitySpec.create(DockerInfrastructure.class) .configure(DockerInfrastructure.DOCKER_HOST_CLUSTER_MIN_SIZE, 1) .configure(DockerInfrastructure.SDN_ENABLE, false) .configure(DockerInfrastructure.LOCATION_NAME, locationName) .displayName("Docker Infrastructure")); Entities.start(dockerInfrastructure, locations); dockerLocation = Optional.of(getManagementContext().getLocationRegistry().resolve(locationName)); }/*from ww w .jav a 2s . com*/ Entities.start(vanillaDockerApplication, dockerLocation.asSet()); }
From source file:com.google.errorprone.refaster.UNewArray.java
@Override @Nullable//from w w w. j av a 2 s.c o m public Choice<Unifier> visitNewArray(NewArrayTree newArray, @Nullable Unifier unifier) { boolean hasRepeated = getInitializers() != null && Iterables.any(getInitializers(), Predicates.instanceOf(URepeated.class)); return unifyNullable(unifier, getType(), newArray.getType()) .thenChoose(unifications(getDimensions(), newArray.getDimensions())) .thenChoose(unifications(getInitializers(), newArray.getInitializers(), hasRepeated)); }
From source file:brooklyn.entity.nosql.redis.RedisStoreImpl.java
@Override protected void connectSensors() { super.connectSensors(); connectServiceUpIsRunning();// w ww .j a va 2 s.c o m // Find an SshMachineLocation for the UPTIME feed Optional<Location> location = Iterables.tryFind(getLocations(), Predicates.instanceOf(SshMachineLocation.class)); if (!location.isPresent()) throw new IllegalStateException("Could not find SshMachineLocation in list of locations"); SshMachineLocation machine = (SshMachineLocation) location.get(); String statsCommand = getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info stats"; sshFeed = SshFeed.builder().entity(this).machine(machine).period(5, TimeUnit.SECONDS) .poll(new SshPollConfig<Integer>(UPTIME) .command(getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info server") .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("uptime_in_seconds"))) .poll(new SshPollConfig<Integer>(TOTAL_CONNECTIONS_RECEIVED).command(statsCommand) .onFailureOrException(Functions.constant(-1)) .onSuccess(infoFunction("total_connections_received"))) .poll(new SshPollConfig<Integer>(TOTAL_COMMANDS_PROCESSED).command(statsCommand) .onFailureOrException(Functions.constant(-1)) .onSuccess(infoFunction("total_commands_processed"))) .poll(new SshPollConfig<Integer>(EXPIRED_KEYS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("expired_keys"))) .poll(new SshPollConfig<Integer>(EVICTED_KEYS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("evicted_keys"))) .poll(new SshPollConfig<Integer>(KEYSPACE_HITS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("keyspace_hits"))) .poll(new SshPollConfig<Integer>(KEYSPACE_MISSES).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("keyspace_misses"))) .build(); }
From source file:org.apache.wicket.atmosphere.MethodEventSubscription.java
/** * Construct.// w ww . j av a 2 s . c o m * * @param component * @param behavior * @param method */ public MethodEventSubscription(Component component, Behavior behavior, Method method) { componentPath = component.getPageRelativePath(); behaviorIndex = behavior == null ? null : component.getBehaviorId(behavior); Class<?> eventType = method.getParameterTypes()[1]; Subscribe subscribe = method.getAnnotation(Subscribe.class); filter = Predicates.and(Predicates.instanceOf(eventType), createFilter(subscribe.filter())); contextAwareFilter = createFilter(subscribe.contextAwareFilter()); methodName = method.getName(); }
From source file:brooklyn.location.access.PortForwardManagerLocationResolver.java
@Override public Location newLocationFromString(Map locationFlags, String spec, brooklyn.location.LocationRegistry registry) { ConfigBag config = extractConfig(locationFlags, spec, registry); Map globalProperties = registry.getProperties(); String namedLocation = (String) locationFlags.get(LocationInternal.NAMED_SPEC_NAME.getName()); String scope = config.get(PortForwardManager.SCOPE); Optional<Location> result = Iterables.tryFind(managementContext.getLocationManager().getLocations(), Predicates.and(Predicates.instanceOf(PortForwardManager.class), LocationPredicates.configEqualTo(PortForwardManager.SCOPE, scope))); if (result.isPresent()) { return result.get(); } else {/*from w ww . ja v a 2s . c o m*/ PortForwardManager loc = managementContext.getLocationManager() .createLocation(LocationSpec.create(PortForwardManagerImpl.class) .configure(config.getAllConfig()).configure(LocationConfigUtils .finalAndOriginalSpecs(spec, locationFlags, globalProperties, namedLocation))); if (LOG.isDebugEnabled()) LOG.debug("Created " + loc + " for scope " + scope); return loc; } }
From source file:org.jclouds.chef.binders.BindCreateClientOptionsToJsonPayload.java
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest, "this binder is only valid for GeneratedHttpRequests"); GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; checkState(gRequest.getInvocation().getArgs() != null, "args should be initialized at this point"); String name = checkNotNull(postParams.remove("name"), "name").toString(); CreateClientOptions options = (CreateClientOptions) Iterables.find(gRequest.getInvocation().getArgs(), Predicates.instanceOf(CreateClientOptions.class)); return bindToRequest(request, new CreateClientParams(name, options)); }
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.DestroyMessageCreationValidator.java
/** * Check that there is not {@link ISequenceEvent} on the target lifeline * with range's upperbound upper than the firstClickLocation.y . * // w w w .j a v a 2 s . c o m * @return true if not {@link ISequenceEvent} upper than * firstClickLocation.y */ private boolean checkNotEventAtUpperTimeInSameLifeline() { boolean valid = true; SequenceDiagram sequenceDiagram = sequenceElementSource.getDiagram(); SequenceDiagramQuery sequenceDiagramQuery = new SequenceDiagramQuery(sequenceDiagram); for (ISequenceEvent sequenceEvent : Iterables.filter( sequenceDiagramQuery.getAllSequenceEventsUpperThan(firstClickLocation.y), Predicates.not(Predicates.instanceOf(Lifeline.class)))) { if (isSequenceEventOfLifeline(sequenceEvent, sequenceElementTarget.getLifeline()) || isMessageTargeting(sequenceEvent, sequenceElementTarget.getLifeline()) || isDestroyMessageFor(sequenceEvent, sequenceElementTarget.getLifeline().get().getInstanceRole())) { valid = false; break; } } return valid; }
From source file:org.eclipselabs.agrum.services.model.plugin.parser.ModelParser.java
/** * To get an iterator on each state of the state machine * @param s - the state machine/*from w ww . ja va2s . c o m*/ * @return the iterator */ private static Iterator<State> StateIterator(StateMachine s) { Predicate<Object> allStates = Predicates.instanceOf(State.class); Iterator<EObject> result = Iterators.filter(s.eAllContents(), allStates); Iterator<State> states = Iterators.transform(result, new com.google.common.base.Function<EObject, State>() { @Override public State apply(EObject arg0) { return (State) arg0; } }); return states; }
From source file:org.apache.brooklyn.entity.nosql.redis.RedisStoreImpl.java
@Override protected void connectSensors() { super.connectSensors(); connectServiceUpIsRunning();// w ww.jav a 2 s .c om // Find an SshMachineLocation for the UPTIME feed Optional<Location> location = Iterables.tryFind(getLocations(), Predicates.instanceOf(SshMachineLocation.class)); if (!location.isPresent()) throw new IllegalStateException("Could not find SshMachineLocation in list of locations"); SshMachineLocation machine = (SshMachineLocation) location.get(); String statsCommand = getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info stats"; boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS); sshFeed = SshFeed.builder().entity(this).machine(machine).period(5, TimeUnit.SECONDS) .poll(new SshPollConfig<Integer>(UPTIME) .command(getDriver().getRunDir() + "/bin/redis-cli -p " + getRedisPort() + " info server") .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("uptime_in_seconds")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(TOTAL_CONNECTIONS_RECEIVED).command(statsCommand) .onFailureOrException(Functions.constant(-1)) .onSuccess(infoFunction("total_connections_received")).enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(TOTAL_COMMANDS_PROCESSED).command(statsCommand) .onFailureOrException(Functions.constant(-1)) .onSuccess(infoFunction("total_commands_processed")).enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(EXPIRED_KEYS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("expired_keys")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(EVICTED_KEYS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("evicted_keys")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(KEYSPACE_HITS).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("keyspace_hits")) .enabled(retrieveUsageMetrics)) .poll(new SshPollConfig<Integer>(KEYSPACE_MISSES).command(statsCommand) .onFailureOrException(Functions.constant(-1)).onSuccess(infoFunction("keyspace_misses")) .enabled(retrieveUsageMetrics)) .build(); }