当前位置: 首页>>代码示例>>Java>>正文


Java Optional.orNull方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:AccessorAttributesCollector.java

示例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;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:20,代码来源:Project.java

示例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);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:DefaultServiceRegistry.java

示例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);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:DefaultServiceRegistry.java

示例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();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:38,代码来源:ProtocolToModelAdapter.java

示例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();
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:15,代码来源:FeedbackRegistry.java

示例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());
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:10,代码来源:StrictAssessmentCreator.java

示例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();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:CrateSearchContext.java

示例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();
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:27,代码来源:Project.java

示例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();
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:16,代码来源:Project.java

示例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();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:9,代码来源:AccelerationManagerImpl.java

示例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;
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:32,代码来源:LocalJobsService.java

示例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());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:11,代码来源:ShardTransaction.java

示例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();
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:7,代码来源:SourcelistManagerModel.java

示例15: fromCorefOnly

import com.google.common.base.Optional; //导入方法依赖的package包/类
public static AssessmentParseResult fromCorefOnly(Optional<Integer> corefId) {
  return new AssessmentParseResult(null, corefId.orNull());
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:4,代码来源:AssessmentCreator.java


注:本文中的com.google.common.base.Optional.orNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。