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


Java Optional.of方法代码示例

本文整理汇总了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();
}
 
开发者ID:Bekreth,项目名称:jetedge,代码行数:19,代码来源:ClassAttributes.java

示例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;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:DestroyableFactory.java

示例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));
}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:21,代码来源:AstBuilder.java

示例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);
					}
				}
			};
		}
	});
}
 
开发者ID:to2mbn,项目名称:authlib-injector,代码行数:28,代码来源:LdcTransformUnit.java

示例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);
}
 
开发者ID:RFTDevGroup,项目名称:RFTBackend,代码行数:15,代码来源:TransportCreateDTOValidator.java

示例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)));  // (*)
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:12,代码来源:OptionalIntegerTest.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:State.java

示例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();
}
 
开发者ID:Bios-Marcel,项目名称:ServerBrowser,代码行数:18,代码来源:OptionalUtility.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:LogParser.java

示例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();
}
 
开发者ID:toasttab,项目名称:jdbishard,代码行数:14,代码来源:DAORegistry.java

示例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));
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:8,代码来源:NatTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:DependencyFinder.java

示例13: first

import java.util.Optional; //导入方法依赖的package包/类
@Override
public final Optional<V> first() {
    return count() > 0 ? Optional.of(createVector(frame, 0)) : Optional.empty();
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:5,代码来源:XDataFrameAxisBase.java

示例14: getVisibility

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Modifier> getVisibility() {
    return Optional.of(Modifier.PUBLIC);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:5,代码来源:MethodDefinition.java

示例15: JoinTeam

import java.util.Optional; //导入方法依赖的package包/类
public JoinTeam(Team team, boolean rejoin, boolean priorityKick) {
    super(Optional.of(team), rejoin, priorityKick);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:JoinTeam.java


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