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