List of usage examples for com.google.common.base Predicates contains
@GwtIncompatible(value = "java.util.regex.Pattern") public static Predicate<CharSequence> contains(Pattern pattern)
From source file:com.flowlogix.ejb.StatefulUtil.java
/** * Pings all pingable SFSBs in the session * //ww w . j av a 2 s.co m * @param session * @return true if successful, false if any of the pings failed */ public static boolean pingStateful(Session session) { boolean rv = true; List<String> attrNames = FluentIterable.from(session.getAttributeKeys()) .transform(new Function<Object, String>() { @Override public String apply(Object f) { if (f instanceof String) { return (String) f; } else { return null; } } }).filter(Predicates.and(Predicates.notNull(), Predicates.contains(ejbPattern))).toList(); for (String attrName : attrNames) { synchronized (session.getId().toString().intern()) { try { Object _pingable = session.getAttribute(attrName); if (_pingable instanceof Pingable) { Pingable pingable = (Pingable) _pingable; pingable.ping(); } } catch (EJBException e) { log.debug("Failed to Ping Stateful EJB: ", e); rv = false; // signal failure if any of the pings fail session.removeAttribute(attrName); } } } return rv; }
From source file:org.richfaces.demo.RF10888.java
private Predicate<Person> contains(String value, Function<Person, CharSequence> accessor) { return Predicates.compose( Predicates.contains(Pattern.compile(Pattern.quote(value), Pattern.CASE_INSENSITIVE)), accessor); }
From source file:com.eucalyptus.cloudformation.ws.CloudFormationRequestLoggingFilter.java
@Override public Collection<String> apply(final Collection<String> parametersOrBody) { if (Iterables.tryFind(ACTION_NVPS, Predicates.in(parametersOrBody)).isPresent()) { final Iterable<String> templateBodyNVPs = Iterables.filter(parametersOrBody, Predicates.contains(TEMPLATE_BODY_PARAMETER_REGEX)); final Iterable<String> parametersNVPs = Iterables.filter(parametersOrBody, Predicates.contains(PARAMETERS_PARAMETER_REGEX)); if (!Iterables.isEmpty(templateBodyNVPs) || !Iterables.isEmpty(parametersNVPs)) { final ArrayList<String> parametersCopy = Lists.newArrayList(parametersOrBody); redactParameters(parametersCopy, templateBodyNVPs, TEMPLATE_BODY_PARAMETER_REGEX); redactParameters(parametersCopy, parametersNVPs, PARAMETERS_PARAMETER_REGEX); return parametersCopy; }//from w ww .jav a2s. c om } return parametersOrBody; }
From source file:net.derquinse.common.meta.StringMetaProperty.java
/** * Returns a predicate that evaluates to {@code true} if the property value being tested contains * any match for the given regular expression pattern. The test used is equivalent to * {@code regex.matcher(arg).find()}// w w w . java 2s . co m */ public final Predicate<C> contains(Pattern pattern) { return compose(Predicates.contains(pattern)); }
From source file:org.apache.abdera2.common.misc.MorePredicates.java
public static <T> Selector<T> containsPattern(Class<T> _class, String method, Pattern pattern) { return PropertySelector.<T>create(_class, method, Predicates.contains(pattern)); }
From source file:com.vino.AppModule.java
@Provides public CORSAuthorizer getCorsAuthorizer() { return new StdCORSAuthorizer.Builder().setPathMatcher(Predicates.<CharSequence>alwaysTrue()) .setPathMatcher(Predicates.contains(Pattern.compile(".*"))) .setAllowedMethods(ImmutableList.of("GET", "POST")).build(); }
From source file:org.seedstack.monitoring.batch.internal.rest.job.JobResource.java
/** * Retrieves the list of jobs./*from ww w . ja v a 2 s. co m*/ * * @param pageIndex the page index * @param pageSize the page size * @return the response */ @GET @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions("seed:monitoring:batch:read") public Response jobs(@DefaultValue("1") @QueryParam("pageIndex") int pageIndex, @DefaultValue("20") @QueryParam("pageSize") int pageSize, @QueryParam("searchedJob") String searchedJob) { Collection<String> names; int totalItems = jobService.countJobs(); if (searchedJob != null) { names = Collections2.filter(jobService.listJobs(0, totalItems), Predicates.contains(Pattern.compile(searchedJob, Pattern.CASE_INSENSITIVE))); totalItems = names.size(); } else { int startJob = (pageIndex - 1) * pageSize; names = jobService.listJobs(startJob, pageSize); } ArrayList<JobInfo> jobs = new ArrayList<JobInfo>(); for (String name : names) { int count; try { count = jobService.countJobExecutionsForJob(name); } catch (NoSuchJobException e) { return Response.status(Response.Status.BAD_REQUEST).entity("There is no such jobs ") .type(MediaType.TEXT_PLAIN).build(); } boolean launchable = jobService.isLaunchable(name); boolean incrementable = jobService.isIncrementable(name); JobInfo jobsInfo = new JobInfo(name, count, null, launchable, incrementable); jobs.add(jobsInfo); } JobRepresentation jobRepresentation = new JobRepresentation(pageIndex, pageSize, totalItems, jobs); return Response.ok(jobRepresentation).build(); }
From source file:org.jclouds.trmk.vcloud_0_8.functions.ParseLoginResponseFromHeaders.java
public String parseTokenFromHeaders(HttpResponse from) { String cookieHeader = from.getFirstHeaderOrNull("x-vcloud-authorization"); if (cookieHeader != null) { Matcher matcher = pattern.matcher(cookieHeader); return matcher.find() ? matcher.group(2) : cookieHeader; } else {/*from w w w.j av a 2 s .c om*/ try { cookieHeader = Iterables.find(from.getHeaders().get(HttpHeaders.SET_COOKIE), Predicates.contains(pattern)); Matcher matcher = pattern.matcher(cookieHeader); matcher.find(); return matcher.group(2); } catch (NoSuchElementException e) { throw new HttpResponseException(String.format("Header %s or %s must be present", "x-vcloud-authorization", HttpHeaders.SET_COOKIE), null, from); } } }
From source file:com.flowlogix.security.cdi.ShiroSessionScopeContext.java
public <T> void onDestroy(Session session) { List<String> attrNames = FluentIterable.from(session.getAttributeKeys()) .transform(new Function<Object, String>() { @Override//w w w . ja va 2 s.com public String apply(Object f) { return f instanceof String ? (String) f : null; } }).filter(Predicates.and(Predicates.notNull(), Predicates.contains(bpPattern))).toList(); for (String attrName : attrNames) { @SuppressWarnings("unchecked") ScopeInst<T> scopeInst = (ScopeInst<T>) session.getAttribute(attrName); if (scopeInst != null) { scopeInst.bean.destroy(scopeInst.instance, scopeInst.context); } } }
From source file:dodola.anole.lib.FileUtils.java
/** * Find a list of files in a directory, using a specified path pattern. *///from ww w .java2 s .c o m public static List<File> find(File base, final Pattern pattern) { checkArgument(base.isDirectory(), "'base' must be a directory."); return Files.fileTreeTraverser().preOrderTraversal(base) .filter(Predicates.compose(Predicates.contains(pattern), GET_PATH)).toList(); }