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

The following are Jave code examples for showing how to use of() 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: javaide   File: XmlDocument.java   View Source Code Vote up 6 votes
/**
 * 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());
}
 
Example 2
Project: flume-release-1.7.0   File: KafkaChannel.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: SECP   File: UserResourceTest.java   View Source Code Vote up 6 votes
@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);
}
 
Example 4
Project: guava-mock   File: MediaType.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 5
Project: HCFCore   File: PlayerLeaveFactionEvent.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: dremio-oss   File: CachedMaterializationProvider.java   View Source Code Vote up 5 votes
@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();
  }
}
 
Example 7
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 8
Project: dremio-oss   File: AccelerationServiceImpl.java   View Source Code Vote up 5 votes
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();
  }
}
 
Example 9
Project: satisfy   File: SatisfyAnnotatedStepDescription.java   View Source Code Vote up 5 votes
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();
}
 
Example 10
Project: TakinRPC   File: ServerController.java   View Source Code Vote up 5 votes
@Override
public void setFailed(String reason) {
    lock.writeLock().lock();
    try {
        failed = Optional.of(reason);
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example 11
Project: CustomWorldGen   File: TRSRTransformation.java   View Source Code Vote up 5 votes
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
{
    if(part.isPresent())
    {
        return Optional.absent();
    }
    return Optional.of(this);
}
 
Example 12
Project: SECP   File: UserResourceTest.java   View Source Code Vote up 5 votes
@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);
}
 
Example 13
Project: AndZilla   File: LifecycleProcessor.java   View Source Code Vote up 5 votes
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();
}
 
Example 14
Project: cucumber-framework-java   File: WebDriverUtils.java   View Source Code Vote up 5 votes
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();
    }
}
 
Example 15
Project: JAMCore   File: OptionalImplementations.java   View Source Code Vote up 4 votes
public static void setBrowserStorageImplementation(HasBrowserStorageMethod browserStorageImplementation) {
	BrowserStorageImplementation =  Optional.of(browserStorageImplementation);
}
 
Example 16
Project: Elasticsearch   File: DocKeys.java   View Source Code Vote up 4 votes
public Optional<Long> version() {
    if (withVersions && key.get(width) != null) {
        return Optional.of((Long) ((Literal) key.get(width)).value());
    }
    return Optional.absent();
}
 
Example 17
Project: verify-hub   File: EidasMatchingServiceResourceIntegrationTest.java   View Source Code Vote up 4 votes
private void stubSamlEngineTranslationLOAForCountry(final LevelOfAssurance loa, final EidasCountryDto country) throws Exception {
    samlEngineStub.reset();
    InboundResponseFromCountry translationDto = new InboundResponseFromCountry(IdpIdaStatus.Status.Success, Optional.absent(), country.getEntityId(), Optional.of("BLOB"), Optional.of("PID"), Optional.of(loa));
    samlEngineStub.setupStubForCountryAuthnResponseTranslate(translationDto);
}
 
Example 18
Project: CustomWorldGen   File: PropertyBool.java   View Source Code Vote up 4 votes
public Optional<Boolean> parseValue(String value)
{
    return !"true".equals(value) && !"false".equals(value) ? Optional.<Boolean>absent() : Optional.of(Boolean.valueOf(value));
}
 
Example 19
Project: JAMCore   File: OptionalImplementations.java   View Source Code Vote up 4 votes
/**
 * Sets the class that handles old CuypersCode game functions, if any.
 **/
public static void SetImagePreloadFunctions(HasImagePreloading impl)
{
	ImagePreloader =  Optional.of(impl);		 
}
 
Example 20
Project: JAMCore   File: OptionalImplementations.java   View Source Code Vote up 4 votes
/**
 * Sets the class that handles old CuypersCode game functions, if any.
 */
public static void SetCuypersCodeSpecificFunctions(JamCuypersCodeSpecificFunctions impl)
{
	CuypersCodeFunctionsImplementation =  Optional.of(impl);		 
}