List of usage examples for com.google.common.base Predicates notNull
@GwtCompatible(serializable = true) public static <T> Predicate<T> notNull()
From source file:org.eclipse.buildship.core.preferences.internal.DefaultPersistentModel.java
private static <T> List<T> loadList(Properties properties, String key, Function<String, T> conversion) { String values = (String) properties.get(key); if (values == null) { return null; } else {/*w w w .ja v a 2s. c o m*/ List<String> collection = Splitter.on(File.pathSeparator).omitEmptyStrings().splitToList(values); return FluentIterable.from(collection).transform(conversion).filter(Predicates.notNull()).toList(); } }
From source file:org.graylog2.users.UserServiceImpl.java
@Override public Set<String> getRoleNames(User user) { final Set<String> roleIds = user.getRoleIds(); if (roleIds.isEmpty()) { return Collections.emptySet(); }/*w w w . j a v a 2 s . c om*/ Map<String, Role> idMap; try { idMap = roleService.loadAllIdMap(); } catch (NotFoundException e) { LOG.error("Unable to load role ID map. Using empty map.", e); idMap = Collections.emptyMap(); } return ImmutableSet.copyOf(Iterables .filter(Collections2.transform(roleIds, Roles.roleIdToNameFunction(idMap)), Predicates.notNull())); }
From source file:org.eclipse.buildship.core.preferences.internal.PersistentModelConverter.java
private static <T> List<T> loadList(Properties properties, String key, Function<String, T> conversion) { String values = (String) properties.get(key); if (values == null) { return ImmutableList.of(); } else {/* w w w . j a va 2s . co m*/ List<String> collection = Splitter.on(File.pathSeparator).omitEmptyStrings().splitToList(values); return FluentIterable.from(collection).transform(conversion).filter(Predicates.notNull()).toList(); } }
From source file:com.isotrol.impe3.nr.api.NodeQueries.java
/** * Merges all queries with must boolean operator * @param queries NodeQuery queries//from w w w .jav a 2 s . co m * @return NodeQuery with must operator with all queries. */ public static NodeQuery all(Iterable<? extends NodeQuery> queries) { queries = Iterables.filter(queries, Predicates.notNull()); final int n = Iterables.size(queries); if (n == 0) { return null; } else if (n == 1) { return Iterables.get(queries, 0); } final NRBooleanQuery q = bool(); for (NodeQuery c : queries) { q.must(c); } return q; }
From source file:com.datastax.driver.core.utils.SocketChannelMonitor.java
/** * @param channelFilter {@link Predicate} to use to determine whether or not a socket shall be considered. * @return Channels matching the given {@link Predicate}. */// ww w . j av a 2 s.c o m public Iterable<SocketChannel> matchingChannels(final Predicate<SocketChannel> channelFilter) { return Iterables.filter(Lists.newArrayList(channels), Predicates.and(Predicates.notNull(), channelFilter)); }
From source file:org.opensaml.saml.saml1.profile.impl.AddStatusToResponse.java
/** * Set the default list of status code values to insert, ordered such that the top level code is first * and every other code will be nested inside the previous one. * // w ww. jav a 2s. c om * @param codes list of status code values to insert */ public void setStatusCodes(@Nonnull @NonnullElements List<QName> codes) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); Constraint.isNotNull(codes, "Status code list cannot be null"); defaultStatusCodes = new ArrayList<>(Collections2.filter(codes, Predicates.notNull())); }
From source file:net.shibboleth.idp.consent.storage.impl.ConsentSerializer.java
/** {@inheritDoc} */ @Override/*from w w w .j a va 2 s . c o m*/ @Nonnull @NotEmpty public String serialize(@Nonnull final Map<String, Consent> consents) throws IOException { Constraint.isNotNull(consents, "Consents cannot be null"); final Collection<Consent> filteredConsents = Collections2.filter(consents.values(), Predicates.notNull()); Constraint.isNotEmpty(filteredConsents, "Consents cannot be empty"); final StringWriter sink = new StringWriter(128); final JsonGenerator gen = generatorFactory.createGenerator(sink); gen.writeStartArray(); for (final Consent consent : filteredConsents) { gen.writeStartObject(); final Integer symbol = symbolics.get(consent.getId()); if (symbol != null) { gen.write(ID_FIELD, symbol); } else { gen.write(ID_FIELD, consent.getId()); } if (consent.getValue() != null) { gen.write(VALUE_FIELD, consent.getValue()); } if (!consent.isApproved()) { gen.write(IS_APPROVED_FIELD, false); } gen.writeEnd(); } gen.writeEnd(); gen.close(); final String serialized = sink.toString(); log.debug("Serialized '{}' as '{}'", consents, serialized); return serialized; }
From source file:net.shibboleth.idp.ui.impl.SetRPUIInformation.java
/** * Set the system wide default languages. * /*from w w w .j a v a2s . c o m*/ * @param langs a semi-colon separated string. */ public void setFallbackLanguages(@Nonnull @NonnullElements final List<String> langs) { ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this); if (langs != null) { fallbackLanguages = new ArrayList(Collections2.filter(langs, Predicates.notNull())); } else { fallbackLanguages = null; } }
From source file:org.sonar.plsqlopen.CustomAnnotationBasedRulesDefinition.java
private void setupSqaleModel(NewRule rule, Class<?> ruleClass) { SqaleSubCharacteristic subChar = getSqaleSubCharAnnotation(ruleClass); if (subChar != null) { rule.setDebtSubCharacteristic(subChar.value()); }//from w ww. jav a 2s . com SqaleConstantRemediation constant = AnnotationUtils.getAnnotation(ruleClass, SqaleConstantRemediation.class); SqaleLinearRemediation linear = AnnotationUtils.getAnnotation(ruleClass, SqaleLinearRemediation.class); SqaleLinearWithOffsetRemediation linearWithOffset = AnnotationUtils.getAnnotation(ruleClass, SqaleLinearWithOffsetRemediation.class); Set<Annotation> remediations = Sets.newHashSet(constant, linear, linearWithOffset); if (Iterables.size(Iterables.filter(remediations, Predicates.notNull())) > 1) { throw new IllegalArgumentException("Found more than one SQALE remediation annotations on " + ruleClass); } if (constant != null) { rule.setDebtRemediationFunction(rule.debtRemediationFunctions().constantPerIssue(constant.value())); } if (linear != null) { rule.setDebtRemediationFunction(rule.debtRemediationFunctions().linear(linear.coeff())); rule.setEffortToFixDescription(linear.effortToFixDescription()); } if (linearWithOffset != null) { rule.setDebtRemediationFunction(rule.debtRemediationFunctions() .linearWithOffset(linearWithOffset.coeff(), linearWithOffset.offset())); rule.setEffortToFixDescription(linearWithOffset.effortToFixDescription()); } }
From source file:co.cask.cdap.internal.app.runtime.adapter.PluginRepository.java
/** * Returns a {@link Map.Entry} represents the plugin information for the plugin being requested. * * @param template name of the template/*from w ww. j a va 2s.c o m*/ * @param pluginType plugin type name * @param pluginName plugin name * @param selector for selecting which plugin to use * @return the entry found or {@code null} if none was found */ @Nullable public Map.Entry<PluginInfo, PluginClass> findPlugin(String template, final String pluginType, final String pluginName, PluginSelector selector) { // Transform by matching type, name. If there is no match, the map value is null. // We then filter out null value SortedMap<PluginInfo, PluginClass> plugins = ImmutableSortedMap.copyOf(Maps.filterValues( Maps.transformValues(getPlugins(template), new Function<Collection<PluginClass>, PluginClass>() { @Nullable @Override public PluginClass apply(Collection<PluginClass> input) { for (PluginClass pluginClass : input) { if (pluginClass.getType().equals(pluginType) && pluginClass.getName().equals(pluginName)) { return pluginClass; } } return null; } }), Predicates.notNull())); return plugins.isEmpty() ? null : selector.select(plugins); }