List of usage examples for com.google.common.base Predicates notNull
@GwtCompatible(serializable = true) public static <T> Predicate<T> notNull()
From source file:com.greensopinion.finance.services.transaction.OfxTransactionReader.java
public List<Transaction> transactions() { List<Transaction> transactions = new ArrayList<>(); try {/*w w w. j a v a 2 s. c o m*/ readHeader(); try (SgmlReader sgmlReader = new SgmlReader(reader)) { String accountNumber = null; Token token; while ((token = sgmlReader.readToken()) != null) { if (token.getType() == TokenType.OPEN_TAG) { if (TAG_BANKACCTFROM.equals(token.getValue()) || TAG_CCACCTFROM.equals(token.getValue())) { accountNumber = readAccountNumber(sgmlReader, token.getValue()); } else if (STMTTRN.equals(token.getValue())) { transactions.add(readTransaction(sgmlReader, token.getValue(), accountNumber)); } } } } } catch (IOException e) { throw Throwables.propagate(e); } return FluentIterable.from(transactions).filter(Predicates.notNull()).toList(); }
From source file:edu.harvard.med.iccbl.screensaver.service.screens.IccblScreenFacilityIdInitializer.java
public boolean updateIdentifierForPrimaryScreen(Screen screen) { List<Screen> screens = _dao.findAllEntitiesOfType(Screen.class, true); Iterable<Integer> primaryScreenNumericFacilityIds = Iterables .filter(Iterables.transform(Iterables.filter(screens, ScreenWithFacilityId), Functions.compose(NonStrictStringToInteger, Screen.ToFacilityId)), Predicates.notNull()); int nextId = 1; if (primaryScreenNumericFacilityIds.iterator().hasNext()) { Integer maxNumericFacilityId = Ordering.natural().max(primaryScreenNumericFacilityIds); nextId += maxNumericFacilityId;/* ww w. j av a2s.c om*/ } String nextPrimaryScreenFacilityIdentifier = Integer.toString(nextId); screen.setFacilityId(nextPrimaryScreenFacilityIdentifier); log.info("set new primary screen facility ID to " + nextPrimaryScreenFacilityIdentifier); return true; }
From source file:com.google.api.server.spi.request.Auth.java
@VisibleForTesting Iterable<Authenticator> getAuthenticatorInstances() { List<Class<? extends Authenticator>> classes = config.getAuthenticators(); return classes == null ? ImmutableList.of(DEFAULT_AUTHENTICATOR) : Iterables.filter(Iterables.transform(classes, INSTANTIATE_AUTHENTICATOR), Predicates.notNull()); }
From source file:org.eclipse.sirius.business.internal.movida.VSMResolver.java
/** * Resolves a set of logical Sirius URIs into the set of physical URIs of * all the resources required to provide these viewpoints, including their * dependencies.//ww w. j av a2s .co m * * @param logicalURIs * the set of logical Sirius URIs to resolve. * @return the physical URIs of all the resources which must be loaded to * provide all the specified viewpoints. * @throws IllegalArgumentException * if some of the (directly or indirectly) required viewpoints * can not be resolved into a physical resource. */ public Set<URI> resolve(Set<URI> logicalURIs) throws IllegalArgumentException { Preconditions.checkNotNull(logicalURIs); Set<URI> allLogical = computeAllLogicalRequirements(logicalURIs); final Set<URI> missing = Sets.newHashSet(); Iterable<URI> allPhysical = Iterables.transform(allLogical, new Function<URI, URI>() { @Override public URI apply(URI from) { Option<URI> provider = registry.getProvider(from); if (provider.some()) { return provider.get(); } else { missing.add(from); return null; } } }); if (!missing.isEmpty()) { String msg = MessageFormat.format( "Some of the required logical Sirius URIs could not be resolved to physical resources: {0}.", //$NON-NLS-1$ Joiner.on(", ").join(missing)); //$NON-NLS-1$ throw new IllegalArgumentException(msg); } else { return ImmutableSet.copyOf(Iterables.filter(allPhysical, Predicates.notNull())); } }
From source file:todoapp.fixture.module.security.UserRolesFixtureScript.java
@Override protected void execute(ExecutionContext ec) { // required//ww w . ja va 2s . c o m final String username = Util.coalesce(ec.getParameter("username"), getUsername()); if (username == null) { throw new IllegalArgumentException("username is required"); } // validate user this.applicationUser = applicationUserRepository.findByUsername(username); if (this.applicationUser == null) { throw new IllegalArgumentException(String.format("No user with username: '%s'", username)); } // no defaults for roles // validate all roleNames this.applicationRoles = Lists.newArrayList( Iterables.filter(Iterables.transform(getRoleNames(), roleNameToRole()), Predicates.notNull())); List<ApplicationRole> applicationRoleList = this.applicationRoles; List<String> roleNames = getRoleNames(); if (applicationRoleList.size() != roleNames.size()) { throw new IllegalArgumentException("One or more roles not found"); } // execute ec.addResult(this, applicationUser.getName(), this.applicationUser); for (ApplicationRole applicationRole : this.applicationRoles) { if (applicationRole != null) { this.applicationUser.addRole(applicationRole); ec.addResult(this, applicationRole.getName(), applicationRole); } } }
From source file:org.opensaml.saml.metadata.resolver.filter.MetadataFilterChain.java
/** * Set the list of {@link MetadataFilter}s that make up this chain. * //from ww w . j a v a 2 s .c o m * @param newFilters list of {@link MetadataFilter}s that make up this chain */ public void setFilters(@Nonnull @NonnullElements final List<MetadataFilter> newFilters) { Constraint.isNotNull(newFilters, "Filter collection cannot be null"); filters = new ArrayList<>(Collections2.filter(newFilters, Predicates.notNull())); }
From source file:com.facebook.buck.java.JavaLibraryClasspathProvider.java
private static FluentIterable<JavaLibrary> getJavaLibraryDeps(Iterable<BuildRule> deps) { return FluentIterable.from(deps).transform(new Function<BuildRule, JavaLibrary>() { @Nullable/*from ww w. j a v a 2 s .c om*/ @Override public JavaLibrary apply(BuildRule input) { if (input.getBuildable() instanceof JavaLibrary) { return (JavaLibrary) input.getBuildable(); } if (input instanceof JavaLibrary) { return (JavaLibrary) input; } return null; } }).filter(Predicates.notNull()); }
From source file:com.google.gerrit.server.extensions.webui.UiCommands.java
public static <R extends RestResource> Iterable<UiCommandDetail> from(DynamicMap<RestView<R>> views, final R resource, final EnumSet<UiCommand.Place> places) { return Iterables .filter(Iterables.transform(views, new Function<DynamicMap.Entry<RestView<R>>, UiCommandDetail>() { @Override// w w w.j ava 2 s .c o m @Nullable public UiCommandDetail apply(DynamicMap.Entry<RestView<R>> e) { int d = e.getExportName().indexOf('.'); if (d < 0) { return null; } String method = e.getExportName().substring(0, d); String name = e.getExportName().substring(d + 1); RestView<R> view; try { view = e.getProvider().get(); } catch (RuntimeException err) { log.error(String.format("error creating view %s.%s", e.getPluginName(), e.getExportName()), err); return null; } if (!(view instanceof UiCommand)) { return null; } UiCommand<R> cmd = (UiCommand<R>) view; if (Sets.intersection(cmd.getPlaces(), places).isEmpty() || !cmd.isVisible(resource)) { return null; } UiCommandDetail dsc = new UiCommandDetail(); dsc.id = e.getPluginName() + '~' + name; dsc.method = method; dsc.label = cmd.getLabel(resource); dsc.title = cmd.getTitle(resource); dsc.enabled = cmd.isEnabled(resource); dsc.confirmationMessage = cmd.getConfirmationMessage(resource); return dsc; } }), Predicates.notNull()); }
From source file:org.opensaml.saml.common.profile.impl.ChainingNameIdentifierGenerator.java
/** * Set the format-specific generators to use. * //from w ww . j a va 2 s . c o m * <p>Only generators that support the {@link FormatSpecificNameIdentifierGenerator} interface are * installed, and the generators are prioritized for a given format by the order they are supplied.</p> * * @param generators generators to use */ public void setGenerators(@Nonnull @NullableElements List<NameIdentifierGenerator<NameIdType>> generators) { Constraint.isNotNull(generators, "NameIdentifierGenerator list cannot be null"); nameIdGeneratorMap.clear(); for (final NameIdentifierGenerator<NameIdType> generator : Collections2.filter(generators, Predicates.notNull())) { if (generator instanceof FormatSpecificNameIdentifierGenerator) { nameIdGeneratorMap.put(((FormatSpecificNameIdentifierGenerator<NameIdType>) generator).getFormat(), generator); } else { log.warn("Unable to install NameIdentifierGenerator of type {}, not format-specific", generator.getClass().getName()); } } }
From source file:org.opensaml.core.xml.util.XMLObjectChildrenList.java
/** * Constructs a list containing the elements in the specified collection, in the order they are returned by the * collection's iterator, with each added XMLObject assigned the given parent XMLObject. * /*from w ww.j a va2 s .c o m*/ * <p>An IllegalArgumentException is thrown if any of the XMLObjects in the given collection already have a parent * other than the given parent * * @param newParent the parent for all the added XMLObjects * @param newElements the elements to be added */ public XMLObjectChildrenList(@Nonnull final XMLObject newParent, @Nonnull final Collection<ElementType> newElements) { Constraint.isNotNull(newParent, "Parent cannot be null"); Constraint.isNotNull(newElements, "Initial collection cannot be null"); parent = newParent; elements = new LazyList<>(); // This does call our add, which handles the null case properly, but // I didn't want to depend on that implementation. Keeping the fail silently // behavior means not using an Immutable collection copy. addAll(Collections2.filter(newElements, Predicates.notNull())); }