Interface ResolvedBookmark


public interface ResolvedBookmark

Links a Bookmark to a BookmarkResolver in order to access the useful data. A ResolvedBookmark indicates that a BookmarkResolver has said that the bookmark looks like it can be accessed by a particular resolver. However, the BookmarkResolver may already have spotted errors with the bookmark that prevent it being opened, such as a missing or invalid option. These sorts of errors should be returned by the validate() method.

A ResolvedBookmark can also return any failure information when the actual data was opened, in addition to any validation Problems. These should be returned alongside the validation errors in the problems associated with the getData(Class) method.

It is expected that implementations will not attempt to reopen a bookmark with each call to access the data, so implementations are free to memoize any validation errors or constructed objects.

  • Method Details

    • from

      static ResolvedBookmark from(Object object)

      Useful testing constructor to return a pre-constructed Object with a fake Bookmark object

    • from

      static ResolvedBookmark from(Object object, List<Problem> dataProblems)

      Useful testing constructor to return a pre-constructed Object with a fake Bookmark object

      Parameters:
      dataProblems - to return with the data (not validation errors)
    • from

      static ResolvedBookmark from(@NonNull @NonNull Object object, @NonNull @NonNull List<Problem> dataProblems, @NonNull @NonNull List<Problem> validationProblems)
    • withId

      static ResolvedBookmark withId(String bookmarkId, Object object)

      Useful testing constructor to return a pre-constructed Object with a fake Bookmark object that has the desired bookmarkId.

    • withId

      static ResolvedBookmark withId(@NonNull @NonNull String bookmarkId, @NonNull @NonNull Object object, @NonNull @NonNull List<Problem> dataProblems, @NonNull @NonNull List<Problem> validationProblems)

      Useful testing constructor to return a pre-constructed Object with a fake Bookmark object that has the desired bookmarkId.

    • stub

      static ResolvedBookmark stub(@NonNull @NonNull Bookmark bookmark, @NonNull @NonNull Object object, @NonNull @NonNull List<Problem> dataProblems, @NonNull @NonNull List<Problem> validationProblems)

      Useful testing constructor to return a pre-constructed Object with a fake Bookmark object that has the desired bookmarkId.

    • getId

      default String getId()
      Returns:
      the id of the Bookmark
    • getBookmark

      Bookmark getBookmark()
      Returns:
      the Bookmark that has been resolved
    • getData

      default <T> ResultOrProblems<T> getData(Class<T> requiredType)
      Returns:
      the underlying data in the required type, or empty with an error if the data isn't of that type the result may contain errors that were encountered when trying to open the data with the given options which might be further to those that were encountered during validation.

      If validate() returned errors, then this method should return an empty result with an error saying there were validation errors stopping the data from being accessed

    • getIfType

      <T> Optional<ResultOrProblems<T>> getIfType(Class<T> requiredType)

      Performs a conditional cast of the resolved thing, even if there are validation issues that stopped the data from being accessed If validate() returned errors, then this method should return an empty result with an error saying there were validation errors stopping the data from being accessed

      Returns:
      Optional.empty() if the wrong type, or an optional of the required type.
    • getDataType

      Class<?> getDataType()
      Returns:
      the type of the resolved thing, regardless of whether it was successfully built or not.
    • isType

      default boolean isType(Class<?> requiredType)
      Returns:
      true if the resolved thing is of the given type
    • validate

      List<Problem> validate()
      Returns:
      a List of Problems encountered when performing a check of the bookmark's options. Implementations should avoid checking the data itself at this point, so that this can remain a "light" operation.
    • getScalarType

      Type getScalarType()

      Returns the RiskScape type that represents this data when extracted from a project and added in to a pipeline or expression as a scalar value.

      It is referred to as the scalar type to make it clear it's not the same as the Type of the data contained within it, e.g. the Struct type of the relation (non-scalar) vs RelationType that represents the relation itself (scalar).

    • hasValidationErrors

      default boolean hasValidationErrors()
      Returns:
      true if there are problems returned from validation that are errors (or worse)