Example usage for com.google.common.base Predicates notNull

List of usage examples for com.google.common.base Predicates notNull

Introduction

In this page you can find the example usage for com.google.common.base Predicates notNull.

Prototype

@GwtCompatible(serializable = true)
public static <T> Predicate<T> notNull() 

Source Link

Document

Returns a predicate that evaluates to true if the object reference being tested is not null.

Usage

From source file:net.shibboleth.idp.relyingparty.impl.DefaultRelyingPartyConfigurationResolver.java

/**
 * Set the verified relying party configurations.
 * /*from www  .ja va 2  s  . c  om*/
 * @param configs list of verified relying party configurations
 */
public void setRelyingPartyConfigurations(
        @Nonnull @NonnullElements final List<RelyingPartyConfiguration> configs) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    Constraint.isNotNull(configs, "RelyingPartyConfiguration list cannot be null");

    rpConfigurations = new ArrayList<>(Collections2.filter(configs, Predicates.notNull()));
}

From source file:org.mayocat.context.RequestContextInitializer.java

public void requestInitialized(ServletRequestEvent servletRequestEvent) {
    if (isStaticPath(this.getRequestURI(servletRequestEvent))) {
        return;/*from   w w  w  .  ja va  2 s. c o m*/
    }

    DefaultWebRequestBuilder requestBuilder = new DefaultWebRequestBuilder();

    // 1. Tenant

    String host = getHost(servletRequestEvent);
    String path = getPath(servletRequestEvent);

    Tenant tenant = this.tenantResolver.get().resolve(host, path);
    DefaultWebContext context = new DefaultWebContext(tenant, null);

    // Set the context in the context already, even if we haven't figured out if there is a valid user yet.
    // The context tenant is actually needed to find out the context user and to initialize tenant configurations
    ((ThreadLocalWebContext) this.context).setContext(context);

    if (tenant != null) {
        requestBuilder.tenantRequest(true);
        if (path.indexOf("/tenant/" + tenant.getSlug()) == 0) {
            path = StringUtils.substringAfter(path, "/tenant/" + tenant.getSlug());
            requestBuilder.tenantPrefix("/tenant/" + tenant.getSlug());
        }
    } else {
        requestBuilder.tenantRequest(false);
    }

    requestBuilder.apiRequest(path.indexOf("/api/") == 0);

    // 2. Configurations

    Map<Class, Serializable> configurations = configurationService.getSettings();
    context.setSettings(configurations);

    // 3. User

    Optional<User> user = Optional.absent();
    for (String headerName : Lists.newArrayList("Authorization", "Cookie")) {
        final String headerValue = Strings.nullToEmpty(this.getHeaderValue(servletRequestEvent, headerName));
        for (Authenticator authenticator : this.authenticators.values()) {
            if (authenticator.respondTo(headerName, headerValue)) {
                user = authenticator.verify(headerValue, tenant);
            }
        }
    }

    context.setUser(user.orNull());

    if (tenant != null) {
        // 4. ThemeDefinition
        context.setTheme(themeManager.getTheme());
    }
    // 5. Locale
    LocalesSettings localesSettings = configurationService.getSettings(GeneralSettings.class).getLocales();
    boolean localeSet = false;
    List<Locale> alternativeLocales = FluentIterable.from(localesSettings.getOtherLocales().getValue())
            .filter(Predicates.notNull()).toList();

    String canonicalPath = path;
    if (!alternativeLocales.isEmpty()) {
        for (Locale locale : alternativeLocales) {
            List<String> fragments = ImmutableList.copyOf(
                    Collections2.filter(Arrays.asList(path.split("/")), Predicates.not(IS_NULL_OR_BLANK)));
            if (fragments.size() > 0 && fragments.get(0).equals(locale.toLanguageTag())) {
                context.setLocale(locale);
                context.setAlternativeLocale(true);
                canonicalPath = StringUtils.substringAfter(canonicalPath, "/" + locale);
                localeSet = true;
                break;
            }
        }
    }
    if (!localeSet) {
        context.setLocale(localesSettings.getMainLocale().getValue());
        context.setAlternativeLocale(false);
    }

    if (context.isAlternativeLocale()) {
        path = StringUtils.substringAfter(path, context.getLocale().toLanguageTag());
    }

    // 6. Request
    Optional<Breakpoint> breakpoint = this.breakpointDetector.getBreakpoint(getUserAgent(servletRequestEvent));

    requestBuilder.baseURI(getBaseURI(servletRequestEvent)).canonicalPath(canonicalPath).path(path)
            .breakpoint(breakpoint);

    requestBuilder.secure(isSecure(servletRequestEvent));

    context.setRequest(requestBuilder.build());
}

