All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.updater.spi.UpdateResult Maven / Gradle / Ivy

The newest version!
package org.opentripplanner.updater.spi;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import java.util.List;
import org.opentripplanner.transit.model.framework.Result;

/**
 * An aggregation of results of the application of realtime updates which makes it easy to get
 * an overview of what the success rate of the update was and which specific problems were
 * encountered.
 */
public record UpdateResult(
  int successful,
  int failed,
  Multimap failures,
  List warnings,
  List successes,
  List errors
) {
  /**
   * Create an empty result.
   */
  public static UpdateResult empty() {
    return new UpdateResult(0, 0, ArrayListMultimap.create(), List.of(), List.of(), List.of());
  }

  /**
   * Aggregate a list of results into an instance of {@link UpdateResult}.
   */
  public static UpdateResult ofResults(List> results) {
    List errors = results
      .stream()
      .filter(Result::isFailure)
      .map(Result::failureValue)
      .toList();
    List successes = results
      .stream()
      .filter(Result::isSuccess)
      .map(Result::successValue)
      .toList();
    List warnings = successes
      .stream()
      .flatMap(s -> s.warnings().stream())
      .toList();
    ImmutableListMultimap errorIndex = Multimaps.index(errors, UpdateError::errorType);
    return new UpdateResult(
      successes.size(),
      errors.size(),
      errorIndex,
      warnings,
      successes,
      errors
    );
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy