Example usage for com.google.common.base Functions constant

List of usage examples for com.google.common.base Functions constant

Introduction

In this page you can find the example usage for com.google.common.base Functions constant.

Prototype

public static <E> Function<Object, E> constant(@Nullable E value) 

Source Link

Document

Creates a function that returns value for any input.

Usage

From source file:de.bund.bfr.knime.nls.NlsUtils.java

public static Map<String, Double> createZeroMap(Collection<String> keys) {
    return new LinkedHashMap<>(Maps.asMap(new LinkedHashSet<>(keys), Functions.constant(0.0)));
}

From source file:brooklyn.entity.basic.EntityTasks.java

/** as {@link #testingAttributeEventually(Entity, AttributeSensor, Predicate, Duration) for multiple entities */
public static <T> Task<Boolean> testingAttributeEventually(Iterable<Entity> entities, AttributeSensor<T> sensor,
        Predicate<T> condition, Duration timeout) {
    return DependentConfiguration.builder().attributeWhenReadyFromMultiple(entities, sensor, condition)
            .postProcess(Functions.constant(true)).timeout(timeout).onTimeoutReturn(false)
            .onUnmanagedReturn(false)//  ww  w.  ja v  a 2 s. c om
            .postProcessFromMultiple(CollectionFunctionals.all(Predicates.equalTo(true))).build();
}

From source file:com.android.builder.files.IncrementalRelativeFileSets.java

/**
 * Reads a directory and adds all files in the directory in a new incremental relative set.
 * The status of each file is set to {@link FileStatus#NEW}. This method is used to construct
 * an initial set of files and is, therefore, an incremental update from zero.
 *
 * @param directory the directory, must be an existing directory
 * @return the file set/*from   ww w  .  ja  v  a 2 s .co m*/
 */
@NonNull
public static ImmutableMap<RelativeFile, FileStatus> fromDirectory(@NonNull File directory) {
    Preconditions.checkArgument(directory.isDirectory(), "!directory.isDirectory()");
    Set<RelativeFile> files = RelativeFiles.fromDirectory(directory);
    files = Sets.filter(files, Predicates.compose(Files.isFile(), RelativeFile.EXTRACT_FILE));
    Map<RelativeFile, FileStatus> map = Maps.asMap(files, Functions.constant(FileStatus.NEW));
    return ImmutableMap.copyOf(map);
}

From source file:io.crate.executor.transport.task.elasticsearch.SymbolToFieldExtractor.java

private static <T> Function<T, Object> constant(Object value) {
    //noinspection unchecked
    return (Function<T, Object>) Functions.constant(value);
}

From source file:brooklyn.entity.messaging.rabbit.RabbitQueue.java

@Override
protected void connectSensors() {
    String runDir = getParent().getRunDir();
    String cmd = String.format("%s/sbin/rabbitmqctl list_queues -p /%s  | grep '%s'", runDir, getVirtualHost(),
            getQueueName());/*from   w  w  w  . j a v a  2  s .  c  o m*/

    sshFeed = SshFeed.builder().entity(this).machine(machine)
            .poll(new SshPollConfig<Integer>(QUEUE_DEPTH_BYTES).env(shellEnvironment).command(cmd)
                    .onFailure(Functions.constant(-1)).onSuccess(new Function<SshPollValue, Integer>() {
                        @Override
                        public Integer apply(SshPollValue input) {
                            return 0; // TODO parse out queue depth from output
                        }
                    }))
            .poll(new SshPollConfig<Integer>(QUEUE_DEPTH_MESSAGES).env(shellEnvironment).command(cmd)
                    .onFailure(Functions.constant(-1)).onSuccess(new Function<SshPollValue, Integer>() {
                        @Override
                        public Integer apply(SshPollValue input) {
                            return 0; // TODO parse out queue depth from output
                        }
                    }))
            .build();
}

From source file:com.twitter.aurora.scheduler.configuration.SanitizedConfiguration.java

