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


Java Optional.of方法代码示例

本文整理汇总了Java中com.google.common.base.Optional.of方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.of方法的具体用法?Java Optional.of怎么用?Java Optional.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.base.Optional的用法示例。


在下文中一共展示了Optional.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: merge

import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
 * merge this higher priority document with a higher priority document.
 * @param lowerPriorityDocument the lower priority document to merge in.
 * @param mergingReportBuilder the merging report to record errors and actions.
 * @return a new merged {@link XmlDocument} or
 * {@link Optional#absent()} if there were errors during the merging activities.
 */
public Optional<XmlDocument> merge(
        XmlDocument lowerPriorityDocument,
        MergingReport.Builder mergingReportBuilder) {

    if (getFileType() == Type.MAIN) {
        mergingReportBuilder.getActionRecorder().recordDefaultNodeAction(getRootNode());
    }

    getRootNode().mergeWithLowerPriorityNode(
            lowerPriorityDocument.getRootNode(), mergingReportBuilder);

    addImplicitElements(lowerPriorityDocument, mergingReportBuilder);

    // force re-parsing as new nodes may have appeared.
    return mergingReportBuilder.hasErrors()
            ? Optional.<XmlDocument>absent()
            : Optional.of(reparse());
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:XmlDocument.java

示例2: deserializeValue

import com.google.common.base.Optional; //导入方法依赖的package包/类
private Event deserializeValue(byte[] value, boolean parseAsFlumeEvent) throws IOException {
  Event e;
  if (parseAsFlumeEvent) {
    ByteArrayInputStream in =
            new ByteArrayInputStream(value);
    decoder = DecoderFactory.get().directBinaryDecoder(in, decoder);
    if (!reader.isPresent()) {
      reader = Optional.of(
              new SpecificDatumReader<AvroFlumeEvent>(AvroFlumeEvent.class));
    }
    AvroFlumeEvent event = reader.get().read(null, decoder);
    e = EventBuilder.withBody(event.getBody().array(),
            toStringMap(event.getHeaders()));
  } else {
    e = EventBuilder.withBody(value, Collections.EMPTY_MAP);
  }
  return e;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:19,代码来源:KafkaChannel.java

示例3: testModifyUserWithValidParameters

import com.google.common.base.Optional; //导入方法依赖的package包/类
@Test
public void testModifyUserWithValidParameters()
{
    //test user modify with invalid id
    UserDTO userDTO = createUser();
    Permission permission = new Permission(userDTO.getPermission().getName());
    permission.setId(1);

    Role roleObj = new Role(role);
    roleObj.setId(1);

    User user = new User();
    user.setId(1);

    Optional<Permission> permissionFromDB = Optional.of(permission);
    Mockito.when(permissionDAO.find(1)).thenReturn(permissionFromDB);
    Optional<Role> roleFromDB = Optional.of(roleObj);
    Mockito.when(rolesDAO.find(1)).thenReturn(roleFromDB);
    Optional<User> userFromDB = Optional.of(user);
    Mockito.when(userDAO.find(userID)).thenReturn(userFromDB);

    Response response = resources.client().target(modifyUrl).request().post(Entity.json(userDTO));
    ResponseValidator.validate(response, 200);
}
 
开发者ID:tosinoni,项目名称:SECP,代码行数:25,代码来源:UserResourceTest.java

示例4: charset

import com.google.common.base.Optional; //导入方法依赖的package包/类
/**
 * Returns an optional charset for the value of the charset parameter if it is specified.
 *
 * @throws IllegalStateException if multiple charset values have been set for this media type
 * @throws IllegalCharsetNameException if a charset value is present, but illegal
 * @throws UnsupportedCharsetException if a charset value is present, but no support is available
 *     in this instance of the Java virtual machine
 */
public Optional<Charset> charset() {
  // racy single-check idiom, this is safe because Optional is immutable.
  Optional<Charset> local = parsedCharset;
  if (local == null) {
    String value = null;
    local = Optional.absent();
    for (String currentValue : parameters.get(CHARSET_ATTRIBUTE)) {
      if (value == null) {
        value = currentValue;
        local = Optional.of(Charset.forName(value));
      } else if (!value.equals(currentValue)) {
        throw new IllegalStateException(
            "Multiple charset values defined: " + value + ", " + currentValue);
      }
    }
    parsedCharset = local;
  }
  return local;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:28,代码来源:MediaType.java

示例5: PlayerLeaveFactionEvent

import com.google.common.base.Optional; //导入方法依赖的package包/类
public PlayerLeaveFactionEvent(CommandSender sender, @Nullable Player player, UUID playerUUID, PlayerFaction playerFaction, FactionLeaveCause cause, boolean isKick, boolean force) {
    super(playerFaction);

    Preconditions.checkNotNull(sender, "Sender cannot be null");
    Preconditions.checkNotNull(playerUUID, "Player UUID cannot be null");
    Preconditions.checkNotNull(playerFaction, "Player faction cannot be null");
    Preconditions.checkNotNull(cause, "Cause cannot be null");

    this.sender = sender;
    if (player != null) {
        this.player = Optional.of(player);
    }

    this.uniqueID = playerUUID;
    this.cause = cause;
    this.isKick = isKick;
    this.force = force;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:19,代码来源:PlayerLeaveFactionEvent.java

示例6: get

import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public Optional<MaterializationDescriptor> get(String materializationId) {
  MaterializationDescriptor descriptor = cached.get().get(materializationId);
  if (descriptor!= null && descriptor.isComplete()) {
    return Optional.of(descriptor);
  } else {
   return Optional.absent();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:CachedMaterializationProvider.java

示例7: 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

示例8: getEffectiveMaterialization

import com.google.common.base.Optional; //导入方法依赖的package包/类
Optional<Materialization> getEffectiveMaterialization(final Layout layout) {
  MaterializationWrapper materializationInfo = Iterables.getFirst(getEffectiveMaterialization(layout, getActiveHosts(), false), null);
  if (materializationInfo != null) {
    return Optional.of(materializationInfo.getMaterialization());
  } else {
    return Optional.absent();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:9,代码来源:AccelerationServiceImpl.java

示例9: getNameFromStepAnnotationIn

import com.google.common.base.Optional; //导入方法依赖的package包/类
private Optional<String> getNameFromStepAnnotationIn(final Method
                                                             testMethod) {
    Step step = testMethod.getAnnotation(Step.class);

    if ((step != null) && (!StringUtils.isEmpty(step.value()))) {
        return Optional.of(step.value());
    }
    return Optional.absent();
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:10,代码来源:SatisfyAnnotatedStepDescription.java

示例10: setFailed

import com.google.common.base.Optional; //导入方法依赖的package包/类
@Override
public void setFailed(String reason) {
    lock.writeLock().lock();
    try {
        failed = Optional.of(reason);
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:10,代码来源:ServerController.java

示例11: apply

import com.google.common.base.Optional; //导入方法依赖的package包/类
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
{
    if(part.isPresent())
    {
        return Optional.absent();
    }
    return Optional.of(this);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:9,代码来源:TRSRTransformation.java

示例12: testIsUserAnAdminWithInvalidID

import com.google.common.base.Optional; //导入方法依赖的package包/类
@Test
public void testIsUserAnAdminWithInvalidID()
{
    long id = 12;
    Optional<User> user = Optional.of(new User());
    Mockito.when(userDAO.find(id)).thenReturn(user);
    Response response = resources.client().target(isUserAnAdminUrl + id).request().get();
    ResponseValidator.validate(response, 204);
}
 
开发者ID:tosinoni,项目名称:SECP,代码行数:10,代码来源:UserResourceTest.java

示例13: getAnnotationMirror

import com.google.common.base.Optional; //导入方法依赖的package包/类
public static Optional<AnnotationMirror> getAnnotationMirror(Element element,
                                                             Class<? extends Annotation> annotationClass) {
    String annotationClassName = annotationClass.getCanonicalName();
    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        TypeElement annotationTypeElement = asType(annotationMirror.getAnnotationType().asElement());
        if (annotationTypeElement.getQualifiedName().contentEquals(annotationClassName)) {
            return Optional.of(annotationMirror);
        }
    }
    return Optional.absent();
}
 
开发者ID:zillachan,项目名称:AndZilla,代码行数:12,代码来源:LifecycleProcessor.java

示例14: elementExists

import com.google.common.base.Optional; //导入方法依赖的package包/类
public static Optional<WebElement> elementExists( WebDriver driver, By locator )
{
    List<WebElement> list = driver.findElements( locator );
    if( list.size() == 1 )
    {
        return Optional.of( list.get( 0 ) );
    } else if( list.isEmpty() )
    {
        return Optional.absent();
    } else
    {
        throw new NotUniqueItemException();
    }
}
 
开发者ID:hemano,项目名称:cucumber-framework-java,代码行数:15,代码来源:WebDriverUtils.java

示例15: setBrowserStorageImplementation

import com.google.common.base.Optional; //导入方法依赖的package包/类
public static void setBrowserStorageImplementation(HasBrowserStorageMethod browserStorageImplementation) {
	BrowserStorageImplementation =  Optional.of(browserStorageImplementation);
}
 
开发者ID:ThomasWrobel,项目名称:JAMCore,代码行数:4,代码来源:OptionalImplementations.java


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