Java Code Examples for com.google.common.base.Optional.orNull()

The following are Jave code examples for showing how to use orNull() of the com.google.common.base.Optional class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: AccessorAttributesCollector.java   View Source Code Vote up 6 votes
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;
}
 
Example 2
Project: gitplex-mit   File: Project.java   View Source Code Vote up 6 votes
@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;
}
 
Example 3
Project: Reer   File: DefaultServiceRegistry.java   View Source Code Vote up 5 votes
@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);
}
 
Example 4
Project: Reer   File: DefaultServiceRegistry.java   View Source Code Vote up 5 votes
@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);
}
 
Example 5
Project: Reer   File: ProtocolToModelAdapter.java   View Source Code Vote up 5 votes
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();
    }
}
 
Example 6
Project: empiria.player   File: FeedbackRegistry.java   View Source Code Vote up 5 votes
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();
}
 
Example 7
Project: tac-kbp-eal   File: StrictAssessmentCreator.java   View Source Code Vote up 5 votes
@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());
}
 
Example 8
Project: Elasticsearch   File: CrateSearchContext.java   View Source Code Vote up 5 votes
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();
}
 
Example 9
Project: gitplex-mit   File: Project.java   View Source Code Vote up 5 votes
/**
 * 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();
}
 
Example 10
Project: gitplex-mit   File: Project.java   View Source Code Vote up 5 votes
@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();
}
 
Example 11
Project: dremio-oss   File: AccelerationManagerImpl.java   View Source Code Vote up 5 votes
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();
}
 
Example 12
Project: dremio-oss   File: LocalJobsService.java   View Source Code Vote up 5 votes
@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;
  }
}
 
Example 13
Project: hashsdn-controller   File: ShardTransaction.java   View Source Code Vote up 5 votes
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());
}
 
Example 14
Project: empiria.player   File: SourcelistManagerModel.java   View Source Code Vote up 4 votes
public SourcelistClient getClientById(String clientId) {
    String sourcelistId = clientIdToSourcelistIdCache.get(clientId);
    SourcelistGroup group = groups.get(sourcelistId);
    Optional<SourcelistClient> optionalClient = group.getClientById(clientId);
    return optionalClient.orNull();
}
 
Example 15
Project: tac-kbp-eal   File: AssessmentCreator.java   View Source Code Vote up 4 votes
public static AssessmentParseResult fromCorefOnly(Optional<Integer> corefId) {
  return new AssessmentParseResult(null, corefId.orNull());
}
 
Example 16
Project: ide-plugins   File: ProjectImportWizardController.java   View Source Code Vote up 4 votes
private GradleDistributionWrapper createGradleDistribution(Optional<String> gradleDistributionType, Optional<String> gradleDistributionConfiguration) {
    DistributionType distributionType = DistributionType.valueOf(gradleDistributionType.or(DistributionType.WRAPPER.name()));
    String distributionConfiguration = gradleDistributionConfiguration.orNull();
    return GradleDistributionWrapper.from(distributionType, distributionConfiguration);
}
 
Example 17
Project: guava-mock   File: CacheBuilderFactory.java   View Source Code Vote up 4 votes
@Override public Object apply(Optional<?> optional) {
  return optional.orNull();
}
 
Example 18
Project: googles-monorepo-demo   File: CacheBuilderFactory.java   View Source Code Vote up 4 votes
@Override public Object apply(Optional<?> optional) {
  return optional.orNull();
}