當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。