Java Code Examples for scala.util.Either#isLeft()

The following examples show how to use scala.util.Either#isLeft() . 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: EntityDiscoveryService.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private GremlinQuery toGremlinQuery(String query, int limit, int offset) throws AtlasBaseException {
    QueryParams params = validateSearchParams(limit, offset);
    Either<NoSuccess, Expression> either = QueryParser.apply(query, params);

    if (either.isLeft()) {
        throw new AtlasBaseException(DISCOVERY_QUERY_FAILED, query);
    }

    Expression   expression      = either.right().get();
    Expression   validExpression = QueryProcessor.validate(expression);
    GremlinQuery gremlinQuery    = new GremlinTranslator(validExpression, graphPersistenceStrategy).translate();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Translated Gremlin Query: {}", gremlinQuery.queryStr());
    }

    return gremlinQuery;
}
 
Example 2
Source File: HaskellRunConfigurationBase.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
protected void requireCabalVersionMinimum(double minimumVersion, @NotNull String errorMessage) throws RuntimeConfigurationException {
    final HaskellBuildSettings buildSettings = HaskellBuildSettings.getInstance(getProject());
    final String cabalPath = buildSettings.getCabalPath();
    if (cabalPath.isEmpty()) {
        throw new RuntimeConfigurationError("Path to cabal is not set.");
    }
    GeneralCommandLine cabalCmdLine = new GeneralCommandLine(cabalPath, "--numeric-version");
    Either<ExecUtil.ExecError, String> result = ExecUtil.readCommandLine(cabalCmdLine);
    if (result.isLeft()) {
        //noinspection ThrowableResultOfMethodCallIgnored
        ExecUtil.ExecError e = EitherUtil.unsafeGetLeft(result);
        NotificationUtil.displaySimpleNotification(
            NotificationType.ERROR, getProject(), "cabal", e.getMessage()
        );
        throw new RuntimeConfigurationError("Failed executing cabal to check its version: " + e.getMessage());
    }
    final String out = EitherUtil.unsafeGetRight(result);
    final Matcher m = EXTRACT_CABAL_VERSION_REGEX.matcher(out);
    if (!m.find()) {
        throw new RuntimeConfigurationError("Could not parse cabal version: '" + out + "'");
    }
    final Double actualVersion = Double.parseDouble(m.group(1));
    if (actualVersion < minimumVersion) {
        throw new RuntimeConfigurationError(errorMessage);
    }
}
 
Example 3
Source File: DecisionByMetricStage.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
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 4
Source File: GhcMod.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@Nullable
public static String exec(@NotNull Project project, @NotNull String workingDirectory, @NotNull String ghcModPath,
                          @NotNull String command, @NotNull String ghcModFlags, String... params) {
    if (!validateGhcVersion(project, ghcModPath, ghcModFlags)) return null;
    GeneralCommandLine commandLine = new GeneralCommandLine(ghcModPath);
    GhcModUtil.updateEnvironment(project, commandLine.getEnvironment());
    ParametersList parametersList = commandLine.getParametersList();
    parametersList.addParametersString(ghcModFlags);
    parametersList.add(command);
    parametersList.addAll(params);
    // setWorkDirectory is deprecated but is needed to work with IntelliJ 13 which does not have withWorkDirectory.
    commandLine.setWorkDirectory(workingDirectory);
    // Make sure we can actually see the errors.
    commandLine.setRedirectErrorStream(true);
    HaskellToolsConsole toolConsole = HaskellToolsConsole.get(project);
    toolConsole.writeInput(ToolKey.GHC_MOD_KEY, "Using working directory: " + workingDirectory);
    toolConsole.writeInput(ToolKey.GHC_MOD_KEY, commandLine.getCommandLineString());
    Either<ExecUtil.ExecError, String> result = ExecUtil.readCommandLine(commandLine);
    if (result.isLeft()) {
        //noinspection ThrowableResultOfMethodCallIgnored
        ExecUtil.ExecError e = EitherUtil.unsafeGetLeft(result);
        toolConsole.writeError(ToolKey.GHC_MOD_KEY, e.getMessage());
        NotificationUtil.displayToolsNotification(
            NotificationType.ERROR, project, "ghc-mod", e.getMessage()
        );
        return null;
    }
    String out = EitherUtil.unsafeGetRight(result);
    toolConsole.writeOutput(ToolKey.GHC_MOD_KEY, out);
    return out;
}
 
Example 5
Source File: CucumberReportAdapter.java    From openCypher with Apache License 2.0 4 votes vote down vote up
private Throwable errorOrNull(Either<Throwable, Either<ExecutionFailed, CypherValueRecords>> result) {
    return result.isLeft() ? result.left().get() : null;
}