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

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

Introduction

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

Prototype

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

Source Link

Document

Returns a predicate that always evaluates to true .

Usage

From source file:org.apache.brooklyn.enricher.stock.AbstractAggregator.java

@SuppressWarnings({ "unchecked" })
protected void setEntityLoadingConfig() {
    this.producer = getConfig(PRODUCER);
    this.fromHardcodedProducers = getConfig(FROM_HARDCODED_PRODUCERS);
    this.defaultMemberValue = (T) getConfig(DEFAULT_MEMBER_VALUE);
    this.fromMembers = Maybe.fromNullable(getConfig(FROM_MEMBERS)).or(fromMembers);
    this.fromChildren = Maybe.fromNullable(getConfig(FROM_CHILDREN)).or(fromChildren);
    this.entityFilter = (Predicate<? super Entity>) (getConfig(ENTITY_FILTER) == null ? Predicates.alwaysTrue()
            : getConfig(ENTITY_FILTER));
    this.valueFilter = (Predicate<? super T>) (getConfig(VALUE_FILTER) == null ? getDefaultValueFilter()
            : getConfig(VALUE_FILTER));//from  w  ww .  j  av a  2  s .  co  m

    setEntityLoadingTargetConfig();
}

From source file:org.jclouds.vcloud.config.DefaultVCloudReferencesModule.java

@Provides
@Singleton
@org.jclouds.vcloud.endpoints.Network
protected Predicate<ReferenceType> provideDefaultNetworkSelector(Injector i) {
    return Predicates.alwaysTrue();
}

From source file:omero.cmd.graphs.ChildOptionI.java

/**
 * Initialize this child option instance.
 * An option takes effect according to the {@link ChildOption} field values set when this method was last called.
 */// ww  w. j  ava  2  s  .c o  m
public void init() {
    /* convert the class names to actual classes */

    final Function<String, Class<? extends IObject>> getClassFromName = new Function<String, Class<? extends IObject>>() {
        @Override
        public Class<? extends IObject> apply(String className) {
            final int lastDot = className.lastIndexOf('.');
            if (lastDot > 0) {
                className = className.substring(lastDot + 1);
            }
            return graphPathBean.getClassForSimpleName(className);
        }
    };

    /* construct the function corresponding to the type-based inclusion requirements */

    final ImmutableSet<Class<? extends IObject>> typeInclusions;
    final ImmutableSet<Class<? extends IObject>> typeExclusions;

    if (CollectionUtils.isEmpty(includeType)) {
        typeInclusions = ImmutableSet.of();
    } else {
        typeInclusions = ImmutableSet.copyOf(Collections2.transform(includeType, getClassFromName));
    }
    if (CollectionUtils.isEmpty(excludeType)) {
        typeExclusions = ImmutableSet.of();
    } else {
        typeExclusions = ImmutableSet.copyOf(Collections2.transform(excludeType, getClassFromName));
    }

    if (typeInclusions.isEmpty() && typeExclusions.isEmpty()) {
        throw new IllegalArgumentException("child option must include or exclude some type");
    }

    isIncludeType = new Function<Class<? extends IObject>, Boolean>() {
        @Override
        public Boolean apply(Class<? extends IObject> objectClass) {
            for (final Class<? extends IObject> typeInclusion : typeInclusions) {
                if (typeInclusion.isAssignableFrom(objectClass)) {
                    return Boolean.TRUE;
                }
            }
            for (final Class<? extends IObject> typeExclusion : typeExclusions) {
                if (typeExclusion.isAssignableFrom(objectClass)) {
                    return Boolean.FALSE;
                }
            }
            return null;
        }
    };

    /* if no annotation namespaces are set, then apply the defaults */

    if (CollectionUtils.isEmpty(includeNs) && CollectionUtils.isEmpty(excludeNs)) {
        excludeNs = new ArrayList<String>(defaultExcludeNs);
    }

    /* construct the predicate corresponding to the namespace restriction */

    if (CollectionUtils.isEmpty(includeNs)) {
        if (CollectionUtils.isEmpty(excludeNs)) {
            /* there is no adjustment to make, not even for any default namespaces */
            isTargetNamespace = Predicates.alwaysTrue();
        } else {
            final ImmutableSet<String> nsExclusions = ImmutableSet.copyOf(excludeNs);
            isTargetNamespace = new Predicate<String>() {
                @Override
                public boolean apply(String namespace) {
                    return !nsExclusions.contains(namespace);
                }
            };
        }
    } else {
        if (CollectionUtils.isEmpty(excludeNs)) {
            final ImmutableSet<String> nsInclusions = ImmutableSet.copyOf(includeNs);
            isTargetNamespace = new Predicate<String>() {
                @Override
                public boolean apply(String namespace) {
                    return nsInclusions.contains(namespace);
                }
            };
        } else {
            throw new IllegalArgumentException("child option may not both include and exclude namespace");
        }
    }
}

