本文整理汇总了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();
}
示例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();
}
示例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);
}
示例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();
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}