Class ResourceMessage

java.lang.Object
com.thecsdev.common.resource.ResourceMessage
Direct Known Subclasses:
ResourceRequest, ResourceResponse

public abstract sealed class ResourceMessage extends Object permits ResourceRequest, ResourceResponse
An abstract base class representing a message related to a resource identified by a URI.
This class serves as a common foundation for both ResourceRequest and ResourceResponse.
  • Constructor Details

  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable @Nullable Object obj)
      Overrides:
      equals in class Object
    • getUri

      @NotNull public final @NotNull URI getUri()
      Returns the URI associated with this resource message.
    • getMetadata

      @NotNull public final @NotNull Map<String, List<String>> getMetadata()
      Returns an unmodifiable Map containing metadata associated with the resource message. This may include HTTP headers, system metadata, or other relevant information. Meanings vary based on URI.getScheme().

      The returned Map and all of its List entries are all unmodifiable.

    • has

      public final boolean has(@NotNull @NotNull String metadataName) throws NullPointerException
      Checks if the specified metadata entry exists.
      Parameters:
      metadataName - The name of the metadata entry.
      Throws:
      NullPointerException - If the argument is null.
    • getFirst

      @Nullable public final @Nullable String getFirst(@NotNull @NotNull String metadataName) throws NullPointerException
      Returns the first metadata value associated with the specified metadata name.
      Parameters:
      metadataName - The name of the metadata entry.
      Throws:
      NullPointerException - If a NotNull argument is null.
    • getFirstOrThrow

      @NotNull public final @NotNull String getFirstOrThrow(@NotNull @NotNull String metadataName) throws NullPointerException, NoSuchElementException
      Returns the first metadata value associated with the specified metadata name, or throws NoSuchElementException if not found.
      Parameters:
      metadataName - The name of the metadata entry.
      Throws:
      NullPointerException - If a NotNull argument is null.
      NoSuchElementException - If no metadata entry is found for the specified name.
    • getFirst

      @Contract("_, null -> _; _, !null -> !null") @Nullable public final @Nullable String getFirst(@NotNull @NotNull String metadataName, @Nullable @Nullable String defaultValue) throws NullPointerException
      Returns the first metadata value associated with the specified metadata name.
      Parameters:
      metadataName - The name of the metadata entry.
      defaultValue - The default value to return if the metadata entry is not found.
      Throws:
      NullPointerException - If a NotNull argument is null.
    • getData

      public final byte @NotNull [] getData()
      Returns the byte[] containing the raw byte data of this ResourceMessage.