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