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


Java Optional.isPresent方法代码示例

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

示例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;
}
 
开发者ID:OWASP,项目名称:url-classifier,代码行数:21,代码来源:Authority.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:25,代码来源:Doc.java

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

示例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();
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:28,代码来源:CharSource.java

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

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

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

示例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;
}
 
开发者ID:elasticjob,项目名称:elastic-job-cloud,代码行数:20,代码来源:CloudJobConfigurationService.java

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

示例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);

}
 
开发者ID:mulesoft-labs,项目名称:raml-java-tools,代码行数:14,代码来源:HandlerList.java

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

示例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;
}
 
开发者ID:tosinoni,项目名称:SECP,代码行数:9,代码来源:UserDAO.java

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

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


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