From source file:net.shibboleth.idp.saml.nameid.impl.PersistentSAML2NameIDGenerator.java

/**
 * Set the attribute sources to pull from.
 * //from   w ww  . j  a  v a2  s  .  com
 * @param ids attribute IDs to pull from
 */
public void setAttributeSourceIds(@Nonnull @NonnullElements final List<String> ids) {
    ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
    Constraint.isNotNull(ids, "Attribute ID collection cannot be null");

    attributeSourceIds = new ArrayList<>(Collections2.filter(ids, Predicates.notNull()));
}

From source file:org.apache.cassandra.io.LazilyCompactedRow.java

public Iterator<IColumn> iterator() {
    for (SSTableIdentityIterator row : rows) {
        row.reset();/*from   w w  w  . j av a2s .co  m*/
    }
    iter = new LazyColumnIterator(new CollatingIterator(getComparator().columnComparator, rows));
    return Iterators.filter(iter, Predicates.notNull());
}

From source file:org.mitre.oauth2.service.impl.DefaultSystemScopeService.java

@Override
public Set<SystemScope> fromStrings(Set<String> scope) {
    if (scope == null) {
        return null;
    } else {// ww w .  j a  v  a 2 s  .c  om
        return new LinkedHashSet<SystemScope>(
                Collections2.filter(Collections2.transform(scope, stringToSystemScope), Predicates.notNull()));
    }
}

From source file:net.shibboleth.idp.attribute.resolver.spring.dc.impl.DataConnectorFactoryBean.java

/**
 * Set the list of bean post processors for this connector.
 * //from   w w  w  .  j  a  v  a  2 s . c om
 * @param processors bean post processors to apply
 */
public void setBeanPostProcessors(@Nonnull @NonnullElements final List<BeanPostProcessor> processors) {
    postProcessors = Lists.newArrayList(Collections2.filter(processors, Predicates.notNull()));
}

From source file:de.metas.ui.web.handlingunits.HUEditorRowsPagedLoadingIterator.java

private Iterator<HUEditorRow> getNextPageIterator() {
    // the result; part of it will be taken from cache, the, rest will be loaded
    final HUEditorRow[] rows = new HUEditorRow[bufferSize];

    // HUEditorRowIds that we don't have in the cache and that therefore need to be loaded
    final Map<HUEditorRowId, Integer> rowIdToLoad2index = new HashMap<>();

    // Get from cache as much as possible
    {/* www.jav  a  2  s.com*/
        int idx = 0;
        while (rowIds.hasNext() && idx < bufferSize) {
            final HUEditorRowId rowId = rowIds.next();

            final HUEditorRowId topLevelRowId = rowId.toTopLevelRowId();
            final HUEditorRow topLevelRow = cache.get(topLevelRowId.toDocumentId());

            if (topLevelRow == null) {
                // to be loaded
                rowIdToLoad2index.put(rowId, idx);
            } else {
                if (rowId.equals(topLevelRowId)) {
                    rows[idx] = topLevelRow;
                } else {
                    rows[idx] = topLevelRow.getIncludedRowById(rowId.toDocumentId()).orElse(null);
                }
            }

            idx++;
        }
    }

    //
    // Load missing rows (which were not found in cache)
    if (!rowIdToLoad2index.isEmpty()) {
        final ListMultimap<HUEditorRowId, HUEditorRowId> topLevelRowId2rowIds = rowIdToLoad2index.keySet()
                .stream().map(rowId -> GuavaCollectors.entry(rowId.toTopLevelRowId(), rowId))
                .collect(GuavaCollectors.toImmutableListMultimap());

        final Set<HuId> topLevelHUIds = topLevelRowId2rowIds.keys().stream().map(HUEditorRowId::getTopLevelHUId)
                .collect(ImmutableSet.toImmutableSet());

        huEditorRepo.retrieveHUEditorRows(topLevelHUIds, filter).forEach(topLevelRow -> {
            final HUEditorRowId topLevelRowId = topLevelRow.getHURowId();
            for (final HUEditorRowId includedRowId : topLevelRowId2rowIds.get(topLevelRowId)) {
                final Integer idx = rowIdToLoad2index.remove(includedRowId);
                if (idx == null) {
                    // wtf?! shall not happen
                    continue;
                }

                if (topLevelRowId.equals(includedRowId)) {
                    rows[idx] = topLevelRow;
                    cache.put(topLevelRow.getId(), topLevelRow);
                } else {
                    rows[idx] = topLevelRow.getIncludedRowById(includedRowId.toDocumentId()).orElse(null);
                }
            }
        });
    }

    return Stream.of(rows).filter(Predicates.notNull()) // IMPORTANT: just to make sure we won't stream some empty gaps (e.g. missing rows because HU was not a top level one)
            .filter(filterPredicate).iterator();
}

