List of usage examples for com.google.common.base Optional of
public static <T> Optional<T> of(T reference)
From source file:org.akraievoy.cnet.soo.domain.ConditionSooFitnessCapping.java
public boolean isValid(GeneticStrategy<GenomeSoo> strategy, GenomeSoo child, Collection<GenomeSoo> generation, int generationIndex) { final GeneticStrategySoo strategySoo = (GeneticStrategySoo) strategy; if (!fitnessCap.isPresent()) { double fcTarget = strategySoo.getFitnessCap(); fitnessCap = Optional.of(Interpolate .norm(0, strategySoo.generationNum * 0.5, fcTarget * 0.85, fcTarget, Interpolate.LINEAR) .apply(generationIndex)); }//from w w w. j a v a2 s .co m final double fitness = child.getOrComputeFitness(strategy); final Double fitnessCap = this.fitnessCap.get(); final boolean valid = fitness <= fitnessCap; /* System.out.printf("%g <= %g --> %s %n", fitness, fitnessCap, valid ? "valid" : "invalid"); */ return valid; }
From source file:io.macgyver.ssh.PubKeyCredentials.java
private Optional<File> locateKeyFile(String username) { String home = System.getProperty("user.home", "."); File f = new File(home, ".ssh/id_rsa"); if (f.exists()) { return Optional.of(f); }/*from w w w.j a v a2 s .c o m*/ f = new File(home, ".ssh/id_dsa"); if (f.exists()) { return Optional.of(f); } return Optional.absent(); }
From source file:com.dangdang.ddframe.job.lite.console.controller.JobOperationController.java
@RequestMapping(value = "trigger", method = RequestMethod.POST) public void triggerJob(final ServerInfo jobServer) { jobAPIService.getJobOperatorAPI().trigger(Optional.of(jobServer.getJobName()), Optional.of(jobServer.getIp())); }
From source file:com.facebook.buck.parser.ExportFileBuildRuleFactory.java
@Override protected void amendBuilder(AbstractBuildRuleBuilder abstractBuilder, BuildRuleFactoryParams params) throws NoSuchBuildTargetException { ExportFileRule.Builder builder = (ExportFileRule.Builder) abstractBuilder; Optional<String> src = params.getOptionalStringAttribute("src"); if (src.isPresent()) { String srcPath = params.resolveFilePathRelativeToBuildFileDirectory(src.get()); builder.setSrc(Optional.of(srcPath)); } else {//w ww . j av a2 s. co m builder.setSrc(src); } Optional<String> out = params.getOptionalStringAttribute("out"); builder.setOut(out); }
From source file:org.brooklyncentral.catalog.model.CatalogItem.java
@SuppressWarnings("unchecked") public CatalogItem(String repoUrl, String repoName, String author, String description, String documentation, String catalogBomString, Map<String, Object> catalogBomYaml, @Nullable String masterCommitHash, @Nullable String license, @Nullable String changelog) { this.repoUrl = repoUrl; this.repoName = repoName; this.author = author; this.token = author + "/" + repoName; this.description = description; this.documentation = documentation; this.catalogBomString = catalogBomString; this.catalogBomYaml = (Map<String, Object>) Yamls.parseAll(catalogBomString).iterator().next(); this.masterCommitHash = Optional.of(masterCommitHash); this.license = Optional.of(license); this.changelog = Optional.of(changelog); }
From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.toxml.ObjectNameAttributeWritingStrategy.java
@Override public void writeElement(Element parentElement, String namespace, Object value) { Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class); Element innerNode = XmlUtil.createElement(document, key, Optional.of(namespace)); String moduleName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getServiceName(); String refName = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getRefName(); String namespaceForType = ((ObjectNameAttributeMappingStrategy.MappedDependency) value).getNamespace(); Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlNetconfConstants.TYPE_KEY, XmlNetconfConstants.PREFIX, namespaceForType, moduleName); innerNode.appendChild(typeElement);/*from w w w . j a v a 2s. c o m*/ final Element nameElement = XmlUtil.createTextElement(document, XmlNetconfConstants.NAME_KEY, refName, Optional.<String>absent()); innerNode.appendChild(nameElement); parentElement.appendChild(innerNode); }
From source file:com.qcadoo.mes.orders.dates.OrderDates.java
public static OrderDates of(final Entity order, final DateTime defaultStart, final DateTime defaultEnd) { return OrderDates.of(order, Optional.of(defaultStart), Optional.of(defaultEnd)); }
From source file:com.palantir.common.remoting.ServiceNotAvailableException.java
public ServiceNotAvailableException(String message, HostAndPort serviceHint) { super(message); this.serviceHint = Optional.of(serviceHint); }
From source file:org.inferred.freebuilder.processor.BuilderFactory.java
/** Determines the correct way of constructing a default {@code builderType} instance, if any. */ public static Optional<BuilderFactory> from(TypeElement builderType) { ImmutableSet<String> staticMethods = findPotentialStaticFactoryMethods(builderType); if (staticMethods.contains("builder")) { return Optional.of(BUILDER_METHOD); } else if (staticMethods.contains("newBuilder")) { return Optional.of(NEW_BUILDER_METHOD); } else if (hasExplicitNoArgsConstructor(builderType)) { return Optional.of(NO_ARGS_CONSTRUCTOR); } else {/*from ww w. j a v a 2 s. c o m*/ return Optional.absent(); } }
From source file:org.opennms.newts.rest.RepositoryHealthCheck.java
/** Perform simple query; Establishes only that we can go to the database without excepting. */ @Override/*from w w w .j a va2 s. co m*/ protected Result check() throws Exception { m_repository.select(Context.DEFAULT_CONTEXT, new Resource("notreal"), Optional.of(Timestamp.fromEpochMillis(0)), Optional.of(Timestamp.fromEpochMillis(0))); return Result.healthy(); }