List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:com.treasuredata.client.TDClientConfig.java
@JsonCreator TDClientConfig(Optional<String> endpoint, Optional<Integer> port, boolean useSSL, Optional<String> apiKey, Optional<String> user, Optional<String> password, Optional<ProxyConfig> proxy, int retryLimit, int retryInitialIntervalMillis, int retryMaxIntervalMillis, double retryMultiplier, int connectTimeoutMillis, int idleTimeoutMillis, int requestTimeoutMillis, int connectionPoolSize, Multimap<String, String> headers, Optional<Integer> requestBufferSize, Optional<Integer> responseBufferSize, Optional<Integer> maxContentLength) { this.endpoint = endpoint.or("api.treasuredata.com"); this.port = port; this.useSSL = useSSL; this.apiKey = apiKey; this.user = user; this.password = password; this.proxy = proxy; this.retryLimit = retryLimit; this.retryInitialIntervalMillis = retryInitialIntervalMillis; this.retryMaxIntervalMillis = retryMaxIntervalMillis; this.retryMultiplier = retryMultiplier; this.connectTimeoutMillis = connectTimeoutMillis; this.idleTimeoutMillis = idleTimeoutMillis; this.requestTimeoutMillis = requestTimeoutMillis; this.connectionPoolSize = connectionPoolSize; this.headers = headers; this.requestBufferSize = requestBufferSize; this.responseBufferSize = responseBufferSize; this.maxContentLength = maxContentLength; }
From source file:org.puder.trs80.EditConfigurationFragment.java
private void updateSummaries() { Optional<String> valOpt = configPersitence.getName(); if (valOpt.isPresent()) { name.setSummary(valOpt.get());// ww w .ja v a2s . com } valOpt = configPersitence.getModel(); if (valOpt.isPresent()) { String val = valOpt.get(); if (val.equals("1")) { val = "I"; } else if (val.equals("3")) { val = "III"; } else if (val.equals("5")) { val = "4P"; } model.setSummary("Model " + val); } // Cassette valOpt = configPersitence.getCasettePath(); cassette.setSummary(valOpt.or(defaultCassetteSummary)); // Disk 1 valOpt = configPersitence.getDiskPath(0); disk1.setSummary(valOpt.or(defaultDisk1Summary)); // Disk 2 valOpt = configPersitence.getDiskPath(1); disk2.setSummary(valOpt.or(defaultDisk2Summary)); // Disk 3 valOpt = configPersitence.getDiskPath(2); disk3.setSummary(valOpt.or(defaultDisk3Summary)); // Disk 4 valOpt = configPersitence.getDiskPath(3); disk4.setSummary(valOpt.or(defaultDisk4Summary)); // Character color setCharacterColorSummary(configPersitence.getCharacterColor(0)); // Keyboard portrait setKeyboardSummary(keyboardPortrait, configPersitence.getKeyboardLayoutPortrait()); // Keyboard landscape setKeyboardSummary(keyboardLandscape, configPersitence.getKeyboardLayoutLandscape()); }
From source file:gobblin.runtime.GobblinMultiTaskAttempt.java
public GobblinMultiTaskAttempt(Iterator<WorkUnit> workUnits, String jobId, JobState jobState, TaskStateTracker taskStateTracker, TaskExecutor taskExecutor, Optional<String> containerIdOptional, Optional<StateStore<TaskState>> taskStateStoreOptional, SharedResourcesBroker<GobblinScopeTypes> jobBroker) { super();/*from www.j a v a 2s. c o m*/ this.workUnits = workUnits; this.jobId = jobId; this.jobState = jobState; this.taskStateTracker = taskStateTracker; this.taskExecutor = taskExecutor; this.containerIdOptional = containerIdOptional; this.taskStateStoreOptional = taskStateStoreOptional; this.log = LoggerFactory .getLogger(GobblinMultiTaskAttempt.class.getName() + "-" + containerIdOptional.or("noattempt")); this.jobBroker = jobBroker; }
From source file:org.locationtech.geogig.storage.bdbje.JEObjectDatabase.java
private int getBulkPartitionSize() { Optional<Integer> configuredSize = configDB.get(BULK_PARTITIONING_CONFIG_KEY, Integer.class); return configuredSize.or(DEFAULT_BULK_PARTITIONING).intValue(); }
From source file:org.puder.trs80.EmulatorActivity.java
public void notImplemented(String msg) { TRS80Application.setCrashedFlag(true); Crashlytics.setString("NOT_IMPLEMENTED", msg); Crashlytics.setInt("MODEL", currentConfiguration.getModel()); Crashlytics.setString("NAME", currentConfiguration.getName().or("-")); Optional<String> path = currentConfiguration.getDiskPath(0); Crashlytics.setString("DISK_0", path.or("-")); throw new RuntimeException(); }
From source file:org.apache.aurora.scheduler.http.Mname.java
private Response get(String role, String env, String job, int instanceId, UriInfo uriInfo, Optional<String> forwardRequest) { IScheduledTask task = Iterables.getOnlyElement(Storage.Util.fetchTasks(storage, Query.instanceScoped(JobKeys.from(role, env, job), instanceId).active()), null); if (task == null) { return respond(NOT_FOUND, "No such live instance found."); }/*from ww w .j av a 2s .co m*/ if (task.getStatus() != RUNNING) { return respond(NOT_FOUND, "The selected instance is currently in state " + task.getStatus()); } IAssignedTask assignedTask = task.getAssignedTask(); Optional<Integer> port = getRedirectPort(assignedTask); if (!port.isPresent()) { return respond(NOT_FOUND, "The task does not have a registered http port."); } UriBuilder redirect = UriBuilder.fromPath(forwardRequest.or("/")).scheme("http") .host(assignedTask.getSlaveHost()).port(port.get()); for (Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) { for (String value : entry.getValue()) { redirect.queryParam(entry.getKey(), value); } } return Response.temporaryRedirect(redirect.build()).build(); }
From source file:com.github.katjahahn.parser.sections.SectionLoader.java
/** * Assembles the loadInfo object for the dataDirKey. * // w ww . j av a 2 s . c om * @param dataDirKey * data directory key * @return loading information */ private Optional<LoadInfo> maybeGetLoadInfo(DataDirectoryKey dataDirKey) { Optional<DataDirEntry> dirEntry = optHeader.maybeGetDataDirEntry(dataDirKey); if (dirEntry.isPresent()) { long virtualAddress = dirEntry.get().getVirtualAddress(); Optional<Long> maybeOffset = maybeGetFileOffsetFor(dataDirKey); if (!maybeOffset.isPresent()) { logger.info("unable to get file offset for " + dataDirKey); } long offset = maybeOffset.or(-1L); return Optional.of(new LoadInfo(offset, virtualAddress, getMemoryMappedPE(), data, this)); } return Optional.absent(); }
From source file:com.qcadoo.mes.costNormsForMaterials.CostNormsForMaterialsService.java
public void updateCostsForProductInOrder(final Entity order, final Long productId, final Optional<BigDecimal> newQuantity, final Optional<BigDecimal> costForOrder) { Optional<Entity> orderMaterialCostsOpt = orderMaterialCostsDataProvider.find(order.getId(), productId); /*/*from w w w . j av a 2 s . c om*/ * .or(new Supplier<Entity>() { * @Override public Entity get() { throw new IllegalArgumentException(String.format( * "TechnologyInstanceOperationProductInComponent (order material costs entity) not found for " + "product: %d order: %d", * productId, order.getId())); } }); */ if (orderMaterialCostsOpt.isPresent()) { Entity orderMaterialCosts = orderMaterialCostsOpt.get(); orderMaterialCosts.setField(TechnologyInstOperProductInCompFields.COST_FOR_ORDER, numberService.setScale(costForOrder.or(BigDecimal.ZERO))); BigDecimal oldQuantity = orderMaterialCosts .getDecimalField(TechnologyInstOperProductInCompFields.COST_FOR_NUMBER); if (oldQuantity == null) { LOG.debug(String.format( "There are no costs in TechnologyInstanceOperationProductInComponent (id: %d ) to recalculate.", orderMaterialCosts.getId())); } else { updateCosts(zeroToOne(newQuantity.or(BigDecimal.ONE)), orderMaterialCosts, zeroToOne(oldQuantity)); } orderMaterialCosts.getDataDefinition().save(orderMaterialCosts); } else { if (LOG.isDebugEnabled()) { LOG.debug(String.format( "TechnologyInstanceOperationProductInComponent (order material costs entity) not found for " + "product: %d order: %d", productId, order.getId())); } } }
From source file:com.twitter.aurora.scheduler.http.Mname.java
private Response get(String role, String env, String job, int instanceId, UriInfo uriInfo, Optional<String> forwardRequest) { IScheduledTask task = Iterables.getOnlyElement(Storage.Util.consistentFetchTasks(storage, Query.instanceScoped(JobKeys.from(role, env, job), instanceId).active()), null); if (task == null) { return respond(NOT_FOUND, "No such live instance found."); }/* www.ja va2 s .c o m*/ if (task.getStatus() != RUNNING) { return respond(NOT_FOUND, "The selected instance is currently in state " + task.getStatus()); } IAssignedTask assignedTask = task.getAssignedTask(); Optional<Integer> port = getRedirectPort(assignedTask); if (!port.isPresent()) { return respond(NOT_FOUND, "The task does not have a registered http port."); } UriBuilder redirect = UriBuilder.fromPath(forwardRequest.or("/")).scheme("http") .host(assignedTask.getSlaveHost()).port(port.get()); for (Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) { for (String value : entry.getValue()) { redirect.queryParam(entry.getKey(), value); } } return Response.temporaryRedirect(redirect.build()).build(); }
From source file:org.apache.gobblin.runtime.GobblinMultiTaskAttempt.java
public GobblinMultiTaskAttempt(Iterator<WorkUnit> workUnits, String jobId, JobState jobState, TaskStateTracker taskStateTracker, TaskExecutor taskExecutor, Optional<String> containerIdOptional, Optional<StateStore<TaskState>> taskStateStoreOptional, SharedResourcesBroker<GobblinScopeTypes> jobBroker) { super();/*w ww. ja v a 2s . c o m*/ this.workUnits = workUnits; this.jobId = jobId; this.jobState = jobState; this.taskStateTracker = taskStateTracker; this.taskExecutor = taskExecutor; this.containerIdOptional = containerIdOptional; this.taskStateStoreOptional = taskStateStoreOptional; this.log = LoggerFactory .getLogger(GobblinMultiTaskAttempt.class.getName() + "-" + containerIdOptional.or("noattempt")); this.jobBroker = jobBroker; this.tasks = new ArrayList<>(); }