From source file:blue.lapis.pore.converter.data.block.type.BTDCTestUtil.java

@SuppressWarnings({ "deprecation", "unchecked" })
public static void testDeabstraction(BlockType blockType, byte rawData,
        Collection<? extends AbstractDataValue<? extends DataManipulator, ?>> abstractedData, boolean invert)
        throws Exception {
    Location loc = new Location(mock(Extent.class), 0, 0, 0);
    when(loc.getBlockType()).thenReturn(blockType);
    /*for (AbstractDataValue datum : abstractedData) {
    DataManipulator<?> spongeDatum = datum.getValue() != AbstractDataValue.ABSENT
            ? (DataManipulator<?>) mock(datum.getDataClass()) : null;
    if (spongeDatum instanceof SingleValueData) {
        when(((SingleValueData) spongeDatum).getValue()).thenReturn(datum.getValue());
    }//www  .  j av  a 2 s .com
    when(loc.getData((Class<DataManipulator>) datum.getDataClass()))
            .thenReturn(Optional.<DataManipulator>fromNullable(spongeDatum));
    }*/
    Collection<DataManipulator<?, ?>> manipulators = FluentIterable.from(abstractedData)
            .transform(new Function<AbstractDataValue<? extends DataManipulator, ?>, DataManipulator<?, ?>>() {
                public DataManipulator<?, ?> apply(AbstractDataValue datum) {
                    if (datum.getValue() == AbstractDataValue.ABSENT) {
                        return null;
                    }
                    DataManipulator<?, ?> dm = (DataManipulator<?, ?>) mock(datum.getDataClass());
                    if (dm instanceof VariantData) {
                        Value value = mock(Value.class);
                        when(value.get()).thenReturn(datum.getValue());
                        when(((VariantData) dm).type()).thenReturn(value);
                    }
                    return dm;
                }
            }).filter(Predicates.notNull()).toList();
    when(loc.getContainers()).thenReturn(manipulators);
    Block block = PoreBlock.of(loc);
    if (invert) {
        assertNotEquals((long) rawData, (long) block.getData());
    } else {
        assertEquals(rawData, block.getData());
    }
}

From source file:org.eclipse.sirius.editor.tools.internal.presentation.ViewpoitnDependenciesSelectionDialog.java

private List<URI> getAvailableViewpointsURIs() {
    return Lists.newArrayList(Iterables.filter(Iterables
            .transform(ViewpointRegistry.getInstance().getViewpoints(), new Function<Viewpoint, URI>() {
                public URI apply(Viewpoint from) {
                    Option<URI> uri = new ViewpointQuery(from).getViewpointURI();
                    if (uri.some()) {
                        return uri.get();
                    } else {
                        return null;
                    }/*from w w w  .  ja  va2  s .c om*/
                }
            }), Predicates.notNull()));
}

From source file:fr.javatronic.damapping.intellij.plugin.integration.psiparsing.impl.DANameExtractorImpl.java

@Override
@Nullable//from  w  ww  . j a v  a 2s  .  com
public DAName qualifiedName(@Nonnull final String name, @Nullable PsiContext psiContext) {
    if (isQualified(name)) {
        return DANameFactory.from(name);
    }

    if (psiContext == null) {
        return null;
    }

    Optional<DAName> foundImport = from(Arrays.asList(psiContext.getImportStatements()))
            .filter(new Predicate<PsiImportStatement>() {
                @Override
                public boolean apply(@Nullable PsiImportStatement psiImportStatement) {
                    return psiImportStatement != null && psiImportStatement.getQualifiedName() != null
                            && psiImportStatement.getQualifiedName().endsWith(name);
                }
            }).transform(new Function<PsiImportStatement, DAName>() {
                @Nullable
                @Override
                public DAName apply(@Nullable PsiImportStatement psiImportStatement) {
                    if (psiImportStatement == null || psiImportStatement.getQualifiedName() == null) {
                        return null;
                    }
                    return DANameFactory.from(psiImportStatement.getQualifiedName());
                }
            }).filter(Predicates.notNull()).first();
    if (foundImport.isPresent()) {
        return foundImport.get();
    }
    return null;
}