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:io.hops.transaction.context.BaseEntityContext.java

final Collection<Entity> getRemoved() {
    Collection<Entity> entities = Maps.transformValues(contextEntities, new Function<ContextEntity, Entity>() {
        @Override//from w  w  w .  j ava2 s . c o  m
        public Entity apply(ContextEntity input) {
            if (input.getState() == State.REMOVED && input.firstState != State.ADDED) {
                return input.getEntity();
            }
            return null;
        }
    }).values();
    return Collections2.filter(entities, Predicates.notNull());
}

From source file:net.shibboleth.idp.authn.impl.RemoteUserAuthServlet.java

/**
 * Set the list of request attributes to check for an identity.
 * //ww  w  . ja v a  2  s . co m
 * @param attributes    list of request attributes to check
 */
public void setCheckAttributes(@Nonnull @NonnullElements final Collection<String> attributes) {
    checkAttributes = new ArrayList<>(Collections2.filter(attributes, Predicates.notNull()));
}

From source file:net.pterodactylus.sone.data.AlbumImpl.java

@Override
public List<Image> getImages() {
    return new ArrayList<Image>(
            Collections2.filter(Collections2.transform(imageIds, new Function<String, Image>() {

                @Override/*from   w w  w.  j a v a  2 s.  c om*/
                @SuppressWarnings("synthetic-access")
                public Image apply(String imageId) {
                    return images.get(imageId);
                }
            }), Predicates.notNull()));
}

From source file:de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowsLoader.java

public PricingConditionsRowData load() {
    final Set<PricingConditionsId> pricingConditionsIds = getAllPricingConditionsId();

    final List<PricingConditionsRow> rows = pricingConditionsRepo
            .getPricingConditionsByIds(pricingConditionsIds).stream()
            .flatMap(pricingConditionsBreaksExtractor::streamPricingConditionsBreaks)
            .filter(Predicates.notNull()).flatMap(this::createPricingConditionsRows).sorted(ROWS_SORTING)
            .collect(ImmutableList.toImmutableList());

    final PricingConditionsRow editableRow = rows.stream().filter(this::isCurrentConditions).findFirst()
            .map(PricingConditionsRow::copyAndChangeToEditable)
            .orElseGet(this::createEditablePricingConditionsRowOrNull);

    return PricingConditionsRowData.builder().editableRow(editableRow).rows(rows)
            .orderLineId(sourceDocumentLine != null ? sourceDocumentLine.getOrderLineId() : null).build()
            .filter(filters);//from   w  ww  .  j  av  a  2  s.c o m
}

From source file:de.metas.ui.web.order.products_proposal.model.ProductsProposalRowsLoader.java

private Stream<ProductsProposalRow> loadAndStreamRowsForPriceListVersionId(
        final PriceListVersionId priceListVersionId) {
    final String currencyCode = getCurrencyCodeByPriceListVersionId(priceListVersionId);

    return priceListsRepo.retrieveProductPrices(priceListVersionId, productIdsToExclude)
            .map(productPriceRecord -> toProductsProposalRowOrNull(productPriceRecord, currencyCode))
            .filter(Predicates.notNull());
}

From source file:us.eharning.atomun.mnemonic.spi.bip0039.BIP0039MnemonicUtility.java

/**
 * Utility method to retrieve all known dictionaries.
 *
 * @return iterable that contains known dictionaries.
 *//*ww  w .  j  a  v  a  2 s.  c  o  m*/
@Nonnull
static Iterable<BidirectionalDictionary> getDictionaries() {
    Iterable<BidirectionalDictionary> dictionaryIterable = Iterables.transform(KNOWN_DICTIONARIES,
            new Function<String, BidirectionalDictionary>() {
                @Nullable
                @Override
                public BidirectionalDictionary apply(String input) {
                    if (null == input) {
                        return null;
                    }
                    try {
                        return getDictionary(input);
                    } catch (Throwable ignored) {
                        return null;
                    }
                }
            });
    /* Filter out any missing dictionaries */
    dictionaryIterable = Iterables.filter(dictionaryIterable, Predicates.notNull());
    return dictionaryIterable;
}