From source file:org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.Navigatable.java

/**
 * Returns, from the given TreeNode, the next TreeNode that contains a diff.
 * //from ww  w.  j a va2s .c o m
 * @param treeNode
 *            the given TreeNode for which we want to find the next.
 * @return the next TreeNode that contains a diff.
 */
private Object getNextDiff(TreeItem start) {
    return getNextData(start, Predicates.alwaysTrue());
}

From source file:com.bazaarvoice.dropwizard.caching.CacheControlConfigurationItem.java

private static Predicate<String> groupNameMatcher(String name) {
    if (name.equals("*")) {
        return Predicates.alwaysTrue();
    }/*w ww .  ja  v  a2s.co m*/

    return regexMatcher(Pattern.compile("" + "^" + Joiner.on(".*")
            .join(FluentIterable.from(Splitter.on('*').split(name)).transform(new Function<String, Object>() {
                public Object apply(String input) {
                    return input.length() == 0 ? input : Pattern.quote(input);
                }
            })) + "$", Pattern.CASE_INSENSITIVE));
}

From source file:org.apache.brooklyn.enricher.stock.AbstractAggregator.java

protected Predicate<?> getDefaultValueFilter() {
    return Predicates.alwaysTrue();
}

From source file:com.eucalyptus.autoscaling.common.internal.metadata.AbstractOwnedPersistentsWithResourceNameSupport.java

protected <T> T lookupByName(final OwnerFullName ownerFullName, final String scope, final String name,
        final Function<? super AOP, T> transform) throws AutoScalingMetadataException {
    return lookupByExample(exampleWithName(ownerFullName, scope, name), ownerFullName, name,
            Predicates.alwaysTrue(), transform);
}

From source file:org.apache.brooklyn.core.config.BasicConfigKey.java

public BasicConfigKey(TypeToken<T> type, String name, String description, T defaultValue) {
    this.description = description;
    this.name = checkNotNull(name, "name");

    this.type = TypeTokens.getRawTypeIfRaw(checkNotNull(type, "type"));
    this.typeToken = TypeTokens.getTypeTokenIfNotRaw(type);

    this.defaultValue = defaultValue;
    this.reconfigurable = false;
    this.constraint = Predicates.alwaysTrue();
}

From source file:net.automatalib.util.ts.copy.TSCopy.java

/**
 * Copies an {@link Automaton} to a {@link MutableAutomaton} with a compatible input alphabet, but possibly heterogeneous state and
 * transition properties. States and transitions will not be filtered.
 * /*from   w  w w .  j a  va  2  s  . com*/
 * @param method the traversal method to use
 * @param in the input transition system
 * @param limit the traversal limit, a value less than 0 means no limit
 * @param inputs the inputs to consider
 * @param out the output automaton
 * @param spMapping the function for obtaining state properties
 * @param tpMapping the function for obtaining transition properties
 * @return a mapping from old to new states
 */
public static <S1, I, T1, S2, T2, SP2, TP2> Mapping<S1, S2> rawCopy(TSTraversalMethod method,
        TransitionSystem<S1, ? super I, T1> in, int limit, Collection<? extends I> inputs,
        MutableAutomaton<S2, I, T2, SP2, TP2> out, Function<? super S1, ? extends SP2> spMapping,
        Function<? super T1, ? extends TP2> tpMapping) {
    return rawCopy(method, in, limit, inputs, out, spMapping, tpMapping, Predicates.alwaysTrue(),
            TransitionPredicates.alwaysTrue());
}

