List of usage examples for com.google.common.base Predicates notNull
@GwtCompatible(serializable = true) public static <T> Predicate<T> notNull()
From source file:net.shibboleth.idp.saml.profile.config.saml2.BrowserSSOProfileConfiguration.java
/** * Set the default authentication contexts to use, expressed as custom principals. * /*from ww w .ja v a 2s . c o m*/ * @param contexts default authentication contexts to use */ public void setDefaultAuthenticationMethods( @Nonnull @NonnullElements final List<AuthnContextClassRefPrincipal> contexts) { Constraint.isNotNull(contexts, "List of contexts cannot be null"); defaultAuthenticationContexts = Lists.newArrayList(Collections2.filter(contexts, Predicates.notNull())); }
From source file:com.eucalyptus.autoscaling.config.AutoScalingConfiguration.java
private static <E extends Enum<E>> EnumSet<E> toEnumSet(final Class<E> enumClass, final String text) { final List<E> values = Lists.newArrayList( Iterables.filter(Iterables.transform(Splitter.on(",").omitEmptyStrings().trimResults().split(text), Enums.valueOfFunction(enumClass)), Predicates.notNull())); return values.isEmpty() ? EnumSet.noneOf(enumClass) : EnumSet.copyOf(values); }
From source file:org.eclipse.buildship.core.preferences.internal.DefaultPersistentModel.java
private static <T> void storeList(Properties properties, String key, Collection<T> values, Function<T, String> conversion) { if (values != null) { List<String> stringList = FluentIterable.from(values).transform(conversion).filter(Predicates.notNull()) .toList();/*from w w w .j a v a 2 s . c o m*/ properties.put(key, Joiner.on(File.pathSeparator).join(stringList)); } else if (properties.containsKey(key)) { properties.remove(key); } }
From source file:org.pentaho.di.trans.dataservice.serialization.DataServiceMetaStoreUtil.java
public Iterable<DataServiceMeta> getDataServices(final Repository repository, IMetaStore metaStore, final Function<Exception, Void> exceptionHandler) { MetaStoreFactory<ServiceTrans> serviceTransFactory = getServiceTransFactory(metaStore); List<ServiceTrans> serviceTransList; try {//w ww. ja v a2s .c o m serviceTransList = serviceTransFactory.getElements(); } catch (Exception e) { exceptionHandler.apply(e); serviceTransList = Collections.emptyList(); } Map<ServiceTrans.Reference, Supplier<TransMeta>> transMetaMap = FluentIterable.from(serviceTransList) .transformAndConcat(new Function<ServiceTrans, Iterable<ServiceTrans.Reference>>() { @Override public Iterable<ServiceTrans.Reference> apply(ServiceTrans serviceTrans) { return serviceTrans.getReferences(); } }).toMap(createTransMetaLoader(repository, exceptionHandler)); List<DataServiceMeta> dataServices = Lists.newArrayListWithExpectedSize(serviceTransList.size()); for (ServiceTrans serviceTrans : serviceTransList) { Optional<TransMeta> transMeta = FluentIterable.from(serviceTrans.getReferences()) .transform(Functions.forMap(transMetaMap)).transform(Suppliers.<TransMeta>supplierFunction()) .firstMatch(Predicates.notNull()); if (transMeta.isPresent()) { try { dataServices.add(getDataService(serviceTrans.getName(), transMeta.get())); } catch (Exception e) { exceptionHandler.apply(e); } } else { try { if (PentahoSessionHolder.getSession() != null && SecurityHelper.getInstance() .runAsSystem(() -> !ServiceTrans.isValid(repository).apply(serviceTrans))) { serviceTransFactory.deleteElement(serviceTrans.getName()); } } catch (Exception e) { exceptionHandler.apply(e); } } } return dataServices; }
From source file:net.shibboleth.idp.attribute.IdPAttribute.java
/** * Replaces the existing encoders for this attribute with the given encoders. * /*from w w w .ja v a 2s . c om*/ * @param newEncoders the new encoders for this attribute */ public void setEncoders(@Nullable @NullableElements final Collection<AttributeEncoder<?>> newEncoders) { final ImmutableSet.Builder<AttributeEncoder<?>> builder = ImmutableSet.builder(); if (newEncoders != null) { builder.addAll(Collections2.filter(newEncoders, Predicates.notNull())); } encoders = builder.build(); }
From source file:org.locationtech.geogig.geotools.plumbing.ExportDiffOp.java
private static Iterator<SimpleFeature> getFeatures(Iterator<DiffEntry> diffs, final boolean old, final ObjectDatabase database, final ObjectId metadataId, final ProgressListener progressListener) { final SimpleFeatureType featureType = addChangeTypeAttribute(database.getFeatureType(metadataId)); final RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType); final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); Function<DiffEntry, SimpleFeature> asFeature = new Function<DiffEntry, SimpleFeature>() { @Override/*w ww . j ava 2 s .co m*/ @Nullable public SimpleFeature apply(final DiffEntry input) { NodeRef nodeRef = old ? input.getOldObject() : input.getNewObject(); if (nodeRef == null) { return null; } final RevFeature revFeature = database.getFeature(nodeRef.objectId()); ImmutableList<Optional<Object>> values = revFeature.getValues(); for (int i = 0; i < values.size(); i++) { String name = featureType.getDescriptor(i + 1).getLocalName(); Object value = values.get(i).orNull(); featureBuilder.set(name, value); } featureBuilder.set(CHANGE_TYPE_NAME, input.changeType().name().charAt(0)); Feature feature = featureBuilder.buildFeature(nodeRef.name()); feature.getUserData().put(Hints.USE_PROVIDED_FID, true); feature.getUserData().put(RevFeature.class, revFeature); feature.getUserData().put(RevFeatureType.class, revFeatureType); if (feature instanceof SimpleFeature) { return (SimpleFeature) feature; } return null; } }; Iterator<SimpleFeature> asFeatures = Iterators.transform(diffs, asFeature); UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull()); return filterNulls; }
From source file:com.tinspx.util.net.FormEncodedBody.java
/** * Returns a modifiable view of the parameters. *//*from w w w .ja va 2 s .co m*/ public ListMultimap<String, String> parameters() { if (paramsView == null) { paramsView = Predicated.listMultimap(Listenable.listMultimap(params, new Listenable.Modification() { @Override public void onModify(Object src, Listenable.Event type) { array = null; } //don't track entries as values can be null }), Predicates.notNull(), Predicates.alwaysTrue(), false); } return paramsView; }
From source file:de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowsLoader.java
private Stream<PricingConditionsInfo> streamPricingConditionsInfos(@NonNull final BPartnerType bpartnerType) { final Map<BPartnerId, Integer> discountSchemaIdsByBPartnerId = bpartnersRepo .retrieveAllDiscountSchemaIdsIndexedByBPartnerId(bpartnerType); return discountSchemaIdsByBPartnerId.keySet().stream().map(lookups::lookupBPartner) .filter(Predicates.notNull()) .map(bpartner -> PricingConditionsInfo.builder().bpartner(bpartner) .pricingConditionsId( getPricingConditionsIdByBPartner(bpartner, discountSchemaIdsByBPartnerId)) .bpartnerType(bpartnerType).build()); }
From source file:org.sfs.elasticsearch.Elasticsearch.java
public Observable<Void> start(final VertxContext<Server> vertxContext, final JsonObject config, boolean isMasterNode) { SfsVertx sfsVertx = vertxContext.vertx(); Context context = sfsVertx.getOrCreateContext(); return Defer.aVoid().filter(aVoid -> status.compareAndSet(Status.STOPPED, Status.STARTING)) .flatMap(aVoid -> RxHelper.executeBlocking(context, sfsVertx.getBackgroundPool(), () -> { if (elasticSearchClient == null) { LOGGER.debug("Starting Elasticsearch"); try { ESLoggerFactory.setDefaultFactory(new Slf4jESLoggerFactory()); defaultScrollTimeout = Long.parseLong( ConfigHelper.getFieldOrEnv(config, "elasticsearch.defaultscrolltimeout", String.valueOf(TimeUnit.MINUTES.toMillis(2)))); defaultIndexTimeout = Long.parseLong( ConfigHelper.getFieldOrEnv(config, "elasticsearch.defaultindextimeout", "500")); defaultGetTimeout = Long.parseLong( ConfigHelper.getFieldOrEnv(config, "elasticsearch.defaultgettimeout", "500")); defaultSearchTimeout = Long.parseLong( ConfigHelper.getFieldOrEnv(config, "elasticsearch.defaultsearchtimeout", String.valueOf(TimeUnit.SECONDS.toMillis(5)))); defaultDeleteTimeout = Long.parseLong(ConfigHelper.getFieldOrEnv(config, "elasticsearch.defaultdeletetimeout", "500")); defaultAdminTimeout = Long.parseLong( ConfigHelper.getFieldOrEnv(config, "elasticsearch.defaultadmintimeout", String.valueOf(TimeUnit.SECONDS.toMillis(30)))); shards = Integer.parseInt( ConfigHelper.getFieldOrEnv(config, "elasticsearch.shards", String.valueOf(1))); replicas = Integer.parseInt(ConfigHelper.getFieldOrEnv(config, "elasticsearch.replicas", String.valueOf(0))); Settings.Builder settings = Settings.settingsBuilder(); settings.put("node.client", true); String clusterName = ConfigHelper.getFieldOrEnv(config, "elasticsearch.cluster.name"); if (clusterName != null) { settings.put("cluster.name", clusterName); }/*www . j a v a2s. c o m*/ String nodeName = ConfigHelper.getFieldOrEnv(config, "elasticsearch.node.name"); if (nodeName != null) { settings.put("node.name", nodeName); } Iterable<String> unicastHosts = ConfigHelper.getArrayFieldOrEnv(config, "elasticsearch.discovery.zen.ping.unicast.hosts", new String[] {}); settings.put("discovery.zen.ping.multicast.enabled", ConfigHelper.getFieldOrEnv(config, "elasticsearch.discovery.zen.ping.multicast.enabled", "true")); settings.put("discovery.zen.ping.unicast.enabled", ConfigHelper.getFieldOrEnv(config, "elasticsearch.discovery.zen.ping.unicast.enabled", "false")); settings.put("discovery.zen.ping.unicast.hosts", Joiner.on(',').join(unicastHosts)); settings.put("client.transport.sniff", "true"); Iterable<InetSocketTransportAddress> transports = FluentIterable.from(unicastHosts) .filter(Predicates.notNull()).transform(HostAndPort::fromString) .transform(input -> { try { return new InetSocketTransportAddress( InetAddress.getByName(input.getHostText()), input.getPortOrDefault(9300)); } catch (UnknownHostException e) { throw new RuntimeException(e); } }); TransportClient transportClient = TransportClient.builder().settings(settings).build(); for (InetSocketTransportAddress transportAddress : transports) { transportClient.addTransportAddress(transportAddress); } elasticSearchClient = transportClient; } catch (Exception e) { throw new RuntimeException(e); } } return null; })).flatMap(aVoid -> waitForGreen(vertxContext)) .flatMap(aVoid -> prepareCommonIndex(vertxContext, isMasterNode)) .doOnNext(aVoid -> Preconditions.checkState(status.compareAndSet(Status.STARTING, Status.STARTED))) .doOnNext(aVoid -> LOGGER.debug("Started Elasticsearch")); }
From source file:es.uah.aut.srg.micobs.xtext.MICOBSAbstractScopeProvider.java
/** * Returns a scope from a collection of model referenceable objects and including * a parent scope.//from ww w. j a va 2s . c o m * * The description of the objects is their name, prefixed by all the list of * containing objects up to the container element's name but without including it. * * @param elements the collection of referenceable objects to be included * in the scope. * @param parentScope the parent scope. * @return the scope from the collection of elements. */ public IScope getRelativeObjectScope(final Collection<? extends MCommonReferenceableObj> elements, IScope parentScope) { if (elements.isEmpty()) { return parentScope; } Iterable<IEObjectDescription> fullQN = Iterables.transform(elements, new Function<MCommonReferenceableObj, IEObjectDescription>() { @Override public IEObjectDescription apply(MCommonReferenceableObj from) { String name = MICOBSStringHelper.getInstance().getPartialObjectNameToElement(from, 0); if (name == null) { return null; } return EObjectDescription.create(qualifiedNameConverter.toQualifiedName(name), from); } }); return new SimpleScope(parentScope, Iterables.filter(fullQN, Predicates.notNull())); }