net.anwiba.commons.lang.optional.Optional.of()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中net.anwiba.commons.lang.optional.Optional.of()方法的一些代码示例,展示了Optional.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.of()方法的具体详情如下:
包路径:net.anwiba.commons.lang.optional.Optional
类名称:Optional
方法名:of

Optional.of介绍

暂无

代码示例

代码示例来源: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-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

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-core

public static TimeZone getUserTimeZone() {
 return Optional.of(System.getProperty("user.timezone")).convert(z -> TimeZone.getTimeZone(z)).getOr(
   () -> TimeZone.getDefault());
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-core

@Override
public IOptional<T, E> first(final IAcceptor<T> acceptor) {
 try {
  return Optional.of(this.exceptionClass, this.iterable.first(acceptor));
 } catch (final Exception exception) {
  return optional(this.exceptionClass, exception);
 }
}

代码示例来源: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 <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-http

@Override
public InputStream getInputStream() throws IOException {
 return new CancelableInputStream(
   this.cancelable,
   Optional
     .of(IOException.class, this.response)
     .convert(r -> r.getEntity())
     .convert(e -> e.getContent())
     .getOrThrow(() -> new IOException()));
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-core

@Override
public IOptional<T, E> failed(final ISupplier<T, E> supplier) {
 try {
  return of(this.exceptionClass, supplier.supply());
 } catch (final Exception exception) {
  return Optional.failed(this.exceptionClass, exception, getCause());
 }
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-http

@Override
public String getContentType() {
 return Optional
   .of(this.response)
   .convert(r -> r.getEntity())
   .convert(e -> e.getContentType())
   .convert(h -> h.getValue())
   .get();
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-utilities

@Override
public IAuthentication getAuthentication() {
 return Optional.of(this.authority).convert(a -> a.getAuthentication()).get();
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-core

@Override
public IHost getHost() {
 return Optional.of(this.authority).convert(a -> a.getHost()).get();
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-reference

protected IOptional<File, IOException> ifFile(final IResourceReference resourceReference) {
 return Optional
   .of(IOException.class, resourceReference)
   .accept(r -> isFileSystemResource(resourceReference))
   .convert(r -> {
    try {
     return getFile(resourceReference);
    } catch (final URISyntaxException exception) {
     throw new IOException();
    }
   });
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-utilities

private Integer port(final String string) throws CreationException {
 if (StringUtilities.isNullOrTrimmedEmpty(string)) {
  return null;
 }
 if (!NumberUtilities.isNumber(string)) {
  throw new CreationException("No number '" + string + "'"); //$NON-NLS-1$ //$NON-NLS-2$
 }
 return Optional.of(string).convert(s -> Integer.valueOf(s)).get();
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-utilities

public void add(final char character) {
  if (character == '&') {
   Optional.of(this.parameterBuilder).convert(b -> b.build()).consume(p -> this.parameters.add(p));
   this.parameterBuilder = null;
   return;
  }
  if (this.parameterBuilder == null) {
   this.parameterBuilder = new ParameterBuilder();
  }
  this.parameterBuilder.add(character);
 }
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-core

public void add(final char character) {
  if (character == '&') {
   Optional.of(this.parameterBuilder).convert(b -> b.build()).consume(p -> this.parameters.add(p));
   this.parameterBuilder = null;
   return;
  }
  if (this.parameterBuilder == null) {
   this.parameterBuilder = new ParameterBuilder();
  }
  this.parameterBuilder.add(character);
 }
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-core

public UrlBuilder(final IUrl url) {
 this.scheme.addAll(url.getScheme());
 final IAuthentication authentication = url.getAuthentication();
 this.username = Optional.of(authentication).convert(a -> a.getUsername()).get();
 this.password = Optional.of(authentication).convert(a -> a.getPassword()).get();
 final IHost host = url.getHost();
 this.hostName = Optional.of(host).convert(a -> a.getName()).get();
 this.port = Optional.of(host).convert(a -> a.getPort()).get();
 url.getQuery().forEach(p -> this.parameters.add(p));
 this.path.addAll(url.getPath());
 this.fragment = url.getFragment();
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-swing-core

@Override
 public WindowState getState() {
  return Optional.of(this.preferences.get("state", null)).convert(v -> WindowState.valueOf(v)).getOr(
    () -> WindowState.NORMAL);
 }
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-utilities

@Override
 public String getPassword() {
  return Optional.of(this.authority).convert(a -> a.getAuthentication()).convert(a -> a.getPassword()).get();
 }
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-utilities

@Override
public int getPort() {
 return Optional.of(this.authority).convert(a -> a.getHost()).convert(h -> h.getPort()).getOr(() -> -1);
}

相关文章

微信公众号

最新文章

更多