List of usage examples for com.google.common.base Functions constant
public static <E> Function<Object, E> constant(@Nullable E value)
From source file:brooklyn.entity.nosql.couchbase.CouchbaseSyncGatewayImpl.java
@Override protected void connectServiceUpIsRunning() { HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(CouchbaseSyncGateway.ADMIN_REST_API_PORT)); String managementUri = String.format("http://%s:%s", hp.getHostText(), hp.getPort()); setAttribute(MANAGEMENT_URL, managementUri); httpFeed = HttpFeed.builder().entity(this).period(200).baseUri(managementUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();//from w ww.j a v a2 s. c om }
From source file:brooklyn.entity.nosql.solr.SolrServerImpl.java
@Override protected void connectSensors() { super.connectSensors(); HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getSolrPort()); String solrUri = String.format("http://%s:%d/solr", hp.getHostText(), hp.getPort()); setAttribute(Attributes.MAIN_URI, URI.create(solrUri)); httpFeed = HttpFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS).baseUri(solrUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();//from w ww. j a va2 s . c o m }
From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseSyncGatewayImpl.java
@Override protected void connectServiceUpIsRunning() { HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(CouchbaseSyncGateway.ADMIN_REST_API_PORT)); String managementUri = String.format("http://%s:%s", hp.getHostText(), hp.getPort()); sensors().set(MANAGEMENT_URL, managementUri); httpFeed = HttpFeed.builder().entity(this).period(200).baseUri(managementUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();//www .j av a 2s . c o m }
From source file:org.apache.brooklyn.entity.nosql.solr.SolrServerImpl.java
@Override protected void connectSensors() { super.connectSensors(); HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getSolrPort()); String solrUri = String.format("http://%s:%d/solr", hp.getHostText(), hp.getPort()); sensors().set(Attributes.MAIN_URI, URI.create(solrUri)); httpFeed = HttpFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS).baseUri(solrUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();/*from w w w .j av a 2 s . c o m*/ }
From source file:edu.uci.ics.jung.algorithms.scoring.HITSWithPriors.java
/** * Creates an instance for the specified graph, vertex priors, and random * jump probability (alpha). The edge weights default to 1.0. * @param g the input graph/* w w w . j a va2 s . c om*/ * @param vertex_priors the prior probability for each vertex * @param alpha the probability of a random jump at each step */ public HITSWithPriors(Hypergraph<V, E> g, Function<V, HITS.Scores> vertex_priors, double alpha) { super(g, Functions.constant(1.0), vertex_priors, alpha); disappearing_potential = new HITS.Scores(0, 0); }
From source file:net.hydromatic.optiq.prepare.RelOptTableImpl.java
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType, List<String> names, Expression expression) {/* w w w .java 2 s . co m*/ //noinspection unchecked final Function<Class, Expression> expressionFunction = (Function) Functions.constant(expression); return new RelOptTableImpl(schema, rowType, names, null, expressionFunction, null); }
From source file:org.apache.brooklyn.entity.stock.DataEntityImpl.java
protected void connectSensors() { FunctionFeed.Builder builder = FunctionFeed.builder().entity(this).period(getConfig(POLL_PERIOD)); Map<AttributeSensor<?>, Supplier<?>> map = getConfig(SENSOR_SUPPLIER_MAP); if (map != null && map.size() > 0) { for (Map.Entry<AttributeSensor<?>, Supplier<?>> entry : map.entrySet()) { final AttributeSensor sensor = entry.getKey(); final Supplier<?> supplier = entry.getValue(); builder.poll(new FunctionPollConfig<Object, Object>(sensor).supplier(supplier) .onFailureOrException(Functions.constant(null))); }/* ww w .j a v a2s. co m*/ } feed = builder.build(); }
From source file:net.automatalib.util.automata.copy.AutomatonLowLevelCopy.java
/** * Copies an {@link Automaton} to a {@link MutableAutomaton} with possibly heterogeneous input alphabets and * state and transition properties.// www . jav a 2 s . c om * * @param <S1> input automaton state type * @param <I1> input automaton input symbol type * @param <T1> input automaton transition type * @param <S2> output automaton state type * @param <I2> output automaton input symbol type * @param <T2> output automaton transition type * @param <SP2> output automaton state property type * @param <TP2> output automaton transition property type * @param method the copy method to use * @param in the input automaton * @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(AutomatonCopyMethod method, Automaton<S1, ? super I1, T1> in, 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(); } LowLevelAutomatonCopier<S1, I1, T1, S2, I2, T2, SP2, TP2> copier = method.createLowLevelCopier(in, inputs, out, inputsMapping, spMapping, tpMapping, stateFilter, transFilter); copier.doCopy(); return copier.getStateMapping(); }
From source file:brooklyn.entity.basic.EntityTasks.java
/** as {@link #requiringAttributeEventually(Entity, AttributeSensor, Predicate, Duration) for multiple entities */ public static <T> Task<Boolean> requiringAttributeEventually(Iterable<Entity> entities, AttributeSensor<T> sensor, Predicate<T> condition, Duration timeout) { return DependentConfiguration.builder().attributeWhenReadyFromMultiple(entities, sensor, condition) .postProcess(Functions.constant(true)).timeout(timeout).onTimeoutThrow().onUnmanagedThrow() .postProcessFromMultiple(CollectionFunctionals.all(Predicates.equalTo(true))).build(); }
From source file:org.terasology.rendering.nui.layers.mainMenu.PlayerSettingsScreen.java
@Override public void initialise() { UIText nametext = find("playername", UIText.class); if (nametext != null) { nametext.bindText(BindHelper.bindBeanProperty("name", config.getPlayer(), String.class)); }/*w w w .j a va 2s .c om*/ Color color = config.getPlayer().getColor(); img = find("image", UIImage.class); slider = find("tone", UISlider.class); slider.bindValue(new NotifyingBinding(findClosestIndex(color))); slider.setIncrement(0.01f); Function<Object, String> constant = Functions.constant(" "); // ensure a certain width slider.setLabelFunction(constant); WidgetUtil.trySubscribe(this, "close", new ActivateEventListener() { @Override public void onActivated(UIWidget button) { getManager().popScreen(); } }); updateImage(); }