本文整理了Java中io.vavr.control.Option.getOrElseThrow()
方法的一些代码示例,展示了Option.getOrElseThrow()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getOrElseThrow()
方法的具体详情如下:
包路径:io.vavr.control.Option
类名称:Option
方法名:getOrElseThrow
[英]Returns the value if this is a Some, otherwise throws an exception.
[中]如果这是Some,则返回该值,否则将引发异常。
代码示例来源:origin: vavr-io/vavr
@Deprecated
@Override
default Traversable<V> apply(K key) {
return get(key).getOrElseThrow(NoSuchElementException::new);
}
代码示例来源:origin: vavr-io/vavr
@Override
default Tuple2<K, V> last() {
return max().getOrElseThrow(() -> new NoSuchElementException("last on empty SortedMap"));
}
代码示例来源:origin: vavr-io/vavr
@Deprecated
@Override
default V apply(K key) {
return get(key).getOrElseThrow(() -> new NoSuchElementException(String.valueOf(key)));
}
代码示例来源:origin: vavr-io/vavr
@Override
public V apply(K key) {
return get(key).getOrElseThrow(() -> new NoSuchElementException(String.valueOf(key)));
}
@Override
代码示例来源:origin: vavr-io/vavr
/**
* Returns the single element of this Traversable or throws, if this is empty or contains more than one element.
*
* @return the single element from the Traversable
* @throws NoSuchElementException if the Traversable does not contain a single element.
*/
default T single() {
return singleOption().getOrElseThrow(() -> new NoSuchElementException("Does not contain a single value"));
}
代码示例来源:origin: vavr-io/vavr
@Override
public Traversable<V> apply(K key) {
return get(key).getOrElseThrow(NoSuchElementException::new);
}
@Override
代码示例来源:origin: resilience4j/resilience4j
@RequestMapping(value = "stream/events/{circuitBreakerName}", produces = MEDIA_TYPE_TEXT_EVENT_STREAM)
public SseEmitter getEventsStreamFilteredByCircuitBreakerName(@PathVariable("circuitBreakerName") String circuitBreakerName) {
CircuitBreaker circuitBreaker = circuitBreakerRegistry.getAllCircuitBreakers()
.find(cb -> cb.getName().equals(circuitBreakerName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("circuit breaker with name %s not found", circuitBreakerName)));
return CircuitBreakerEventEmitter.createSseEmitter(toFlux(circuitBreaker.getEventPublisher()));
}
代码示例来源:origin: resilience4j/resilience4j
@RequestMapping(value = "stream/events/{rateLimiterName}", produces = MEDIA_TYPE_TEXT_EVENT_STREAM)
public SseEmitter getEventsStreamFilteredByRateLimiterName(@PathVariable("rateLimiterName") String rateLimiterName) {
RateLimiter rateLimiter = rateLimiterRegistry.getAllRateLimiters()
.find(rL -> rL.getName().equals(rateLimiterName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("rate limiter with name %s not found", rateLimiterName)));
return RateLimiterEventsEmitter.createSseEmitter(toFlux(rateLimiter.getEventPublisher()));
}
代码示例来源:origin: resilience4j/resilience4j
@RequestMapping(value = "stream/events/{circuitBreakerName}/{eventType}", produces = MEDIA_TYPE_TEXT_EVENT_STREAM)
public SseEmitter getEventsStreamFilteredByCircuitBreakerNameAndEventType(@PathVariable("circuitBreakerName") String circuitBreakerName,
@PathVariable("eventType") String eventType) {
CircuitBreaker circuitBreaker = circuitBreakerRegistry.getAllCircuitBreakers()
.find(cb -> cb.getName().equals(circuitBreakerName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("circuit breaker with name %s not found", circuitBreakerName)));
Flux<CircuitBreakerEvent> eventStream = toFlux(circuitBreaker.getEventPublisher())
.filter(event -> event.getEventType() == CircuitBreakerEvent.Type.valueOf(eventType.toUpperCase()));
return CircuitBreakerEventEmitter.createSseEmitter(eventStream);
}
代码示例来源:origin: resilience4j/resilience4j
@RequestMapping(value = "stream/events/{rateLimiterName}/{eventType}", produces = MEDIA_TYPE_TEXT_EVENT_STREAM)
public SseEmitter getEventsStreamFilteredByRateLimiterNameAndEventType(@PathVariable("rateLimiterName") String rateLimiterName,
@PathVariable("eventType") String eventType) {
RateLimiterEvent.Type targetType = RateLimiterEvent.Type.valueOf(eventType.toUpperCase());
RateLimiter rateLimiter = rateLimiterRegistry.getAllRateLimiters()
.find(rL -> rL.getName().equals(rateLimiterName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("rate limiter with name %s not found", rateLimiterName)));
Flux<RateLimiterEvent> eventStream = toFlux(rateLimiter.getEventPublisher())
.filter(event -> event.getEventType() == targetType);
return RateLimiterEventsEmitter.createSseEmitter(eventStream);
}
}
代码示例来源:origin: resilience4j/resilience4j
String bulkheadName = ctx.getPathTokens().get("name");
Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName))
.getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName)));
Function<BulkheadEvent, String> data = b -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(BulkheadEventDTO.createEventDTO(b));
ServerSentEvents events = ServerSentEvents.serverSentEvents(ReactorAdapter.toFlux(bulkhead.getEventPublisher()), e -> e.id(BulkheadEvent::getBulkheadName).event(c -> c.getEventType().name()).data(data));
String eventType = ctx.getPathTokens().get("type");
Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName))
.getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName)));
Flux<BulkheadEvent> eventStream = ReactorAdapter.toFlux(bulkhead.getEventPublisher())
.filter(event -> event.getEventType() == BulkheadEvent.Type.valueOf(eventType.toUpperCase()));
代码示例来源:origin: resilience4j/resilience4j
Retry retry = retryRegistry.getAllRetries()
.find(rL -> rL.getName().equals(rateLimiterName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("rate limiter with name %s not found", rateLimiterName)));
Function<RetryEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(RetryEventDTO.createRetryEventDTO(r));
Retry retry = retryRegistry.getAllRetries()
.find(rL -> rL.getName().equals(retryName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("rate limiter with name %s not found", retryName)));
Flux<RetryEvent> eventStream = ReactorAdapter.toFlux(retry.getEventPublisher())
代码示例来源:origin: resilience4j/resilience4j
RateLimiter rateLimiter = rateLimiterRegistry.getAllRateLimiters()
.find(rL -> rL.getName().equals(rateLimiterName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("rate limiter with name %s not found", rateLimiterName)));
Function<RateLimiterEvent, String> data = r -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(RateLimiterEventDTO.createRateLimiterEventDTO(r));
RateLimiter rateLimiter = rateLimiterRegistry.getAllRateLimiters()
.find(rL -> rL.getName().equals(rateLimiterName))
.getOrElseThrow(() ->
new IllegalArgumentException(String.format("rate limiter with name %s not found", rateLimiterName)));
Flux<RateLimiterEvent> eventStream = ReactorAdapter.toFlux(rateLimiter.getEventPublisher())
代码示例来源:origin: resilience4j/resilience4j
String circuitBreakerName = ctx.getPathTokens().get("name");
CircuitBreaker circuitBreaker = circuitBreakerRegistry.getAllCircuitBreakers().find(cb -> cb.getName().equals(circuitBreakerName))
.getOrElseThrow(() -> new IllegalArgumentException(String.format("circuit breaker with name %s not found", circuitBreakerName)));
Function<CircuitBreakerEvent, String> data = c -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(CircuitBreakerEventDTOFactory.createCircuitBreakerEventDTO(c));
ServerSentEvents events = ServerSentEvents.serverSentEvents(ReactorAdapter.toFlux(circuitBreaker.getEventPublisher()), e -> e.id(CircuitBreakerEvent::getCircuitBreakerName).event(c -> c.getEventType().name()).data(data));
String eventType = ctx.getPathTokens().get("type");
CircuitBreaker circuitBreaker = circuitBreakerRegistry.getAllCircuitBreakers().find(cb -> cb.getName().equals(circuitBreakerName))
.getOrElseThrow(() -> new IllegalArgumentException(String.format("circuit breaker with name %s not found", circuitBreakerName)));
Flux<CircuitBreakerEvent> eventStream = ReactorAdapter.toFlux(circuitBreaker.getEventPublisher())
.filter(event -> event.getEventType() == CircuitBreakerEvent.Type.valueOf(eventType.toUpperCase()));
代码示例来源:origin: io.vavr/vavr
@Deprecated
@Override
default V apply(K key) {
return get(key).getOrElseThrow(() -> new NoSuchElementException(String.valueOf(key)));
}
代码示例来源:origin: io.vavr/vavr
@Override
public V apply(K key) {
return get(key).getOrElseThrow(() -> new NoSuchElementException(String.valueOf(key)));
}
@Override
代码示例来源:origin: io.vavr/vavr
/**
* Returns the single element of this Traversable or throws, if this is empty or contains more than one element.
*
* @return the single element from the Traversable
* @throws NoSuchElementException if the Traversable does not contain a single element.
*/
default T single() {
return singleOption().getOrElseThrow(() -> new NoSuchElementException("Does not contain a single value"));
}
代码示例来源:origin: ch.netzwerg/paleo-core
@SuppressWarnings("unchecked")
private <T extends Column<?>> T getTypedColumn(ColumnId columnId) {
return (T) columns.find(c -> c.getId().equals(columnId)).getOrElseThrow(() -> {
String msg = String.format("Unknown column id '%s'", columnId);
throw new IllegalArgumentException(msg);
});
}
代码示例来源:origin: Tristan971/Lyrebird
/**
* Requests closure of the application.
*/
private void exitApplication() {
LOG.info("Requesting application closure from tray icon.");
stageManager.getSingle(Screen.ROOT_VIEW).getOrElseThrow(IllegalStateException::new).close();
Platform.exit();
}
代码示例来源:origin: org.janusgraph/janusgraph-cql
Map<String, String> getCompressionOptions(final String name) throws BackendException {
final KeyspaceMetadata keyspaceMetadata = Option.of(this.cluster.getMetadata().getKeyspace(this.keyspace))
.getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown keyspace '%s'", this.keyspace)));
return Option.of(keyspaceMetadata.getTable(name))
.map(tableMetadata -> tableMetadata.getOptions().getCompression())
.getOrElseThrow(() -> new PermanentBackendException(String.format("Unknown table '%s'", name)));
}
内容来源于网络,如有侵权,请联系作者删除!