本文整理汇总了Java中com.google.common.base.Optional.isPresent方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.isPresent方法的具体用法?Java Optional.isPresent怎么用?Java Optional.isPresent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Optional
的用法示例。
在下文中一共展示了Optional.isPresent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EnumDefinition
import com.google.common.base.Optional; //导入方法依赖的package包/类
EnumDefinition(TypeElement element, String qualified, String simple) {
this.qualified = qualified;
this.simple = simple;
for (Element e : element.getEnclosedElements()) {
if (e.getKind() == ElementKind.ENUM_CONSTANT) {
Optional<OkNamedMirror> nameAnnotation = OkNamedMirror.find(e);
String name = e.getSimpleName().toString();
String jsonName = name;
if (nameAnnotation.isPresent()) {
String s = nameAnnotation.get().name();
// just ignore annotation with empty name
if (!s.isEmpty()) {
jsonName = s;
}
}
byFirstLetter.put(
jsonName.charAt(0),
new EnumConstant(name, jsonName));
}
}
}
示例2: Authority
import com.google.common.base.Optional; //导入方法依赖的package包/类
/** */
private Authority(
Optional<String> userName, Optional<String> password,
Optional<Object> host, int portOrNegOne,
IDNA.Info info) {
if (host.isPresent()) {
Object hostObj = host.get();
Preconditions.checkArgument(
hostObj instanceof InternetDomainName
|| hostObj instanceof Inet4Address
|| hostObj instanceof Inet6Address,
"Invalid host", hostObj);
}
this.userName = userName;
this.password = password;
this.host = host;
this.portOrNegOne = portOrNegOne;
this.info = info;
}
示例3: computeBreakAndSplit
import com.google.common.base.Optional; //导入方法依赖的package包/类
/** Lay out a Break-separated group of Docs in the current Level. */
private static State computeBreakAndSplit(
CommentsHelper commentsHelper,
int maxWidth,
State state,
Optional<Break> optBreakDoc,
List<Doc> split) {
float breakWidth = optBreakDoc.isPresent() ? optBreakDoc.get().getWidth() : 0.0F;
float splitWidth = getWidth(split);
boolean shouldBreak =
(optBreakDoc.isPresent() && optBreakDoc.get().fillMode == FillMode.UNIFIED)
|| state.mustBreak
|| state.column + breakWidth + splitWidth > maxWidth;
if (optBreakDoc.isPresent()) {
state = optBreakDoc.get().computeBreaks(state, state.lastIndent, shouldBreak);
}
boolean enoughRoom = state.column + splitWidth <= maxWidth;
state = computeSplit(commentsHelper, maxWidth, split, state.withMustBreak(false));
if (!enoughRoom) {
state = state.withMustBreak(true); // Break after, too.
}
return state;
}
示例4: addAnnotationParts
import com.google.common.base.Optional; //导入方法依赖的package包/类
private static void addAnnotationParts(final AssessedResponse assessedResponse,
final CorefAnnotation corefAnnotation, final List<String> parts) {
final ResponseAssessment ann = assessedResponse.assessment();
parts.add(FieldAssessment.asCharacterOrNil(ann.justificationSupportsEventType()));
parts.add(FieldAssessment.asCharacterOrNil(ann.justificationSupportsRole()));
parts.add(FieldAssessment.asCharacterOrNil(ann.entityCorrectFiller()));
parts.add(FieldAssessment.asCharacterOrNil(ann.baseFillerCorrect()));
final Optional<Integer> corefId = corefAnnotation.corefId(
assessedResponse.response().canonicalArgument());
if (corefId.isPresent()) {
parts.add(Integer.toString(corefId.get()));
} else {
parts.add("NIL");
}
parts.add(KBPRealis.asString(ann.realis()));
parts.add(FillerMentionType.stringOrNil(ann.mentionTypeOfCAS()));
}
示例5: isEmpty
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* Returns whether the source has zero chars. The default implementation returns true if
* {@link #lengthIfKnown} returns zero, falling back to opening a stream and checking for EOF if
* the length is not known.
*
* <p>Note that, in cases where {@code lengthIfKnown} returns zero, it is <i>possible</i> that
* chars are actually available for reading. This means that a source may return {@code true} from
* {@code isEmpty()} despite having readable content.
*
* @throws IOException if an I/O error occurs
* @since 15.0
*/
public boolean isEmpty() throws IOException {
Optional<Long> lengthIfKnown = lengthIfKnown();
if (lengthIfKnown.isPresent() && lengthIfKnown.get() == 0L) {
return true;
}
Closer closer = Closer.create();
try {
Reader reader = closer.register(openStream());
return reader.read() == -1;
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
示例6: systemEquivClassToAssessedRepresentativeResponses
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* Note this will not include system equivalence classes whose representative responses were
* unassessed.
*/
public ImmutableMap<EquivClassType, AssessedResponse> systemEquivClassToAssessedRepresentativeResponses() {
final ImmutableMap.Builder<EquivClassType, AssessedResponse> ret = ImmutableMap.builder();
for (final Map.Entry<EquivClassType, Collection<Response>> systemTRFR : equivalenceClassesToSystemResponses()
.asMap().entrySet()) {
final Response representativeResponse = systemOutput()
.selectFromMultipleSystemResponses(systemTRFR.getValue()).get();
final Optional<AssessedResponse> optAssessedRepResponse =
answerKey().assess(representativeResponse);
if (optAssessedRepResponse.isPresent()) {
ret.put(systemTRFR.getKey(), optAssessedRepResponse.get());
}
}
return ret.build();
}
示例7: getStorages
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) {
if (uri.isArchive()) {
URIBasedStorage storage = new URIBasedStorage(uri);
String authority = uri.authority();
URI archiveFileURI = URI.createURI(authority.substring(0, authority.length() - 1));
Optional<? extends IN4JSEclipseProject> optionalProject = eclipseCore.findProject(archiveFileURI);
if (optionalProject.isPresent()) {
return Collections.singletonList(Tuples.<IStorage, IProject> create(storage, optionalProject.get()
.getProject()));
} else {
return Collections.singletonList(Tuples.create(storage, null));
}
} else {
return Collections.emptyList();
}
}
示例8: getOptionalLinkingStore
import com.google.common.base.Optional; //导入方法依赖的package包/类
private static Optional<LinkingStore> getOptionalLinkingStore(final String linkingParam,
final Parameters params) throws FileNotFoundException {
final Optional<File> optLinkingAnnotationStoreDir = params.getOptionalExistingDirectory(
linkingParam);
final Optional<LinkingStore> optLinkingAnnotationStore;
if (optLinkingAnnotationStoreDir.isPresent()) {
optLinkingAnnotationStore = Optional.of(
LinkingStoreSource.createFor2015().openLinkingStore(optLinkingAnnotationStoreDir.get()));
} else {
optLinkingAnnotationStore = Optional.absent();
}
return optLinkingAnnotationStore;
}
示例9: loadAll
import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
* 获取所有注册的云作业配置.
*
* @return 注册的云作业配置
*/
public Collection<CloudJobConfiguration> loadAll() {
if (!regCenter.isExisted(CloudJobConfigurationNode.ROOT)) {
return Collections.emptyList();
}
List<String> jobNames = regCenter.getChildrenKeys(CloudJobConfigurationNode.ROOT);
Collection<CloudJobConfiguration> result = new ArrayList<>(jobNames.size());
for (String each : jobNames) {
Optional<CloudJobConfiguration> config = load(each);
if (config.isPresent()) {
result.add(config.get());
}
}
return result;
}
示例10: isRejected
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public boolean isRejected(IFolder folder) {
if (isLibraryFolder(folder)) {
return false;
}
Optional<? extends IN4JSSourceContainer> sourceContainerOpt = eclipseCore.create(folder);
return !sourceContainerOpt.isPresent();
}
示例11: handleSafely
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public boolean handleSafely(final Node node, YamlEmitter emitter) throws IOException {
Optional<NodeHandler<?>> handler = FluentIterable.from(handlerList).firstMatch(new Predicate<NodeHandler<? extends Node>>() {
@Override
public boolean apply(@Nullable NodeHandler<? extends Node> nodeHandler) {
return nodeHandler.handles(node);
}
});
return handler.isPresent() && handler.get().handle(node, emitter);
}
示例12: extractScoringEntity
import com.google.common.base.Optional; //导入方法依赖的package包/类
static ScoringCorefID extractScoringEntity(EREArgument ea, EREDocument ereDoc) {
if (ea instanceof EREEntityArgument) {
final Optional<EREEntity> entityContainingMention = ereDoc.getEntityContaining(
((EREEntityArgument) ea).entityMention());
if (entityContainingMention.isPresent()) {
return new ScoringCorefID.Builder()
.scoringEntityType(ScoringEntityType.fromCASType(
EREAligner.getBestCASType(entityContainingMention.get())))
.withinTypeID(entityContainingMention.get().getID()).build();
} else {
throw new TACKBPEALException("ERE mention not in any entity");
}
} else if (ea instanceof EREFillerArgument) {
if (ea.getRole().equals("time")) {
// in the 2016 guidelines we special case time to be resolved to its
// TIME form
final Optional<String> normalizedTime =
((EREFillerArgument) ea).filler().getNormalizedTime();
if (normalizedTime.isPresent()) {
return new ScoringCorefID.Builder().scoringEntityType(ScoringEntityType.Time)
.withinTypeID(normalizedTime.get()).build();
} else {
throw new TACKBPEALException("Time argument has non-temporal filler");
}
} else {
return new ScoringCorefID.Builder().scoringEntityType(ScoringEntityType.Filler)
.withinTypeID(((EREFillerArgument) ea).filler().getID()).build();
}
} else {
throw new TACKBPEALException("Unknown ERE argument type " + ea.getClass());
}
}
示例13: getUserWithDevices
import com.google.common.base.Optional; //导入方法依赖的package包/类
public Optional<User> getUserWithDevices(long id)
{
Optional<User> optionalUser = find(id);
if(optionalUser.isPresent())
Hibernate.initialize(optionalUser.get().getDevices());
return optionalUser;
}
示例14: checkAnnotationConstraintError
import com.google.common.base.Optional; //导入方法依赖的package包/类
protected static Optional<String> checkAnnotationConstraintError(Object objectToValidate, Field field,
Annotation annotation) {
try {
field.setAccessible(true);
Object fieldValue = field.get(objectToValidate);
Optional<String> errorOpt = checkErrorInFieldForAnnotation(annotation, fieldValue);
if (errorOpt.isPresent())
return Optional.of(String.format("Field '%s' %s", field.getName(), errorOpt.get()));
return errorOpt;
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new InternalException(e);
}
}
示例15: onDrop
import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public void onDrop(DropEvent event) {
Optional<DragDataObject> objectFromEvent = objectFromEventExtractor.extractDroppedObjectFromEvent(event);
if (objectFromEvent.isPresent()) {
DragDataObject dataObject = objectFromEvent.get();
sourceListPresenter.onDropEvent(dataObject.getItemId(), dataObject.getSourceId());
}
}