/**
 * Constructs a SanitizedConfiguration object and populates the set of {@link ITaskConfig}s for
 * the provided config./*w  w  w .  java  2s.  c  o  m*/
 *
 * @param sanitized A sanitized configuration.
 */
@VisibleForTesting
public SanitizedConfiguration(IJobConfiguration sanitized) {
    this.sanitized = sanitized;
    this.tasks = Maps.toMap(
            ContiguousSet.create(Range.closedOpen(0, sanitized.getInstanceCount()), DiscreteDomain.integers()),
            Functions.constant(sanitized.getTaskConfig()));
}

From source file:edu.uci.ics.jung.io.GraphMLWriter.java

public GraphMLWriter() {
    vertex_ids = new Function<V, String>() {
        public String apply(V v) {
            return v.toString();
        }/*  ww  w .j av a  2 s  . c o m*/
    };
    edge_ids = Functions.constant(null);
    graph_data = Collections.emptyMap();
    vertex_data = Collections.emptyMap();
    edge_data = Collections.emptyMap();
    vertex_desc = Functions.constant(null);
    edge_desc = Functions.constant(null);
    graph_desc = Functions.constant(null);
    nest_level = 0;
}

From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java

/**
 * Creates a <code>VertexShapeFactory</code> with a constant size of
 * 10 and a constant aspect ratio of 1./* ww w. j av  a2  s . co  m*/
 */
public VertexShapeFactory() {
    this(Functions.constant(10), Functions.constant(1.0f));
}

From source file:org.asoem.greyfish.core.model.ModelParameterTypeListener.java

/**
 * Create a new instance which maps {@link ModelParameter} annotated fields named like a key of the map to the value
 * mapped to the key converted to the type of the field.
 *
 * @param overwriteMap the mapping of field keys to values
 *//*from   ww w.  j a v a2  s . c om*/
public ModelParameterTypeListener(final Map<String, String> overwriteMap) {
    this.overwriteMap = checkNotNull(overwriteMap);
    this.expressionFactoryResolver = Functions.constant(null);
}

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

/**
 * Copies an {@link TransitionSystem} to a {@link MutableAutomaton} with possibly heterogeneous input alphabets and
 * state and transition properties.//from   w  ww. ja v a  2s  .c  om
 * 
 * @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 inputsMapping the transformation for input symbols
 * @param spMapping the function for obtaining state properties
 * @param tpMapping the function for obtaining transition properties
 * @param stateFilter the filter predicate for states
 * @param transFilter the filter predicate for transitions
 * @return a mapping from old to new states
 */
public static <S1, I1, T1, S2, I2, T2, SP2, TP2> Mapping<S1, S2> rawCopy(TSTraversalMethod method,
        TransitionSystem<S1, ? super I1, T1> in, int limit, Collection<? extends I1> inputs,
        MutableAutomaton<S2, I2, T2, ? super SP2, ? super TP2> out,
        Function<? super I1, ? extends I2> inputsMapping, Function<? super S1, ? extends SP2> spMapping,
        Function<? super T1, ? extends TP2> tpMapping, Predicate<? super S1> stateFilter,
        TransitionPredicate<? super S1, ? super I1, ? super T1> transFilter) {
    if (spMapping == null) {
        spMapping = Functions.constant(null);
    }
    if (tpMapping == null) {
        tpMapping = Functions.constant(null);
    }
    if (stateFilter == null) {
        stateFilter = Predicates.alwaysTrue();
    }
    if (transFilter == null) {
        transFilter = TransitionPredicates.alwaysTrue();
    }

    TSCopyVisitor<S1, I1, T1, S2, I2, T2, SP2, TP2> vis = new TSCopyVisitor<>(in, out, inputsMapping, spMapping,
            tpMapping, stateFilter, transFilter);

    method.traverse(in, limit, inputs, vis);
    return vis.getStateMapping();
}