本文整理汇总了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());
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
}
示例15: setBrowserStorageImplementation
import com.google.common.base.Optional; //导入方法依赖的package包/类
public static void setBrowserStorageImplementation(HasBrowserStorageMethod browserStorageImplementation) {
BrowserStorageImplementation = Optional.of(browserStorageImplementation);
}