List of usage examples for com.google.common.base Predicates notNull
@GwtCompatible(serializable = true) public static <T> Predicate<T> notNull()
From source file:org.jclouds.azurecompute.util.NetworkSecurityGroups.java
public static List<Rule> getCustomRules(final NetworkSecurityGroup networkSecurityGroup) { final List<Rule> rules = networkSecurityGroup.rules(); return FluentIterable.from(rules).filter(Predicates.notNull()).filter(new Predicate<Rule>() { @Override//w w w. j a v a2s . c o m public boolean apply(final Rule rule) { return rule.isDefault() == null || !rule.isDefault(); } }).toSortedList(new Comparator<Rule>() { @Override public int compare(final Rule r1, final Rule r2) { final int p1 = Integer.parseInt(r1.priority()); final int p2 = Integer.parseInt(r2.priority()); return p1 < p2 ? -1 : p1 == p2 ? 0 : 1; } }); }
From source file:com.isotrol.impe3.api.component.sitemap.Sitemap.java
private static <T> ImmutableList<T> create(Iterable<T> entries) { if (entries == null) { return ImmutableList.of(); } else {// ww w.j a v a 2 s .c o m return ImmutableList.copyOf(Iterables.filter(entries, Predicates.notNull())); } }
From source file:org.robotframework.red.viewers.Selections.java
public static <T> List<T> getAdaptableElements(final IStructuredSelection selection, final Class<T> elementsClass) { final List<?> selectionAsList = selection.toList(); return newArrayList(Iterables.filter( transform(selectionAsList, toObjectOfClassUsingAdapters(elementsClass)), Predicates.notNull())); }
From source file:org.eclipse.buildship.ui.util.workbench.WorkingSetUtils.java
/** * Converts the given working set names to {@link org.eclipse.ui.IWorkingSet} instances. Filters * out working sets that cannot be found by the {@link IWorkingSetManager}. * * @param workingSetNames the names of the working sets * @return the {@link org.eclipse.ui.IWorkingSet} instances *///w w w.ja v a 2 s . co m public static IWorkingSet[] toWorkingSets(List<String> workingSetNames) { final IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); return FluentIterable.from(workingSetNames).transform(new Function<String, IWorkingSet>() { @Override public IWorkingSet apply(String name) { return workingSetManager.getWorkingSet(name); } }).filter(Predicates.notNull()).toArray(IWorkingSet.class); }
From source file:com.flowlogix.ejb.StatefulUtil.java
/** * Pings all pingable SFSBs in the session * /*from w w w . j av a2s. 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.apache.aurora.common.base.Closures.java
/** * Combines multiple closures into a single closure, whose calls are replicated sequentially * in the order that they were provided. * If an exception is encountered from a closure it propagates to the top-level closure and the * remaining closures are not executed.//from w w w . j a v a2 s . c o m * * @param closures Closures to combine. * @param <T> Type accepted by the closures. * @return A single closure that will fan out all calls to {@link Closure#execute(Object)} to * the wrapped closures. */ public static <T> Closure<T> combine(Iterable<Closure<T>> closures) { checkNotNull(closures); checkArgument(Iterables.all(closures, Predicates.notNull())); final Iterable<Closure<T>> closuresCopy = ImmutableList.copyOf(closures); return item -> { for (Closure<T> closure : closuresCopy) { closure.execute(item); } }; }
From source file:org.apache.aurora.common.base.Consumers.java
/** * Combines multiple consumers into a single consumer, whose calls are replicated sequentially * in the order that they were provided. * If an exception is encountered from a consumer it propagates to the top-level consumer and the * remaining consumer are not executed.// ww w. j ava 2 s . c o m * * @param consumers Consumers to combine. * @param <T> Type accepted by the consumers. * @return A single consumer that will fan out all calls to {@link Consumer#accept(Object)} to * the wrapped consumers. */ public static <T> Consumer<T> combine(List<Consumer<T>> consumers) { checkNotNull(consumers); checkArgument(Iterables.all(consumers, Predicates.notNull())); return consumers.stream().reduce(noop(), Consumer::andThen); }
From source file:org.sonar.server.app.TomcatConnectors.java
static void configure(Tomcat tomcat, Props props) { List<Connector> connectors = from(asList(newHttpConnector(props), newAjpConnector(props))) .filter(Predicates.notNull()).toList(); verify(connectors);/*from w w w . j a v a2s . c om*/ tomcat.setConnector(connectors.get(0)); for (Connector connector : connectors) { tomcat.getService().addConnector(connector); } }
From source file:org.sfs.util.ConfigHelper.java
public static Iterable<String> getArrayFieldOrEnv(JsonObject config, String name, Iterable<String> defaultValue) { String envVar = formatEnvVariable(name); //USED_ENV_VARS.add(envVar); if (config.containsKey(name)) { JsonArray values = config.getJsonArray(name); if (values != null) { Iterable<String> iterable = FluentIterable.from(values).filter(Predicates.notNull()) .filter(input -> input instanceof String).transform(input -> input.toString()); log(name, envVar, name, iterable); return iterable; }/* w w w.ja v a 2 s . c o m*/ } else { String value = System.getenv(envVar); if (value != null) { log(name, envVar, envVar, value); return Splitter.on(',').split(value); } } log(name, envVar, null, defaultValue); return defaultValue; }
From source file:org.apache.jackrabbit.oak.security.user.AuthorizableIterator.java
static AuthorizableIterator create(Iterator<String> authorizableOakPaths, UserManagerImpl userManager, AuthorizableType authorizableType) { Iterator it = Iterators.transform(authorizableOakPaths, new PathToAuthorizable(userManager, authorizableType)); long size = getSize(authorizableOakPaths); return new AuthorizableIterator(Iterators.filter(it, Predicates.notNull()), size); }