scala.util.Right Java Examples
The following examples show how to use
scala.util.Right.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LimitRateByRejection.java From ditto with Eclipse Public License 2.0 | 7 votes |
@Override public Iterable<Either<E, A>> apply(final A element) { final long currentTime = System.currentTimeMillis(); if (currentTime - previousWindow >= windowSizeMillis) { previousWindow = currentTime; counter = 1; } else { counter++; } final Either<E, A> result; if (counter <= maxElements) { result = Right.apply(element); } else { result = Left.apply(errorReporter.apply(element)); } return Collections.singletonList(result); }
Example #2
Source File: DecisionByMetricStage.java From ditto with Eclipse Public License 2.0 | 6 votes |
private static Either<CreditDecision, Long> getMaxTimerNanosFromStatusInfo(final StatusInfo statusInfo) { if (statusInfo.getDetails().size() != 1) { return left("StatusInfo has non-singleton detail: " + statusInfo); } final JsonValue detail = statusInfo.getDetails().get(0).getMessage(); if (!detail.isObject()) { return left("StatusDetailMessage is not an object: " + statusInfo); } final List<Long> maxTimerNanos = MongoMetrics.fromJson(detail.asObject()).getMaxTimerNanos(); // extract max long value final Optional<Long> max = maxTimerNanos.stream().max(Long::compareTo); if (!max.isPresent()) { return left("Field maxTimerNanos not found or empty in status detail: " + statusInfo); } return new Right<>(max.get()); }
Example #3
Source File: ScalaFeelEngine.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
public <T> T evaluateSimpleExpression(String expression, VariableContext variableContext) { CustomContext context = new CustomContext() { public VariableProvider variableProvider() { return new ContextVariableWrapper(variableContext); } }; Either either = feelEngine.evalExpression(expression, context); if (either instanceof Right) { Right right = (Right) either; return (T) right.value(); } else { Left left = (Left) either; Failure failure = (Failure) left.value(); String message = failure.message(); throw LOGGER.evaluationException(message); } }
Example #4
Source File: MessageMappingProcessorActor.java From ditto with Eclipse Public License 2.0 | 6 votes |
private static Either<RuntimeException, AuthorizationContext> getAuthorizationContextAsEither( final ExternalMessage externalMessage) { return externalMessage.getAuthorizationContext() .filter(authorizationContext -> !authorizationContext.isEmpty()) .<Either<RuntimeException, AuthorizationContext>>map(authorizationContext -> { try { return new Right<>(PlaceholderFilter.applyHeadersPlaceholderToAuthContext(authorizationContext, externalMessage.getHeaders())); } catch (final RuntimeException e) { return new Left<>(e); } }) .orElseGet(() -> new Left<>(new IllegalArgumentException("No nonempty authorization context is available"))); }
Example #5
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds, String[] options) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, Double.NEGATIVE_INFINITY, "GTiff", options ); }
Example #6
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom, double nodata) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, nodata, "GTiff", new String[]{} ); }
Example #7
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom, double nodata, String format) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, nodata, format, new String[]{} ); }
Example #8
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom, String[] options) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, Double.NEGATIVE_INFINITY, "GTiff", options ); }
Example #9
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom, String format, String[] options) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, Double.NEGATIVE_INFINITY, format, options ); }
Example #10
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom, double nodata, String[] options) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, nodata, "GTiff", options ); }
Example #11
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom, double nodata, String format, String[] options) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, nodata, format, options ); }
Example #12
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, Double.NEGATIVE_INFINITY, "GTiff", new String[]{} ); }
Example #13
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds, String format) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, Double.NEGATIVE_INFINITY, format, new String[]{} ); }
Example #14
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds, double nodata) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, nodata, "GTiff", new String[]{} ); }
Example #15
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds, double nodata, String format) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, nodata, format, new String[]{} ); }
Example #16
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, Double.NEGATIVE_INFINITY, "GTiff", new String[]{} ); }
Example #17
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds, String format, String[] options) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, Double.NEGATIVE_INFINITY, format, options ); }
Example #18
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds, double nodata, String[] options) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, nodata, "GTiff", options ); }
Example #19
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, Bounds bounds, double nodata, String format, String[] options) { GDALUtils.saveRaster( dataset, new Right<>(stream), bounds, nodata, format, options ); }
Example #20
Source File: ExceptionWrapperFunction.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public Tuple2<K, ? extends Either<Exception, V>> next() { if (caught != null) { consumed = true; return new Tuple2<>(null, new Left<Exception, V>(caught)); } try { Tuple2<K, V> result = delegate.next(); return new Tuple2<>(result._1(), new Right<Exception, V>(result._2())); } catch (Exception e) { consumed = true; return new Tuple2<>(null, new Left<Exception, V>(e)); } }
Example #21
Source File: ScalaFeelEngine.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public boolean evaluateSimpleUnaryTests(String expression, String inputVariable, VariableContext variableContext) { Map inputVariableMap = new Map.Map1(UnaryTests$.MODULE$.inputVariable(), inputVariable); StaticVariableProvider inputVariableContext = new StaticVariableProvider(inputVariableMap); ContextVariableWrapper contextVariableWrapper = new ContextVariableWrapper(variableContext); CustomContext context = new CustomContext() { public VariableProvider variableProvider() { return new CompositeVariableProvider(toScalaList(inputVariableContext, contextVariableWrapper)); } }; Either either = feelEngine.evalUnaryTests(expression, context); if (either instanceof Right) { Right right = (Right) either; Object value = right.value(); return BoxesRunTime.unboxToBoolean(value); } else { Left left = (Left) either; Failure failure = (Failure) left.value(); String message = failure.message(); throw LOGGER.evaluationException(message); } }
Example #22
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, String format) { GDALUtils.saveRaster( dataset, new Right<>(stream), null, Double.NEGATIVE_INFINITY, format, new String[]{} ); }
Example #23
Source File: DecisionByMetricStage.java From ditto with Eclipse Public License 2.0 | 5 votes |
private static Either<CreditDecision, Long> getMaxTimerNanos(final List<StatusInfo> statusInfos) { long maxTimerNanos = 0L; for (final StatusInfo statusInfo : statusInfos) { final Either<CreditDecision, Long> statusTimerValue = getMaxTimerNanosFromStatusInfo(statusInfo); if (statusTimerValue.isLeft()) { return statusTimerValue; } else { maxTimerNanos = Math.max(maxTimerNanos, statusTimerValue.right().get()); } } return new Right<>(maxTimerNanos); }
Example #24
Source File: ResumeSource.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Override public Iterable<Either<FailureWithLookBehind<E>, E>> apply(final Envelope<E> param) { if (param instanceof Element) { final E element = ((Element<E>) param).element; enqueue(element); return Collections.singletonList(new Right<>(element)); } else if (param instanceof Error) { final List<E> finalElementsCopy = new ArrayList<>(finalElements); final Throwable error = ((Error<E>) param).error; return Collections.singletonList(new Left<>(new FailureWithLookBehind<>(finalElementsCopy, error))); } else { // param is EOS; this is not supposed to happen. throw new IllegalStateException("End-of-stream encountered; stream should be complete already!"); } }
Example #25
Source File: WebSocketRoute.java From ditto with Eclipse Public License 2.0 | 5 votes |
private Graph<FanOutShape2<String, Either<StreamControlMessage, Signal>, DittoRuntimeException>, NotUsed> selectStreamControlOrSignal( final JsonSchemaVersion version, final CharSequence connectionCorrelationId, final AuthorizationContext connectionAuthContext, final DittoHeaders additionalHeaders, final ProtocolAdapter adapter) { final ProtocolMessageExtractor protocolMessageExtractor = new ProtocolMessageExtractor(connectionAuthContext, connectionCorrelationId); return Filter.multiplexByEither(cmdString -> { final Optional<StreamControlMessage> streamControlMessage = protocolMessageExtractor.apply(cmdString); if (streamControlMessage.isPresent()) { return Right.apply(Left.apply(streamControlMessage.get())); } else { try { final Signal<?> signal = buildSignal(cmdString, version, connectionCorrelationId, connectionAuthContext, additionalHeaders, adapter, headerTranslator); return Right.apply(Right.apply(signal)); } catch (final DittoRuntimeException dre) { // This is a client error usually; log at level DEBUG without stack trace. LOGGER.withCorrelationId(dre) .debug("DittoRuntimeException building signal from <{}>: <{}>", cmdString, dre); return Left.apply(dre); } catch (final Exception throwable) { LOGGER.warn("Error building signal from <{}>: {}: <{}>", cmdString, throwable.getClass().getSimpleName(), throwable.getMessage()); final DittoRuntimeException dittoRuntimeException = GatewayInternalErrorException.newBuilder() .cause(throwable) .build(); return Left.apply(dittoRuntimeException); } } }); }
Example #26
Source File: CucumberReportAdapterTest.java From openCypher with Apache License 2.0 | 5 votes |
@Override public Either<ExecutionFailed, CypherValueRecords> cypher(String query, Map<String, CypherValue> params, QueryType meta) { if (query.contains("foo()")) { return new Left<>(new ExecutionFailed("SyntaxError", "compile time", "UnknownFunction", null)); } else if (query.startsWith("RETURN ")) { String result = query.replace("RETURN ", ""); System.out.println("Producing some output " + result); List<String> header = new Set.Set1<>(result).toList(); Map<String, String> row = new Map.Map1<>(result, result); List<Map<String, String>> rows = new Set.Set1<>(row).toList(); return new Right<>(new StringRecords(header, rows).asValueRecords()); } else { return new Right<>(CypherValueRecords.empty()); } }
Example #27
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream) { GDALUtils.saveRaster( dataset, new Right<>(stream), null, Double.NEGATIVE_INFINITY, "GTiff", new String[]{} ); }
Example #28
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRasterTile(Dataset dataset, OutputStream stream, long tx, long ty, int zoom, String format) { GDALUtils.saveRasterTile( dataset, new Right<>(stream), tx, ty, zoom, Double.NEGATIVE_INFINITY, format, new String[]{} ); }
Example #29
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, double nodata) { GDALUtils.saveRaster( dataset, new Right<>(stream), null, nodata, "GTiff", new String[]{} ); }
Example #30
Source File: GDALJavaUtils.java From mrgeo with Apache License 2.0 | 5 votes |
public static void saveRaster(Dataset dataset, OutputStream stream, double nodata, String format) { GDALUtils.saveRaster( dataset, new Right<>(stream), null, nodata, format, new String[]{} ); }