List of usage examples for com.google.common.base Predicates instanceOf
@GwtIncompatible("Class.isInstance") public static Predicate<Object> instanceOf(Class<?> clazz)
From source file:hudson.plugins.emailext.plugins.recipients.RecipientProviderUtilities.java
public static Set<User> getChangeSetAuthors(final Collection<Run<?, ?>> runs, final IDebug debug) { debug.send(" Collecting change authors..."); final Set<User> users = new HashSet<>(); for (final Run<?, ?> run : runs) { debug.send(" build: %d", run.getNumber()); if (run instanceof AbstractBuild<?, ?>) { final ChangeLogSet<?> changeLogSet = ((AbstractBuild<?, ?>) run).getChangeSet(); if (changeLogSet == null) { debug.send(" changeLogSet was null"); } else { addChangeSetUsers(changeLogSet, users, debug); }// w w w .j ava 2s . co m } else { try { Method getChangeSets = run.getClass().getMethod("getChangeSets"); if (List.class.isAssignableFrom(getChangeSets.getReturnType())) { @SuppressWarnings("unchecked") List<ChangeLogSet<ChangeLogSet.Entry>> sets = (List<ChangeLogSet<ChangeLogSet.Entry>>) getChangeSets .invoke(run); if (Iterables.all(sets, Predicates.instanceOf(ChangeLogSet.class))) { for (ChangeLogSet<ChangeLogSet.Entry> set : sets) { addChangeSetUsers(set, users, debug); } } } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { debug.send("Exception getting changesets for %s: %s", run, e); } } } return users; }
From source file:brooklyn.entity.waratek.WaratekJavaApplicationImpl.java
public JavaVirtualContainer getJavaVirtualContainer() { WaratekContainerLocation location = (WaratekContainerLocation) Iterables.find(getLocations(), Predicates.instanceOf(WaratekContainerLocation.class)); return location.getOwner(); }
From source file:org.apache.brooklyn.core.location.access.PortForwardManagerLocationResolver.java
@Override public Location newLocationFromString(Map locationFlags, String spec, 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 w w . j a v a 2 s . co 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.apache.abdera2.common.misc.MorePredicates.java
/** * Returns a Predicate that checks if the value of a named property of * instances of the specified class is an instance of the given test class *///from ww w. j a v a 2 s . c om public static <T> Selector<T> instanceOf(Class<T> _class, String method, Class<?> _test) { return PropertySelector.<T>create(_class, method, Predicates.instanceOf(_test)); }
From source file:org.eclipse.emf.compare.uml2.internal.provider.decorator.StereotypeReferenceChangeItemProviderDecorator.java
/** * Retrieves the {@link ReferenceChange} which is refined by the {@link StereotypeReferenceChange}. * //from w ww . ja v a2 s . co m * @param diff * Input object. . * @return an {@link ReferenceChange} if the input is a {@link StereotypeReferenceChange} which is refined * by an {@link ReferenceChange} or <code>null</code> otherwise. */ private ReferenceChange getReferenceChange(Object diff) { ReferenceChange referenceChange = null; if (diff instanceof StereotypeReferenceChange) { StereotypeReferenceChange stereotypeReferenceChange = (StereotypeReferenceChange) diff; Optional<Diff> element = Iterables.tryFind(stereotypeReferenceChange.getRefinedBy(), Predicates.instanceOf(ReferenceChange.class)); if (element.isPresent()) { referenceChange = (ReferenceChange) element.get(); } } return referenceChange; }
From source file:org.polarsys.reqcycle.traceability.table.handlers.DeleteLinkHandler.java
@Override public boolean isEnabled() { ISelection selection = getSelection(); if (selection instanceof IStructuredSelection) { Iterator<?> iterator = ((IStructuredSelection) selection).iterator(); return Iterators.all(iterator, Predicates.instanceOf(TransverseLink.class)); }// w w w . j a v a2s . c om return false; }
From source file:org.jclouds.openstack.nova.v1_1.binders.BindSecurityGroupRuleToJsonPayload.java
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { Builder<String, String> payload = ImmutableMap.builder(); payload.putAll(postParams);//from w ww .ja v a2 s . c o m checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>, "this binder is only valid for GeneratedHttpRequests!"); GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; Ingress ingress = Ingress.class .cast(Iterables.find(gRequest.getArgs(), Predicates.instanceOf(Ingress.class))); payload.put("ip_protocol", ingress.getIpProtocol().toString()); payload.put("from_port", ingress.getFromPort() + ""); payload.put("to_port", ingress.getToPort() + ""); return super.bindToRequest(request, ImmutableMap.of("security_group_rule", payload.build())); }
From source file:org.jclouds.abiquo.binders.BindToPath.java
/** * Get the link to be used to build the request URI. * //w w w . j a v a 2s. c om * @param request * The current request. * @param payload * The object containing the link. * @return The link to be used to build the request URI. */ static RESTLink getLinkToUse(final GeneratedHttpRequest request, final SingleResourceTransportDto payload) { int argIndex = request.getInvocation().getArgs().indexOf(payload); Annotation[] annotations = request.getInvocation().getInvokable().getParameters().get(argIndex) .getAnnotations(); EndpointLink linkName = (EndpointLink) Iterables.find(Arrays.asList(annotations), Predicates.instanceOf(EndpointLink.class), null); if (linkName == null) { throw new BindException(request, "Expected a EndpointLink annotation but not found in the parameter"); } return checkNotNull(payload.searchLink(linkName.value()), "No link was found in object with rel: " + linkName); }
From source file:vazkii.botania.common.item.lens.LensInfluence.java
@Override public void updateBurst(IManaBurst burst, EntityThrowable entity, ItemStack stack) { if (!burst.isFake()) { double range = 3.5; List<Entity> movables = entity.worldObj.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range)); movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityArrow.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); movables.addAll(entity.worldObj.getEntitiesWithinAABB(EntityFallingBlock.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range))); movables.addAll(entity.worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range), Predicates.instanceOf(IManaBurst.class))); for (Entity movable : movables) { if (movable == burst) continue; if (movable instanceof IManaBurst) { IManaBurst otherBurst = (IManaBurst) movable; ItemStack lens = otherBurst.getSourceLens(); if (lens != null && lens.getItem() == ModItems.lens && lens.getItemDamage() == ItemLens.INFLUENCE) continue; ((IManaBurst) movable).setMotion(entity.motionX, entity.motionY, entity.motionZ); } else { movable.motionX = entity.motionX; movable.motionY = entity.motionY; movable.motionZ = entity.motionZ; }/* w w w . ja v a 2 s . c o m*/ } } }
From source file:hudson.plugins.emailext.plugins.recipients.CulpritsRecipientProvider.java
@Override public void addRecipients(final ExtendedEmailPublisherContext context, EnvVars env, Set<InternetAddress> to, Set<InternetAddress> cc, Set<InternetAddress> bcc) { final class Debug implements RecipientProviderUtilities.IDebug { private final ExtendedEmailPublisherDescriptor descriptor = Jenkins.getActiveInstance() .getDescriptorByType(ExtendedEmailPublisherDescriptor.class); private final PrintStream logger = context.getListener().getLogger(); public void send(final String format, final Object... args) { descriptor.debug(logger, format, args); }/*ww w .j ava 2s . c o m*/ } final Debug debug = new Debug(); Run<?, ?> run = context.getRun(); boolean runHasGetCulprits = false; // TODO: core 2.60+, workflow-job 2.12+: Switch to checking if run is RunWithSCM and make catch an else block try { Method getCulprits = run.getClass().getMethod("getCulprits"); runHasGetCulprits = true; if (Set.class.isAssignableFrom(getCulprits.getReturnType())) { @SuppressWarnings("unchecked") Set<User> users = (Set<User>) getCulprits.invoke(run); if (Iterables.all(users, Predicates.instanceOf(User.class))) { RecipientProviderUtilities.addUsers(users, context, env, to, cc, bcc, debug); } } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { // Only log a debug message if the exception is not due to an older WorkflowRun without getCulprits... if (!(run instanceof WorkflowRun && !runHasGetCulprits)) { debug.send("Exception getting culprits for %s: %s", run, e); } List<Run<?, ?>> builds = new ArrayList<>(); Run<?, ?> build = run; builds.add(build); build = build.getPreviousCompletedBuild(); while (build != null) { final Result buildResult = build.getResult(); if (buildResult != null) { if (buildResult.isWorseThan(Result.SUCCESS)) { debug.send("Including build %s with status %s", build.getId(), buildResult); builds.add(build); } else { break; } } build = build.getPreviousCompletedBuild(); } Set<User> users = RecipientProviderUtilities.getChangeSetAuthors(builds, debug); RecipientProviderUtilities.addUsers(users, context, env, to, cc, bcc, debug); } }