From source file:com.eucalyptus.tags.TagManager.java

public CreateTagsResponseType createTags(final CreateTagsType request) throws EucalyptusCloudException {
    final CreateTagsResponseType reply = request.getReply();
    reply.set_return(false);

    final Context context = Contexts.lookup();
    final UserFullName userFullName = context.getUserFullName();
    final AccountFullName accountFullName = userFullName.asAccountFullName();
    final List<String> resourceIds = Objects.firstNonNull(request.getResourcesSet(),
            Collections.<String>emptyList());
    final List<ResourceTag> resourceTags = Objects.firstNonNull(request.getTagSet(),
            Collections.<ResourceTag>emptyList());

    for (final ResourceTag resourceTag : resourceTags) {
        final String key = resourceTag.getKey();
        final String value = Strings.nullToEmpty(resourceTag.getValue()).trim();

        if (Strings.isNullOrEmpty(key) || key.trim().length() > 128 || isReserved(key)) {
            throw new InvalidParameterValueException(
                    "Invalid key (max length 128, must not be empty, reserved prefixes " + reservedPrefixes
                            + "): " + key);
        }/*w  ww  . j av  a  2 s .c  om*/
        if (value.length() > 256 || isReserved(key)) {
            throw new InvalidParameterValueException(
                    "Invalid value (max length 256, reserved prefixes " + reservedPrefixes + "): " + value);
        }
    }

    if (resourceTags.size() > 0 && resourceIds.size() > 0) {
        final Predicate<Void> creator = new Predicate<Void>() {
            @Override
            public boolean apply(final Void v) {
                final List<CloudMetadata> resources = Lists.transform(resourceIds, resourceLookup(true));
                if (!Iterables.all(resources,
                        Predicates.and(Predicates.notNull(), typeSpecificFilters(), permissionsFilter()))) {
                    return false;
                }

                for (final CloudMetadata resource : resources) {
                    for (final ResourceTag resourceTag : resourceTags) {
                        final String key = Strings.nullToEmpty(resourceTag.getKey()).trim();
                        final String value = Strings.nullToEmpty(resourceTag.getValue()).trim();
                        TagSupport.fromResource(resource).createOrUpdate(resource, userFullName, key, value);
                    }

                    if (TagSupport.fromResource(resource).count(resource,
                            accountFullName) > MAX_TAGS_PER_RESOURCE) {
                        throw new TagLimitException();
                    }
                }

                return true;
            }
        };

        try {
            reply.set_return(Entities.asTransaction(Tag.class, creator).apply(null));
        } catch (TagLimitException e) {
            throw new TagLimitExceededException();
        } catch (RuntimeException e) {
            handleException(e);
        }
    }

    return reply;
}

From source file:org.eclipse.sirius.diagram.ui.edit.internal.part.listener.VisibilityPostCommitListener.java

private Set<View> getElementsWhoseVisibilityChanged(ResourceSetChangeEvent event) {
    Iterable<Notification> changes = getVisibilityChanges(event);
    Set<View> result = Sets
            .newHashSet(Iterables.filter(Iterables.transform(changes, new Function<Notification, View>() {
                public View apply(Notification from) {
                    if (from.getNotifier() instanceof View) {
                        return (View) from.getNotifier();
                    } else {
                        return null;
                    }/*from ww w .java  2s  .c  o  m*/
                }
            }), Predicates.notNull()));
    return result;
}

From source file:gg.uhc.uhc.modules.team.RandomTeamsCommand.java

