本文整理汇总了Java中java.util.Optional.of方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.of方法的具体用法?Java Optional.of怎么用?Java Optional.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Optional
的用法示例。
在下文中一共展示了Optional.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getElementType
import java.util.Optional; //导入方法依赖的package包/类
/**
* @return the array or Collection underlying element type for the Class object.
*/
public Optional<ClassAttributes> getElementType() {
if (isArray()) {
return Optional.of(create(clazz));
}
if (isCollection()) {
List<Class<?>> parameterizedTypes = getParameterizedTypes();
if (!parameterizedTypes.isEmpty()) {
Class<?> first = parameterizedTypes.get(0);
if (first != null) {
return Optional.of(create(first));
}
}
}
return Optional.empty();
}
示例2: DestroyableFactoryImpl
import java.util.Optional; //导入方法依赖的package包/类
public DestroyableFactoryImpl(String name,
@Nullable Boolean required,
boolean visible,
TeamFactory owner,
ProximityMetric proximityMetric,
Region region,
Set<MaterialPattern> materials,
double destructionRequired,
boolean modeChanges,
boolean showProgress,
boolean sparks,
boolean repairable) {
super(name, required, visible, Optional.of(owner), proximityMetric);
this.region = region;
this.materials = materials;
this.destructionRequired = destructionRequired;
this.modeChanges = modeChanges;
this.showProgress = showProgress;
this.sparks = sparks;
this.repairable = repairable;
}
示例3: visitRevoke
import java.util.Optional; //导入方法依赖的package包/类
@Override
public Node visitRevoke(SqlBaseParser.RevokeContext context)
{
Optional<List<String>> privileges;
if (context.ALL() != null) {
privileges = Optional.empty();
}
else {
privileges = Optional.of(context.privilege().stream()
.map(SqlBaseParser.PrivilegeContext::getText)
.collect(toList()));
}
return new Revoke(
getLocation(context),
context.OPTION() != null,
privileges,
context.TABLE() != null,
getQualifiedName(context.qualifiedName()),
(Identifier) visit(context.grantee));
}
示例4: transform
import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<ClassVisitor> transform(String className, ClassVisitor writer, Runnable modifiedCallback) {
return Optional.of(new ClassVisitor(ASM5, writer) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return new MethodVisitor(ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {
@Override
public void visitLdcInsn(Object cst) {
if (cst instanceof String) {
Optional<String> transformed = ldcMapper.apply((String) cst);
if (transformed.isPresent() && !transformed.get().equals(cst)) {
modifiedCallback.run();
log("transform [{0}] to [{1}]", cst, transformed.get());
super.visitLdcInsn(transformed.get());
} else {
super.visitLdcInsn(cst);
}
} else {
super.visitLdcInsn(cst);
}
}
};
}
});
}
示例5: validate
import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<ValidationErrors> validate(Object o) {
ValidationErrors errors = new ValidationErrors();
TransportCreateDTO dto = (TransportCreateDTO) o;
addressValidator.validate("placeOfLoad", dto.getPlaceOfLoad(), errors);
addressValidator.validate("placeOfUnload", dto.getPlaceOfUnload(), errors);
cargoValidator.validate("cargo", dto.getCargo(), errors);
localDateValidator.validate("timeOfLoad", dto.getTimeOfLoad(), errors);
localDateValidator.validate("timeOfUnload", dto.getTimeOfUnload(), errors);
longValidator.validate("startingPrice", dto.getStartingPrice(), errors);
return errors.getErrors().isEmpty() ? Optional.empty() : Optional.of(errors);
}
示例6: deserializesDoubleDueToTypeErasure
import java.util.Optional; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void deserializesDoubleDueToTypeErasure() {
Optional<Integer> initialValue = Optional.of(1);
Class<Optional<Integer>> valueType = (Class<Optional<Integer>>)
initialValue.getClass();
Optional<Integer> readValue = writeThenRead(initialValue, valueType);
assertThat(readValue, is(not(initialValue)));
assertThat(readValue, is(Optional.of(1.0))); // (*)
}
示例7: setCompilable
import java.util.Optional; //导入方法依赖的package包/类
private void setCompilable(int level, boolean value) {
check(level);
compile[level] = Optional.of(value);
if (!value) {
setDontInline(level);
}
}
示例8: firstNonNullOrEmpty
import java.util.Optional; //导入方法依赖的package包/类
/**
* Returns an {@link Optional} of the first non-null Object found within the given objects.
*
* @param objects
* objects to get the first non-null from
* @return first non-null object or an empty {@link Optional}
*/
@SafeVarargs
public static <T> Optional<T> firstNonNullOrEmpty(final T... objects) {
for (final T t : objects) {
if (Objects.nonNull(t)) {
return Optional.of(t);
}
}
return Optional.empty();
}
示例9: getGcId
import java.util.Optional; //导入方法依赖的package包/类
private static Optional<Long> getGcId(String line, Pattern pattern) {
Matcher number = pattern.matcher(line);
if (number.find()) {
return Optional.of(Long.parseLong(number.group(1)));
}
return Optional.empty();
}
示例10: selectByShard
import java.util.Optional; //导入方法依赖的package包/类
@Override
public <DaoT> Optional<DaoT> selectByShard(Class<DaoT> daoClazz, ShardIdT shardId) {
DAOMapKey<ShardIdT, DaoT> key = ImmutableDAOMapKey.<ShardIdT, DaoT>builder()
.daoClazz(daoClazz)
.shardId(shardId)
.build();
if (daoMap.containsKey(key)) {
return Optional.of(daoClazz.cast(daoMap.get(key)));
}
return Optional.empty();
}
示例11: maybeBuild
import java.util.Optional; //导入方法依赖的package包/类
@Theory
public void maybeBuild(Long value) {
Optional<Nat> expected = Nat.isValid.test(value) ?
Optional.of(Nat.of(value)) : Optional.empty();
Optional<Nat> actual = Nat.from(value);
assertThat(actual, is(expected));
}
示例12: parse
import java.util.Optional; //导入方法依赖的package包/类
private Optional<FutureTask<Set<Location>>> parse(Archive archive, Finder finder) {
if (parsedArchives.get(finder).contains(archive))
return Optional.empty();
parsedArchives.get(finder).add(archive);
trace("parsing %s %s%n", archive.getName(), archive.path());
FutureTask<Set<Location>> task = new FutureTask<>(() -> {
Set<Location> targets = new HashSet<>();
for (ClassFile cf : archive.reader().getClassFiles()) {
if (cf.access_flags.is(AccessFlags.ACC_MODULE))
continue;
String classFileName;
try {
classFileName = cf.getName();
} catch (ConstantPoolException e) {
throw new ClassFileError(e);
}
// filter source class/archive
String cn = classFileName.replace('/', '.');
if (!finder.accept(archive, cn, cf.access_flags))
continue;
// tests if this class matches the -include
if (!filter.matches(cn))
continue;
for (Dependency d : finder.findDependencies(cf)) {
if (filter.accepts(d)) {
archive.addClass(d.getOrigin(), d.getTarget());
targets.add(d.getTarget());
} else {
// ensure that the parsed class is added the archive
archive.addClass(d.getOrigin());
}
parsedClasses.putIfAbsent(d.getOrigin(), archive);
}
}
return targets;
});
tasks.add(task);
pool.submit(task);
return Optional.of(task);
}
示例13: first
import java.util.Optional; //导入方法依赖的package包/类
@Override
public final Optional<V> first() {
return count() > 0 ? Optional.of(createVector(frame, 0)) : Optional.empty();
}
示例14: getVisibility
import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Modifier> getVisibility() {
return Optional.of(Modifier.PUBLIC);
}
示例15: JoinTeam
import java.util.Optional; //导入方法依赖的package包/类
public JoinTeam(Team team, boolean rejoin, boolean priorityKick) {
super(Optional.of(team), rejoin, priorityKick);
}