From source file:org.apache.brooklyn.enricher.stock.Propagator.java

@Override
public void setEntity(EntityLocal entity) {
    super.setEntity(entity);

    this.producer = getConfig(PRODUCER) == null ? entity : getConfig(PRODUCER);
    boolean sensorMappingSet = getConfig(SENSOR_MAPPING) != null;
    MutableMap<Sensor<?>, Sensor<?>> sensorMappingTemp = MutableMap.copyOf(getConfig(SENSOR_MAPPING));
    this.propagatingAll = Boolean.TRUE.equals(getConfig(PROPAGATING_ALL))
            || getConfig(PROPAGATING_ALL_BUT) != null;

    if (getConfig(PROPAGATING) != null) {
        if (propagatingAll) {
            throw new IllegalStateException("Propagator enricher " + this
                    + " must not have 'propagating' set at same time as either 'propagatingAll' or 'propagatingAllBut'");
        }/* ww w. j av a  2s  .c  om*/

        for (Object sensorO : getConfig(PROPAGATING)) {
            Sensor<?> sensor = Tasks.resolving(sensorO).as(Sensor.class).timeout(ValueResolver.REAL_QUICK_WAIT)
                    .context(producer).get();
            if (!sensorMappingTemp.containsKey(sensor)) {
                sensorMappingTemp.put(sensor, sensor);
            }
        }
        this.sensorMapping = ImmutableMap.copyOf(sensorMappingTemp);
        this.sensorFilter = new Predicate<Sensor<?>>() {
            @Override
            public boolean apply(Sensor<?> input) {
                // TODO kept for deserialization of inner classes, but shouldn't be necessary, as with other inner classes (qv);
                // NB: previously this did this check:
                //                    return input != null && sensorMapping.keySet().contains(input);
                // but those clauses seems wrong (when would input be null?) and unnecessary (we are doing an explicit subscribe in this code path) 
                return true;
            }
        };
    } else if (sensorMappingSet) {
        if (propagatingAll) {
            throw new IllegalStateException("Propagator enricher " + this
                    + " must not have 'sensorMapping' set at same time as either 'propagatingAll' or 'propagatingAllBut'");
        }
        this.sensorMapping = ImmutableMap.copyOf(sensorMappingTemp);
        this.sensorFilter = Predicates.alwaysTrue();
    } else {
        this.sensorMapping = ImmutableMap.<Sensor<?>, Sensor<?>>of();
        if (!propagatingAll) {
            // default if nothing specified is to do all but the ones not usually propagated
            propagatingAll = true;
            // user specified nothing, so *set* the all_but to the default set
            // if desired, we could allow this to be dynamically reconfigurable, remove this field and always look up;
            // slight performance hit (always looking up), and might need to recompute subscriptions, so not supported currently
            // TODO this default is @Beta behaviour! -- maybe better to throw?
            propagatingAllBut = SENSORS_NOT_USUALLY_PROPAGATED;
        } else {
            propagatingAllBut = getConfig(PROPAGATING_ALL_BUT);
        }
        this.sensorFilter = new Predicate<Sensor<?>>() {
            @Override
            public boolean apply(Sensor<?> input) {
                Collection<Sensor<?>> exclusions = propagatingAllBut;
                // TODO this anonymous inner class and getConfig check kept should be removed / confirmed for rebind compatibility.
                // we *should* be regenerating these fields on each rebind (calling to this method), 
                // so serialization of this class shouldn't be needed (and should be skipped), but that needs to be checked.
                if (propagatingAllBut == null)
                    exclusions = getConfig(PROPAGATING_ALL_BUT);
                return input != null && (exclusions == null || !exclusions.contains(input));
            }
        };
    }

    Preconditions.checkState(propagatingAll ^ sensorMapping.size() > 0,
            "Nothing to propagate; detected: propagatingAll (%s, excluding %s), sensorMapping (%s)",
            propagatingAll, getConfig(PROPAGATING_ALL_BUT), sensorMapping);

    if (propagatingAll) {
        subscriptions().subscribe(producer, null, this);
    } else {
        for (Sensor<?> sensor : sensorMapping.keySet()) {
            subscriptions().subscribe(producer, sensor, this);
        }
    }

    emitAllAttributes();
}