本文整理了Java中net.anwiba.commons.lang.optional.Optional
类的一些代码示例,展示了Optional
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional
类的具体详情如下:
包路径:net.anwiba.commons.lang.optional.Optional
类名称:Optional
暂无
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public IOptional<T, E> or(final T value) {
return of(this.exceptionClass, value);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@SuppressWarnings("unchecked")
@Override
public <O> IOptional<O, E> instanceOf(final Class<O> clazz) {
if (clazz.isInstance(this.value)) {
return of(this.exceptionClass, (O) this.value);
}
return empty(this.exceptionClass);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public <O> IOptional<O, E> aggregate(final O inital, final IAggregator<O, T, O, E> aggregator) {
return Optional.failed(this.exceptionClass, this.cause);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public <O> IOptional<O, E> instanceOf(final Class<O> clazz) {
return empty(this.exceptionClass);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
public static <T> IOptional<T, RuntimeException> empty() {
return empty(RuntimeException.class);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
public static <T> IOptional<T, RuntimeException> of(final T value) {
return of(RuntimeException.class, value);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
public static <T> IOptional<T, RuntimeException> of(final java.util.Optional<T> optional) {
return optional.isPresent() ? of(optional.get()) : empty();
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public <O> IOptional<T, E> equals(final IConverter<T, O, E> converter, final O other) {
try {
if (Objects.equals(converter.convert(this.value), other)) {
return this;
}
return empty(this.exceptionClass);
} catch (final Exception exception) {
return Optional.failed(this.exceptionClass, exception, null);
}
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public IOptional<T, E> first() {
return Optional.failed(this.exceptionClass, this.cause);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public IOptional<T, E> or(final ISupplier<T, E> supplier) {
try {
return of(this.exceptionClass, supplier.supply());
} catch (final Exception exception) {
return Optional.failed(this.exceptionClass, exception, null);
}
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public <O, E extends Exception> IOptional<O, E> excecute(
final Class<E> exceptionClass,
final ISupplier<O, E> supplier)
throws E {
if (this.value) {
return Optional.of(exceptionClass, supplier.supply());
}
return Optional.empty(exceptionClass);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public IOptional<T, E> accept(final IAcceptor<T> acceptor) {
return acceptor.accept(this.value) ? this : empty(this.exceptionClass);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public <O> IOptional<T, E> equals(final IConverter<T, O, E> converter, final O value) {
return Optional.failed(this.exceptionClass, this.cause);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-datasource
public MemoryConnectionDescription(final Serializable content, final String mimeType, final ZonedDateTime timeStamp) {
this.content = content;
this.mimeType = mimeType;
this.timeStamp = Optional.of(timeStamp).getOr(() -> ZonedDateTime.now());
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public <O, E extends Exception> IOptional<O, E> or(final Class<E> exceptionClass, final ISupplier<O, E> supplier)
throws E {
if (!this.value) {
return Optional.of(exceptionClass, supplier.supply());
}
return Optional.empty(exceptionClass);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
public static <T, E extends Exception> IOptional<T, E> of(final Class<E> exceptionClass, final T value) {
if (value == null) {
return empty(exceptionClass);
}
return new Value<>(exceptionClass, value);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public <O> IOptional<O, E> instanceOf(final Class<O> clazz) {
return Optional.failed(this.exceptionClass, this.cause);
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
private synchronized void check() {
if (this.optional == null) {
this.optional = Optional.of(this.exceptionClass, (T) null).or(this.supplier);
}
};
代码示例来源:origin: net.anwiba.commons/anwiba-commons-jdbc
public static <T> T result(
final Connection connection,
final String statementString,
final IProcedure<PreparedStatement, SQLException> prepareProcedure,
final IConverter<IOptional<IResult, SQLException>, T, SQLException> resultFunction)
throws SQLException {
logger.log(ILevel.DEBUG, "Statement: " + statementString); //$NON-NLS-1$
try (PreparedStatement statement = connection.prepareStatement(statementString)) {
prepareProcedure.execute(statement);
if (statement.execute()) {
try (final ResultSet resultSet = statement.getResultSet()) {
final IResult result = new ResultSetToResultAdapter(resultSet);
if (resultSet.next()) {
final T value = resultFunction.convert(Optional.of(SQLException.class, result));
if (resultSet.next()) {
throw new SQLException("Statement result isn't unique '" + statementString + "'"); //$NON-NLS-1$ //$NON-NLS-2$
}
return value;
}
}
}
return resultFunction.convert(Optional.<IResult, SQLException> empty(SQLException.class));
} catch (final SQLException exception) {
throw new SQLException("Executing statement '" + statementString + "' faild", exception); //$NON-NLS-1$ //$NON-NLS-2$
}
}
代码示例来源:origin: net.anwiba.commons/anwiba-commons-core
@Override
public IOptional<T, E> first(final IAcceptor<T> acceptor) {
return Optional.failed(this.exceptionClass, this.cause);
}
内容来源于网络,如有侵权,请联系作者删除!