Java Code Examples for com.google.common.base.Optional#absent()
The following examples show how to use
com.google.common.base.Optional#absent() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: arcusandroid File: CachedAddressableListSource.java License: Apache License 2.0 | 6 votes |
@Override protected Optional<List<M>> loadFromCache() { if(addresses.size() == 0) { return Optional.of( (List<M>) ImmutableList.<M>of() ); } List<M> models = new ArrayList<>(addresses.size()); for(String address: addresses) { M model = (M) cache.get(address); if(model == null) { // TODO better option than this? return Optional.absent(); } models.add(model); } return Optional.of(models); }
Example 2
Source Project: digdag File: DatabaseSecretStore.java License: Apache License 2.0 | 6 votes |
@Override public Optional<String> getSecret(int projectId, String scope, String key) { EncryptedSecret secret = tm.begin(() -> autoCommit((handle, dao) -> dao.getProjectSecret(siteId, projectId, scope, key))); if (secret == null) { return Optional.absent(); } // TODO: look up crypto engine using name if (!crypto.getName().equals(secret.engine)) { throw new AssertionError(String.format(ENGLISH, "Crypto engine mismatch. Expected '%s' but got '%s'", secret.engine, crypto.getName())); } String decrypted = crypto.decryptSecret(secret.value); return Optional.of(decrypted); }
Example 3
Source Project: digdag File: DatabaseProjectStoreManager.java License: Apache License 2.0 | 6 votes |
@Override public StoredProject map(int index, ResultSet r, StatementContext ctx) throws SQLException { String name = r.getString("name"); Optional<Instant> deletedAt = Optional.absent(); if (r.wasNull()) { name = r.getString("deleted_name"); deletedAt = Optional.of(getTimestampInstant(r, "deleted_at")); } return ImmutableStoredProject.builder() .id(r.getInt("id")) .name(name) .siteId(r.getInt("site_id")) .createdAt(getTimestampInstant(r, "created_at")) .deletedAt(deletedAt) .build(); }
Example 4
Source Project: incubator-gobblin File: SelectBetweenTimeBasedPolicy.java License: Apache License 2.0 | 5 votes |
public SelectBetweenTimeBasedPolicy(Config conf) { this(conf.hasPath(TIME_BASED_SELECTION_MIN_LOOK_BACK_TIME_KEY) ? Optional.of(getLookBackPeriod(conf .getString(TIME_BASED_SELECTION_MIN_LOOK_BACK_TIME_KEY))) : Optional.<Period> absent(), conf .hasPath(TIME_BASED_SELECTION_MAX_LOOK_BACK_TIME_KEY) ? Optional.of(getLookBackPeriod(conf .getString(TIME_BASED_SELECTION_MAX_LOOK_BACK_TIME_KEY))) : Optional.<Period> absent()); }
Example 5
Source Project: incubator-gobblin File: HivePurgerQueryTemplate.java License: Apache License 2.0 | 5 votes |
/** * Will return all the queries needed to have a backup table partition pointing to the original partition data location */ public static List<String> getBackupQueries(PurgeableHivePartitionDataset dataset) { List<String> queries = new ArrayList<>(); queries.add(getUseDbQuery(dataset.getDbName())); queries.add(getCreateTableQuery(dataset.getCompleteBackupTableName(), dataset.getDbName(), dataset.getTableName(), dataset.getBackupTableLocation())); Optional<String> fileFormat = Optional.absent(); if (dataset.getSpecifyPartitionFormat()) { fileFormat = dataset.getFileFormat(); } queries.add( getAddPartitionQuery(dataset.getBackupTableName(), PartitionUtils.getPartitionSpecString(dataset.getSpec()), fileFormat, Optional.fromNullable(dataset.getOriginalPartitionLocation()))); return queries; }
Example 6
Source Project: rya File: KafkaBindingSetExporterFactory.java License: Apache License 2.0 | 5 votes |
@Override public Optional<IncrementalResultExporter> build(final Context context) throws IncrementalExporterFactoryException, ConfigurationException { final KafkaBindingSetExporterParameters exportParams = new KafkaBindingSetExporterParameters(context.getObserverConfiguration().toMap()); if (exportParams.getUseKafkaBindingSetExporter()) { log.info("Exporter is enabled."); // Setup Kafka connection final KafkaProducer<String, VisibilityBindingSet> producer = new KafkaProducer<>(exportParams.listAllConfig()); // Create the exporter final IncrementalBindingSetExporter exporter = new KafkaBindingSetExporter(producer); return Optional.of(exporter); } else { return Optional.absent(); } }
Example 7
Source Project: cassandra-mesos-deprecated File: Main.java License: Apache License 2.0 | 5 votes |
static Optional<Credential> getCredential() { final boolean auth = Boolean.valueOf(Env.option("MESOS_AUTHENTICATE").or("false")); if (auth){ LOGGER.info("Enabling authentication for the framework"); final String principal = Env.get("DEFAULT_PRINCIPAL"); final Optional<String> secret = Env.option("DEFAULT_SECRET"); return Optional.of(ProtoUtils.getCredential(principal, secret)); } else { return Optional.absent(); } }
Example 8
Source Project: jtwig-core File: VariableMethodPropertyResolverStrategy.java License: Apache License 2.0 | 5 votes |
@Override public Optional<PropertyResolver> select(Request request) { if (request.getRightExpression() instanceof VariableExpression) { String identifier = ((VariableExpression) request.getRightExpression()).getIdentifier(); JavaClass javaClass = classManager.metadata(request.getLeftValue().getClass()); Optional<JavaMethod> method = propertyMethodFinder.find(javaClass, identifier, Collections.emptyList()); return methodPropertyResolverFactory.create(method); } return Optional.absent(); }
Example 9
Source Project: brooklyn-server File: JcloudsSshMachineLocation.java License: Apache License 2.0 | 5 votes |
/** * @since 0.9.0 * @deprecated since 0.9.0 (only added as aid until the deprecated {@link #getTemplate()} is deleted) */ @Deprecated protected Optional<Template> getOptionalTemplate() { if (_template == null) { _template = Optional.absent(); } return _template; }
Example 10
Source Project: jtwig-core File: MethodPropertyResolverFactory.java License: Apache License 2.0 | 5 votes |
public Optional<PropertyResolver> create (Optional<JavaMethod> method) { if (method.isPresent()) { PropertyResolver propertyResolver = new MethodPropertyResolver(method.get(), argumentsConverter); return Optional.of(propertyResolver); } return Optional.absent(); }
Example 11
Source Project: stratio-cassandra File: CqlConfigHelper.java License: Apache License 2.0 | 5 votes |
private static Optional<AuthProvider> getAuthProvider(Configuration conf) { Optional<String> authProvider = getInputNativeAuthProvider(conf); if (!authProvider.isPresent()) return Optional.absent(); return Optional.of(getClientAuthProvider(authProvider.get(), conf)); }
Example 12
Source Project: incubator-gobblin File: GobblinTaskRunner.java License: Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Options options = buildOptions(); try { CommandLine cmd = new DefaultParser().parse(options, args); if (!cmd.hasOption(GobblinClusterConfigurationKeys.APPLICATION_NAME_OPTION_NAME) || !cmd .hasOption(GobblinClusterConfigurationKeys.HELIX_INSTANCE_NAME_OPTION_NAME)) { printUsage(options); System.exit(1); } logger.info(JvmUtils.getJvmInputArguments()); String applicationName = cmd.getOptionValue(GobblinClusterConfigurationKeys.APPLICATION_NAME_OPTION_NAME); String helixInstanceName = cmd.getOptionValue(GobblinClusterConfigurationKeys.HELIX_INSTANCE_NAME_OPTION_NAME); GobblinTaskRunner gobblinWorkUnitRunner = new GobblinTaskRunner(applicationName, helixInstanceName, getApplicationId(), getTaskRunnerId(), ConfigFactory.load(), Optional.<Path>absent()); gobblinWorkUnitRunner.start(); } catch (ParseException pe) { printUsage(options); System.exit(1); } }
Example 13
Source Project: java-n-IDE-for-Android File: XmlElement.java License: Apache License 2.0 | 5 votes |
private Optional<String> findAndCompareNode( XmlElement otherElement, List<Node> otherElementChildren, XmlElement childNode) { Optional<String> message = Optional.absent(); for (Node potentialNode : otherElementChildren) { if (potentialNode.getNodeType() == Node.ELEMENT_NODE) { XmlElement otherChildNode = new XmlElement((Element) potentialNode, mDocument); if (childNode.getType() == otherChildNode.getType()) { // check if this element uses a key. if (childNode.getType().getNodeKeyResolver().getKeyAttributesNames() .isEmpty()) { // no key... try all the other elements, if we find one equal, we are done. message = childNode.compareTo(otherChildNode); if (!message.isPresent()) { return Optional.absent(); } } else { // key... if (childNode.getKey() == null) { // other key MUST also be null. if (otherChildNode.getKey() == null) { return childNode.compareTo(otherChildNode); } } else { if (childNode.getKey().equals(otherChildNode.getKey())) { return childNode.compareTo(otherChildNode); } } } } } } return message.isPresent() ? message : Optional.of(String.format("Child %1$s not found in document %2$s", childNode.getId(), otherElement.printPosition())); }
Example 14
Source Project: bullet File: ComponentMethodDescriptor.java License: Apache License 2.0 | 5 votes |
private static Optional<ComponentMethodDescriptor> methodDescriptor( ComponentMethodKind kind, DeclaredType type, ExecutableElement componentMethod) { // ObjectGraph API doesn't allow passing qualifier as input, so ignore those methods. if (hasQualifier(componentMethod)) { return Optional.absent(); } return Optional.<ComponentMethodDescriptor>of(new AutoValue_ComponentMethodDescriptor(kind, type, componentMethod.getSimpleName().toString())); }
Example 15
Source Project: distributedlog File: DistributedLogServerTestCase.java License: Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { dlServer = createDistributedLogServer(7001); Optional<String> serverSideRoutingFinagleName = Optional.absent(); if (!clientSideRouting) { serverSideRoutingFinagleName = Optional.of("inet!" + DLSocketAddress.toString(dlServer.getAddress())); } dlClient = createDistributedLogClient("test", serverSideRoutingFinagleName); }
Example 16
Source Project: incubator-gobblin File: TestJobExecutionState.java License: Apache License 2.0 | 4 votes |
@Test public void testStateTransitionsSuccess() throws TimeoutException, InterruptedException { final Logger log = LoggerFactory.getLogger(getClass().getSimpleName() + ".testStateTransitionsSuccess"); JobSpec js1 = JobSpec.builder("gobblin:/testStateTransitionsSuccess/job1") .withConfig(ConfigFactory.empty() .withValue(ConfigurationKeys.JOB_NAME_KEY, ConfigValueFactory.fromAnyRef("myJob"))) .build(); JobExecution je1 = JobExecutionUpdatable.createFromJobSpec(js1); final JobExecutionStateListener listener = mock(JobExecutionStateListener.class); final JobExecutionState jes1 = new JobExecutionState(js1, je1, Optional.<JobExecutionStateListener>absent()); // Current state is null assertFailedStateTransition(jes1, RunningState.RUNNING); assertFailedStateTransition(jes1, RunningState.COMMITTED); assertFailedStateTransition(jes1, RunningState.SUCCESSFUL); assertFailedStateTransition(jes1, RunningState.FAILED); assertFailedStateTransition(jes1, RunningState.RUNNING); assertFailedStateTransition(jes1, RunningState.CANCELLED); assertTransition(jes1, listener, null, RunningState.PENDING, log); // Current state is PENDING assertFailedStateTransition(jes1, RunningState.PENDING); assertFailedStateTransition(jes1, RunningState.COMMITTED); assertFailedStateTransition(jes1, RunningState.SUCCESSFUL); assertTransition(jes1, listener, RunningState.PENDING, RunningState.RUNNING, log); // Current state is RUNNING assertFailedStateTransition(jes1, RunningState.PENDING); assertFailedStateTransition(jes1, RunningState.COMMITTED); assertFailedStateTransition(jes1, RunningState.RUNNING); assertTransition(jes1, listener, RunningState.RUNNING, RunningState.SUCCESSFUL, log); // Current state is SUCCESSFUL assertFailedStateTransition(jes1, RunningState.PENDING); assertFailedStateTransition(jes1, RunningState.RUNNING); assertFailedStateTransition(jes1, RunningState.SUCCESSFUL); assertTransition(jes1, listener, RunningState.SUCCESSFUL, RunningState.COMMITTED, log); // Current state is COMMITTED (final) assertFailedStateTransition(jes1, RunningState.RUNNING); assertFailedStateTransition(jes1, RunningState.COMMITTED); assertFailedStateTransition(jes1, RunningState.SUCCESSFUL); assertFailedStateTransition(jes1, RunningState.FAILED); assertFailedStateTransition(jes1, RunningState.RUNNING); assertFailedStateTransition(jes1, RunningState.CANCELLED); }
Example 17
Source Project: incubator-gobblin File: Orchestrator.java License: Apache License 2.0 | 4 votes |
/** Constructor with no logging */ public Orchestrator(Config config, Optional<TopologyCatalog> topologyCatalog) { this(config, topologyCatalog, Optional.<DagManager>absent(), Optional.<Logger>absent()); }
Example 18
Source Project: onedev File: Project.java License: MIT License | 4 votes |
/** * Read blob content and cache result in repository in case the same blob * content is requested again. * * We made this method thread-safe as we are using ForkJoinPool to calculate * diffs of multiple blob changes concurrently, and this method will be * accessed concurrently in that special case. * * @param blobIdent * ident of the blob * @return * blob of specified blob ident * @throws * ObjectNotFoundException if blob of specified ident can not be found in repository * */ @Nullable public Blob getBlob(BlobIdent blobIdent, boolean mustExist) { Preconditions.checkArgument(blobIdent.revision!=null && blobIdent.path!=null && blobIdent.mode!=null, "Revision, path and mode of ident param should be specified"); Optional<Blob> blob = getBlobCache().get(blobIdent); if (blob == null) { try (RevWalk revWalk = new RevWalk(getRepository())) { ObjectId revId = getObjectId(blobIdent.revision, mustExist); if (revId != null) { RevCommit commit = GitUtils.parseCommit(revWalk, revId); if (commit != null) { RevTree revTree = commit.getTree(); TreeWalk treeWalk = TreeWalk.forPath(getRepository(), blobIdent.path, revTree); if (treeWalk != null) { ObjectId blobId = treeWalk.getObjectId(0); if (blobIdent.isGitLink()) { String url = getSubmodules(blobIdent.revision).get(blobIdent.path); if (url == null) { if (mustExist) throw new ObjectNotFoundException("Unable to find submodule '" + blobIdent.path + "' in .gitmodules"); else blob = Optional.absent(); } else { String hash = blobId.name(); blob = Optional.of(new Blob(blobIdent, blobId, new Submodule(url, hash).toString().getBytes())); } } else if (blobIdent.isTree()) { throw new NotFileException("Path '" + blobIdent.path + "' is a tree"); } else { blob = Optional.of(new Blob(blobIdent, blobId, treeWalk.getObjectReader())); } } } } if (blob == null) { if (mustExist) throw new ObjectNotFoundException("Unable to find blob ident: " + blobIdent); else blob = Optional.absent(); } getBlobCache().put(blobIdent, blob); } catch (IOException e) { throw new RuntimeException(e); } } return blob.orNull(); }
Example 19
Source Project: digdag File: Storage.java License: Apache License 2.0 | 4 votes |
default Optional<DirectDownloadHandle> getDirectDownloadHandle(String key) { return Optional.absent(); }
Example 20
Source Project: incubator-gobblin File: QuartzJobSpecScheduler.java License: Apache License 2.0 | 4 votes |
public QuartzJobSpecScheduler(Logger log, Config cfg) { this(Optional.of(log), cfg, Optional.<SchedulerService>absent()); }