本文整理汇总了Java中com.google.common.base.Optional.orNull方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.orNull方法的具体用法?Java Optional.orNull怎么用?Java Optional.orNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Optional
的用法示例。
在下文中一共展示了Optional.orNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: returnsNormalizedAbstractValueType
import com.google.common.base.Optional; //导入方法依赖的package包/类
private boolean returnsNormalizedAbstractValueType(ExecutableElement validationMethodCandidate) {
Optional<DeclaringType> declaringType = protoclass.declaringType();
if (declaringType.isPresent()) {
TypeStringProvider provider = new TypeStringProvider(
reporter,
validationMethodCandidate,
validationMethodCandidate.getReturnType(),
new ImportsTypeStringResolver(declaringType.orNull(), declaringType.orNull()),
protoclass.constitution().generics().vars(),
null);
provider.process();
String returnTypeName = provider.returnTypeName();
return protoclass.constitution().typeAbstract().toString().equals(returnTypeName);
}
return false;
}
示例2: getRevCommit
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Nullable
public RevCommit getRevCommit(ObjectId revId, boolean mustExist) {
if (commitCache == null)
commitCache = new HashMap<>();
RevCommit commit;
Optional<RevCommit> optional = commitCache.get(revId);
if (optional == null) {
try (RevWalk revWalk = new RevWalk(getRepository())) {
optional = Optional.fromNullable(GitUtils.parseCommit(revWalk, revId));
}
commitCache.put(revId, optional);
}
commit = optional.orNull();
if (mustExist && commit == null)
throw new ObjectNotFoundException("Unable to find commit associated with object id: " + revId);
else
return commit;
}
示例3: getService
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public ServiceProvider getService(LookupContext context, TypeSpec serviceType) {
Optional<ServiceProvider> cached = seen.get(serviceType);
if (cached != null) {
return cached.orNull();
}
ServiceProvider service = delegate.getService(context, serviceType);
return cacheServiceProvider(serviceType, service);
}
示例4: getFactory
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public ServiceProvider getFactory(LookupContext context, Class<?> type) {
Optional<ServiceProvider> cached = seen.get(type);
if (cached != null) {
return cached.orNull();
}
ServiceProvider service = delegate.getFactory(context, type);
return cacheServiceProvider(type, service);
}
示例5: get
import com.google.common.base.Optional; //导入方法依赖的package包/类
public Method get(MethodInvocation invocation) {
Class<?> owner = invocation.getDelegate().getClass();
String name = invocation.getName();
Class<?>[] parameterTypes = invocation.getParameterTypes();
MethodInvocationKey key = new MethodInvocationKey(
owner,
name,
parameterTypes
);
lock.readLock().lock();
Optional<Method> cached = store.get(key);
if (cached == null) {
cacheMiss++;
lock.readLock().unlock();
lock.writeLock().lock();
try {
cached = store.get(key);
if (cached == null) {
cached = lookup(owner, name, parameterTypes);
if (cacheMiss % 10 == 0) {
removeDirtyEntries();
}
store.put(key, cached);
}
lock.readLock().lock();
} finally {
lock.writeLock().unlock();
}
} else {
cacheHit++;
}
try {
return cached.orNull();
} finally {
lock.readLock().unlock();
}
}
示例6: getFeedbacksElement
import com.google.common.base.Optional; //导入方法依赖的package包/类
private Element getFeedbacksElement(Node moduleNode) {
Optional<Element> feedbackElement = Optional.absent();
NodeList moduleChildNodes = moduleNode.getChildNodes();
for (int i = 0; i < moduleChildNodes.getLength(); i++) {
Node child = moduleChildNodes.item(i);
if (NAME_FEEDBACKS.equals(child.getNodeName())) {
feedbackElement = Optional.of((Element) child);
break;
}
}
return feedbackElement.orNull();
}
示例7: createAssessmentFromFields
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public AssessmentParseResult createAssessmentFromFields(Optional<FieldAssessment> aet,
Optional<FieldAssessment> aer, Optional<FieldAssessment> casAssessment,
Optional<KBPRealis> realis,
Optional<FieldAssessment> baseFillerAssessment, Optional<Integer> coreference,
Optional<FillerMentionType> mentionTypeOfCAS) {
return new AssessmentParseResult(ResponseAssessment.of(aet, aer, casAssessment, realis,
baseFillerAssessment, mentionTypeOfCAS), coreference.orNull());
}
示例8: CrateSearchShardRequest
import com.google.common.base.Optional; //导入方法依赖的package包/类
private CrateSearchShardRequest(long nowInMillis, Optional<Scroll> scroll,
IndexShard indexShard) {
this.nowInMillis = nowInMillis;
this.scroll = scroll.orNull();
this.index = indexShard.indexService().index().name();
this.shardId = indexShard.shardId().id();
}
示例9: getObjectId
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* Get cached object id of specified revision.
*
* @param revision
* revision to resolve object id for
* @param mustExist
* true to have the method throwing exception instead
* of returning null if the revision does not exist
* @return
* object id of specified revision, or <tt>null</tt> if revision
* does not exist and mustExist is specified as false
*/
@Nullable
public ObjectId getObjectId(String revision, boolean mustExist) {
if (objectIdCache == null)
objectIdCache = new HashMap<>();
Optional<ObjectId> optional = objectIdCache.get(revision);
if (optional == null) {
optional = Optional.fromNullable(GitUtils.resolve(getRepository(), revision));
objectIdCache.put(revision, optional);
}
if (mustExist && !optional.isPresent())
throw new ObjectNotFoundException("Unable to find object '" + revision + "'");
return optional.orNull();
}
示例10: getRef
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Nullable
public Ref getRef(String revision) {
if (refCache == null)
refCache = new HashMap<>();
Optional<Ref> optional = refCache.get(revision);
if (optional == null) {
try {
optional = Optional.fromNullable(getRepository().findRef(revision));
} catch (IOException e) {
throw new RuntimeException(e);
}
refCache.put(revision, optional);
}
return optional.orNull();
}
示例11: get
import com.google.common.base.Optional; //导入方法依赖的package包/类
private AccelerationEntry get(List<String> path, boolean raiseErrorIfNotFound) {
Optional<AccelerationEntry> entry = accelService.getAccelerationEntryByDataset(new NamespaceKey(path));
if(!entry.isPresent() && raiseErrorIfNotFound){
throw UserException.validationError().message("Table is not currently accelerated.").build(logger);
}
return entry.orNull();
}
示例12: getProfile
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public QueryProfile getProfile(JobId jobId, int attempt) throws JobNotFoundException {
Job job = getJob(jobId);
final AttemptId attemptId = new AttemptId(JobsServiceUtil.getJobIdAsExternalId(jobId), attempt);
if(jobIsDone(job.getJobAttempt())){
return profileStore.get(attemptId);
}
// Check if the profile for given attempt already exists. Even if the job is not done, it is possible that
// profile exists for previous attempts
final QueryProfile queryProfile = profileStore.get(attemptId);
if (queryProfile != null) {
return queryProfile;
}
final NodeEndpoint endpoint = job.getJobAttempt().getEndpoint();
if(endpoint.equals(identity)){
final ForemenTool tool = this.foremenTool.get();
Optional<QueryProfile> profile = tool.getProfile(attemptId.getExternalId());
return profile.orNull();
}
try{
CoordTunnel tunnel = coordTunnelCreator.get().getTunnel(JobsServiceUtil.toPB(endpoint));
return tunnel.requestQueryProfile(attemptId.getExternalId()).checkedGet(15, TimeUnit.SECONDS);
}catch(TimeoutException | RpcException | RuntimeException e){
logger.info("Unable to retrieve remote query profile for external id: {}",
ExternalIdHelper.toString(attemptId.getExternalId()), e);
return null;
}
}
示例13: readData
import com.google.common.base.Optional; //导入方法依赖的package包/类
protected void readData(final AbstractShardDataTreeTransaction<?> transaction, final ReadData message) {
if (checkClosed(transaction)) {
return;
}
final YangInstanceIdentifier path = message.getPath();
Optional<NormalizedNode<?, ?>> optional = transaction.getSnapshot().readNode(path);
ReadDataReply readDataReply = new ReadDataReply(optional.orNull(), message.getVersion());
sender().tell(readDataReply.toSerializable(), self());
}
示例14: getClientById
import com.google.common.base.Optional; //导入方法依赖的package包/类
public SourcelistClient getClientById(String clientId) {
String sourcelistId = clientIdToSourcelistIdCache.get(clientId);
SourcelistGroup group = groups.get(sourcelistId);
Optional<SourcelistClient> optionalClient = group.getClientById(clientId);
return optionalClient.orNull();
}
示例15: fromCorefOnly
import com.google.common.base.Optional; //导入方法依赖的package包/类
public static AssessmentParseResult fromCorefOnly(Optional<Integer> corefId) {
return new AssessmentParseResult(null, corefId.orNull());
}