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


Java Optional.empty方法代码示例

本文整理汇总了Java中java.util.Optional.empty方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.empty方法的具体用法?Java Optional.empty怎么用?Java Optional.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Optional的用法示例。


在下文中一共展示了Optional.empty方法的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: read

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Collection<Change>> read(File projectDir) {
    final Optional<Path> smartTestingScmChangesOptional =
        findFileInDirectoryOrParents(projectDir.getAbsoluteFile(), getScmChangesFileName());

    if (smartTestingScmChangesOptional.isPresent()) {

        final Path localScmChanges = smartTestingScmChangesOptional.get();
        try (Stream<String> changes = Files.lines(localScmChanges)) {
            return Optional.of(changes.map(Change::read).collect(Collectors.toList()));
        } catch (IOException e) {
            LOGGER.warn("Unable to read changes from [%s]. Reason: %s", localScmChanges, e.getMessage());
            e.printStackTrace();
        }
    }

    return Optional.empty();
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:19,代码来源:LocalChangeStorage.java

示例3: queryForOptionalObject

import java.util.Optional; //导入方法依赖的package包/类
public <T> Optional<T> queryForOptionalObject(String query, RowMapper<T> mapper, Object... params)
        throws EventStoreException {
    ResultSetMapper<Optional<T>> rsMapper = rs -> {
        if (rs.next()) {
            T result = mapper.toEvent(rs);
            if (rs.next()) {
                throw new EventStoreException("More than one matching row for query: [" + query + "]");
            } else {
                return Optional.ofNullable(result);
            }
        } else {
            return Optional.empty();
        }
    };
    return query(query, rsMapper, params);
}
 
开发者ID:OasisDigital,项目名称:nges,代码行数:17,代码来源:JdbcQueries.java

示例4: assignMaintainer

import java.util.Optional; //导入方法依赖的package包/类
public Optional<Machine> assignMaintainer(AssignMaintainerData assignMaintainerData) throws BusinessLogicException {
    String[] validateErrors = assignMaintainerData.validate();
    if (validateErrors.length != 0)
        throw new BusinessLogicException(validateErrors);

    Optional<Machine> machineById = machineRepository.findById(assignMaintainerData.getId());
    if (!machineById.isPresent())
        return machineById;

    Machine machine = machineById.get();
    if (!authProvider.canModify(assignMaintainerData.getRequester(), machine))
        throw new BusinessLogicException(new String[]{INSUFFICIENT_PERMISSIONS});

    Optional<Person> technicianById = personRepository.findById(assignMaintainerData.getTechnicianId());
    if (!technicianById.isPresent())
        return Optional.empty();

    Person technician = technicianById.get();
    technician.addMaintainedMachine(machine);
    Optional<Person> possibleUpdated = personRepository.update(technician);

    return possibleUpdated.isPresent() ? Optional.of(machine) : Optional.empty();
}
 
开发者ID:VendingOnTime,项目名称:server-vot,代码行数:24,代码来源:AssignMaintainerService.java

示例5: testUnsupportedColumns

import java.util.Optional; //导入方法依赖的package包/类
@Test
public void testUnsupportedColumns() {
  TableOutputter outputter = mock(TableOutputter.class);
  final SpreadsheetDataSetConsumer consumer =
      new SpreadsheetDataSetConsumer(
        mock(OutputStream.class),
        Optional.<Map<String, Integer>>empty(),
        outputter
      );

  Table one = table("one");
  Table two = table("two");
  when(outputter.tableHasUnsupportedColumns(one)).thenReturn(true);
  when(outputter.tableHasUnsupportedColumns(two)).thenReturn(false);

  consumer.table(one, NO_RECORDS);
  consumer.table(two, NO_RECORDS);

  verify(outputter).table(anyInt(), any(WritableWorkbook.class), eq(two), eq(NO_RECORDS));
  verify(outputter, times(0)).table(anyInt(), any(WritableWorkbook.class), eq(one), eq(NO_RECORDS));
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:22,代码来源:TestSpreadsheetDataSetConsumer.java

示例6: diff

import java.util.Optional; //导入方法依赖的package包/类
public Optional<ChangedParameters> diff(List<Parameter> left, List<Parameter> right) {
    ChangedParameters changedParameters = new ChangedParameters(left, right != null ? new ArrayList<>(right) : null);
    if (null == left) left = new ArrayList<>();
    if (null == right) right = new ArrayList<>();

    for (Parameter leftPara : left) {
        leftPara = refPointer.resolveRef(leftComponents, leftPara, leftPara.get$ref());

        Optional<Parameter> rightParam = contains(rightComponents, right, leftPara);
        if (!rightParam.isPresent()) {
            changedParameters.getMissing().add(leftPara);
        } else {
            Parameter rightPara = rightParam.get();
            right.remove(rightPara);
            openApiDiff.getParameterDiff().diff(leftPara, rightPara).ifPresent(changedParameters.getChanged()::add);
        }
    }
    changedParameters.getIncreased().addAll(right);

    return changedParameters.isDiff() ? Optional.of(changedParameters) : Optional.empty();
}
 
开发者ID:quen2404,项目名称:openapi-diff,代码行数:22,代码来源:ParametersDiff.java

示例7: handle

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<ProcessorDefinition> handle(Choice step, ProcessorDefinition route, SyndesisRouteBuilder routeBuilder) {
    final CamelContext context = routeBuilder.getContext();
    final ChoiceDefinition choice = route.choice();

    List<Filter> filters = ObjectHelper.supplyIfEmpty(step.getFilters(), Collections::<Filter>emptyList);
    for (Filter filter : filters) {
        Predicate predicate = JsonSimpleHelpers.getMandatorySimplePredicate(context, filter, filter.getExpression());
        ChoiceDefinition when = choice.when(predicate);

        routeBuilder.addSteps(when, filter.getSteps());
    }

    Otherwise otherwiseStep = step.getOtherwise();
    if (otherwiseStep != null) {
        List<Step> otherwiseSteps = ObjectHelper.supplyIfEmpty(otherwiseStep.getSteps(), Collections::<Step>emptyList);
        if (!otherwiseSteps.isEmpty()) {
            routeBuilder.addSteps(choice.otherwise(), otherwiseSteps);
        }
    }

    return Optional.empty();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:24,代码来源:ChoiceHandler.java

示例8: put

import java.util.Optional; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");

	final VaadinSession session = VaadinSession.getCurrent();
	if (session == null) {
		throw new IllegalStateException("Current VaadinSession not available");
	}

	Object exist = session.getAttribute(resourceKey);

	session.setAttribute(resourceKey, value);

	try {
		T previous = (T) exist;
		return Optional.ofNullable(previous);
	} catch (@SuppressWarnings("unused") Exception e) {
		// ignore
		return Optional.empty();
	}
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:23,代码来源:VaadinSessionScope.java

示例9: convert

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<ToDeviceMsg> convert(PluginToRuleMsg<?> response) {
  if (response instanceof ResponsePluginToRuleMsg) {
    return Optional.of(((ResponsePluginToRuleMsg) response).getPayload());
  }
  return Optional.empty();
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:8,代码来源:SendMailAction.java

示例10: smooth

import java.util.Optional; //导入方法依赖的package包/类
@Override
public Optional<Ratio> smooth(final Ratio dataPoint) {
    if (aggregatedIs == 0) {
        ema = dataPoint.asBasic();
    } else {
        ema += (dataPoint.asBasic() - ema) * factor;
    }
    if (aggregatedIs < smoothingPeriod - 1) {
        aggregatedIs++;
        return Optional.empty();
    }
    return Optional.of(new Ratio(ema));
}
 
开发者ID:rbi,项目名称:trading4j,代码行数:14,代码来源:ExponentialMovingAverageRatio.java

示例11: detectGroupOfThreePattern

import java.util.Optional; //导入方法依赖的package包/类
default Optional<Pattern> detectGroupOfThreePattern(final Candlestick candlestick1,
                                                    final Candlestick candlestick2,
                                                    final Candlestick candlestick3){

    if(candlestick1.getTrendDirection() == TrendDirection.DOWN){
        return detectTripleDownTrendCandlestickPattern(candlestick1, candlestick2, candlestick3);
    }

    if(candlestick1.getTrendDirection() == TrendDirection.UPPER){
        return detectTripleUpTrendCandlestickPattern(candlestick1, candlestick2, candlestick3);
    }

    return Optional.empty();
}
 
开发者ID:mumukiller,项目名称:stock-patterns-recognition,代码行数:15,代码来源:GroupOfThreePatternDetector.java

示例12: get

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Gets the {@link Optional} {@link TreeNode} from the cache which matches the {@link Range} passed in.
 *
 * @param range {@link Range} to match against.
 * @return The {@link Optional} {@link TreeNode} from the cache, {@code Optional.empty()} if not in cache.
 */
public Optional<TreeNode> get(final Optional<Range<Instant>> range) {
    if (range.isPresent()) {
        final Optional<TreeNode> treeNode = this.cache.get(range.get());
        if (treeNode != null) {
            return treeNode;
        }
    }
    return Optional.empty();
}
 
开发者ID:jpmorganchase,项目名称:swblocks-decisiontree,代码行数:16,代码来源:TimeSliceCache.java

示例13: fromTag

import java.util.Optional; //导入方法依赖的package包/类
/**
 * Searches for a locale with that tag
 *
 * @param tag the tag to search for
 * @return a optionally found locale
 */
@Nonnull
public static Optional<Locale> fromTag(@Nonnull String tag) {
    for (Locale loc : values()) {
        if (loc.getTag().equalsIgnoreCase(tag)) {
            return Optional.of(loc);
        }
    }

    return Optional.empty();
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:17,代码来源:Locale.java

示例14: createProfiler

import java.util.Optional; //导入方法依赖的package包/类
private static Optional<Profiler> createProfiler(Config config, String profilerClassName) {
    try {
        Class profilerClass = Class.forName(DEFAULT_PROFILER_PACKAGE + profilerClassName);
        Profiler profiler =  (Profiler) profilerClass.getConstructor(Config.class).newInstance(config);
        return Optional.of(profiler);
    } catch (Exception ex) {
        log.error(ex);
        return Optional.empty();
    }
}
 
开发者ID:awslabs,项目名称:emr-workload-profiler,代码行数:11,代码来源:ProfilerFactory.java

示例15: cssFirst

import java.util.Optional; //导入方法依赖的package包/类
@Override
public <T extends Node> Optional<RNode<T>> cssFirst(Duration timeout, Class<T> type, String selector) {
	long t = timeout.toMillis();
	while( t > 0 ) {
		Optional<RNode<T>> rv = cssFirst(type, selector);
		if( rv.isPresent() ) {
			return rv;
		}
		sleep(100);
		t -= 100;
	}
	return Optional.empty();
}
 
开发者ID:BestSolution-at,项目名称:FX-Test,代码行数:14,代码来源:FXRobotRemoteController.java


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