@Override
protected boolean runCommand(CommandSender sender, OptionSet options) {
    int size = -1;
    int count = -1;

    if (options.has(teamCountSpec)) {
        count = teamCountSpec.value(options);
    }/*from w w  w.  j  a  v a2 s. co m*/

    if (options.has(teamSizeSpec)) {
        size = teamSizeSpec.value(options);
    }

    if ((size == -1 && count == -1) || (size != -1 && count != -1)) {
        sender.sendMessage(messages.getRaw("count or size"));
        return true;
    }

    Set<Player> choice = Sets.newHashSet(playersSpec.values(options));

    // if none are provided then add all online players
    if (choice.size() == 0) {
        choice = Sets.newHashSet(Bukkit.getOnlinePlayers());
    }

    // parse excludes into online players
    Set<Player> excludes = Sets.newHashSet(
            Iterables.filter(Iterables.transform(excludingSpec.values(options), FunctionalUtil.ONLINE_VERSION),
                    Predicates.notNull()));

    // final list with excludes removed and players that already in a team
    List<Player> toAssign = Lists
            .newArrayList(Iterables.filter(Sets.difference(choice, excludes), Predicates.not(PLAYER_HAS_TEAM)));

    if (toAssign.size() == 0) {
        sender.sendMessage(messages.getRaw("no players"));
        return true;
    }

    Collections.shuffle(toAssign);

    // calculate team sizes to fit in count teams and assign it to size and carry on as if it was a sized command
    if (count != -1) {
        size = (int) Math.ceil((double) toAssign.size() / (double) count);
    }

    // partition into teams
    List<List<Player>> teams = Lists.newArrayList(Lists.partition(toAssign, size));

    int extras = toAssign.size() % size;

    // if we're excluding leftovers and there were leftovers in a final
    // team, then remove that team from the list. If it's the only team
    // then send a message saying no teams could be created.
    if (options.has(excludeExtrasSpec) && extras > 0) {
        if (teams.size() == 1) {
            sender.sendMessage(messages.evalTemplate("not enough players", ImmutableMap.of("size", size)));
            return true;
        }

        teams.remove(teams.size() - 1);
    }

    // start assigning teams
    for (List<Player> teamPlayers : teams) {
        Optional<Team> optional = module.findFirstEmptyTeam();

        if (!optional.isPresent()) {
            sender.sendMessage(messages.getRaw("not enough teams"));
            return true;
        }

        Team team = optional.get();
        String playerNames = Joiner.on(", ")
                .join(Iterables.transform(teamPlayers, FunctionalUtil.PLAYER_NAME_FETCHER));

        //"teamup notification" : ${colours.command}"You were teamed up into the team {{prefix}}{{name}}"${colours.reset}${colours.command}" with: "${colours.secondary}"{{players}}";

        Map<String, String> context = ImmutableMap.<String, String>builder().put("prefix", team.getPrefix())
                .put("name", team.getName()).put("display name", team.getDisplayName())
                .put("players", playerNames).build();

        String message = messages.evalTemplate("teamup notification", context);

        // add each player
        for (Player player : teamPlayers) {
            team.addPlayer(player);
            player.sendMessage(message);
        }
    }

    Map<String, Integer> context = ImmutableMap.<String, Integer>builder().put("count", teams.size())
            .put("size", teams.get(0).size()).put("players", toAssign.size()).build();

    sender.sendMessage(messages.evalTemplate("created", context));

    if (options.has(excludeExtrasSpec) && extras > 0) {
        sender.sendMessage(messages.evalTemplate("extras notice", ImmutableMap.of("extras", extras)));
    }

    return true;
}

From source file:com.tinspx.util.net.Headers.java

private ListMultimap<String, String> view() {
    if (view == null) {
        view = Predicated.listMultimap(Listenable.listMultimap(headers, true, new Listenable.Modification() {
            @Override//  w ww. j ava2  s. co  m
            public void onModify(Object src, Listenable.Event type) {
                rebuildCanons = true;
                rebuildHeaders = true;
            }
        }), Predicates.notNull(), Predicates.notNull(), true);
    }
    return view;
}