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.event.feed.FeedConfig.java
public F setOnFailureOrException(T val) { return onFailureOrException(Functions.constant(val)); }
From source file:brooklyn.entity.container.docker.DockerContainerImpl.java
protected void connectSensors() { status = FunctionFeed.builder().entity(this).period(Duration.seconds(15)) .poll(new FunctionPollConfig<String, String>(DOCKER_CONTAINER_NAME).period(Duration.minutes(1)) .callable(new Callable<String>() { @Override public String call() throws Exception { String containerId = getContainerId(); if (containerId == null) return ""; String name = getDockerHost() .runDockerCommand("inspect -f {{.Name}} " + containerId); return Strings.removeFromStart(name, "/"); }/* www . j a va 2 s .com*/ }).onFailureOrException(Functions.constant(""))) .poll(new FunctionPollConfig<Boolean, Boolean>(SERVICE_UP).callable(new Callable<Boolean>() { @Override public Boolean call() throws Exception { String containerId = getContainerId(); if (containerId == null) return false; return Strings .isNonBlank(getDockerHost().runDockerCommand("inspect -f {{.Id}} " + containerId)); } }).onFailureOrException(Functions.constant(Boolean.FALSE))) .poll(new FunctionPollConfig<Boolean, Boolean>(CONTAINER_RUNNING).callable(new Callable<Boolean>() { @Override public Boolean call() throws Exception { String containerId = getContainerId(); if (containerId == null) return false; String running = getDockerHost() .runDockerCommand("inspect -f {{.State.Running}} " + containerId); return Strings.isNonBlank(running) && Boolean.parseBoolean(Strings.trim(running)); } }).onFailureOrException(Functions.constant(Boolean.FALSE))) .poll(new FunctionPollConfig<Boolean, Boolean>(CONTAINER_PAUSED).callable(new Callable<Boolean>() { @Override public Boolean call() throws Exception { String containerId = getContainerId(); if (containerId == null) return false; String running = getDockerHost() .runDockerCommand("inspect -f {{.State.Paused}} " + containerId); return Strings.isNonBlank(running) && Boolean.parseBoolean(Strings.trim(running)); } }).onFailureOrException(Functions.constant(Boolean.FALSE))).build(); }
From source file:com.android.tools.idea.wizard.ImportWizardModuleBuilder.java
protected void addSteps(WizardPath path) { Collection<ModuleWizardStep> steps = path.getSteps(); mySteps.addAll(steps); myStepsToPath.putAll(Maps.toMap(steps, Functions.constant(path))); }
From source file:org.apache.brooklyn.core.feed.FeedConfig.java
/** @see #onException(Function) */ public F setOnException(T val) { return onException(Functions.constant(val)); }
From source file:com.googlecode.blaisemath.style.ObjectStyler.java
/** * Sets a single label for all objects * @param text label text */ public void setLabelConstant(@Nullable String text) { setLabelDelegate(Functions.constant(text)); }
From source file:org.activityinfo.legacy.shared.impl.GetSitesHandler.java
private void doQuery(final GetSites command, final ExecutionContext context, final AsyncCallback<SiteResult> callback) { // in order to pull in the linked queries, we want to // to create two queries that we union together. // for performance reasons, we want to apply all of the joins // and filters on both parts of the union query SqlQuery unioned;// ww w . j a va2 s.co m if (command.isFetchLinks()) { unioned = unionedQuery(context, command); unioned.appendAllColumns(); } else { unioned = primaryQuery(context, command); } if (isMySql() && command.getLimit() >= 0) { // with this feature, MySQL will keep track of the total // number of rows regardless of our limit statement. // This way we don't have to execute the query twice to // get the total count // // unfortunately, this is not available on sqlite unioned.appendKeyword("SQL_CALC_FOUND_ROWS"); } applySort(unioned, command.getSortInfo()); applyPaging(unioned, command); final Multimap<Integer, SiteDTO> siteMap = HashMultimap.create(); final List<SiteDTO> sites = new ArrayList<SiteDTO>(); final Map<Integer, SiteDTO> reportingPeriods = Maps.newHashMap(); final SiteResult result = new SiteResult(sites); result.setOffset(command.getOffset()); Log.trace("About to execute primary query: " + unioned.toString()); unioned.execute(context.getTransaction(), new SqlResultCallback() { @Override public void onSuccess(SqlTransaction tx, SqlResultSet results) { Log.trace("Primary query returned, starting to add to map"); for (SqlResultSetRow row : results.getRows()) { SiteDTO site = toSite(command, row); sites.add(site); siteMap.put(site.getId(), site); if (command.isFetchAllReportingPeriods()) { reportingPeriods.put(row.getInt("PeriodId"), site); } } Log.trace("Finished adding to map"); List<Promise<Void>> queries = Lists.newArrayList(); if (command.getLimit() <= 0) { result.setTotalLength(results.getRows().size()); } else { queries.add(queryTotalLength(tx, command, context, result)); } if (!sites.isEmpty()) { if (command.isFetchAdminEntities()) { queries.add(joinEntities(tx, siteMap)); } if (command.isFetchAttributes()) { queries.add(joinAttributeValues(command, tx, siteMap)); } if (command.fetchAnyIndicators()) { queries.add(joinIndicatorValues(command, tx, siteMap, reportingPeriods)); } } Promise.waitAll(queries).then(Functions.constant(result)).then(callback); } }); }
From source file:com.qcadoo.mes.deviationCausesReporting.print.DeviationsProtocolPdf.java
private Optional<DateTime> parseDateFromModel(final Object modelValue) { return FluentOptional.fromNullable(modelValue).flatMap(new Function<Object, Optional<DateTime>>() { @Override//from w w w . j a va2s . c om public Optional<DateTime> apply(final Object input) { return DateUtils.tryParse(input).fold(Functions.constant(Optional.<DateTime>absent()), Functions.<Optional<DateTime>>identity()); } }).toOpt(); }
From source file:com.googlecode.blaisemath.style.ObjectStyler.java
/** * Sets a single style for all objects./* w w w . ja v a 2s. co m*/ * @param style style to use for all objects */ public void setStyleConstant(AttributeSet style) { setStyleDelegate(Functions.constant(checkNotNull(style))); }
From source file:org.apache.brooklyn.entity.cloudfoundry.webapp.java.JavaCloudFoundryPaasWebAppImpl.java
private void connectResourceLatencySensor() { resourceLatencyFeed = FunctionFeed.builder().entity(this).period(Duration.seconds(2)) .poll(new FunctionPollConfig<Double, Double>(RESOURCE_LATENCY).onException(Functions.constant(0.0)) .callable(new Callable<Double>() { public Double call() { Double total = getAttribute(DURATION_SUM); Double num = getAttribute(RESOURCE_HITS); return total / num; }/*from ww w. j av a 2s .com*/ })) .build(); }
From source file:me.fromgate.laser.Arsenal.java
public static boolean damageEntity(Player damager, LivingEntity e, double damage) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, e, DamageCause.ENTITY_ATTACK, new EnumMap(ImmutableMap.of(EntityDamageEvent.DamageModifier.BASE, Double.valueOf(damage))), new EnumMap(ImmutableMap.of(EntityDamageEvent.DamageModifier.BASE, Functions.constant(Double.valueOf(-0.0D))))); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) e.damage(event.getDamage(), event.getDamager()); return !event.isCancelled(); }