Class Entity<Header extends ToHttpHeaders>

  • Type Parameters:
    Header - the type of the entity headers; in practice this will be either SnapshotEntityHeader or FeedEntityHeader
    All Implemented Interfaces:
    ToHttpHeaders

    public final class Entity<Header extends ToHttpHeaders>
    extends java.lang.Object
    implements ToHttpHeaders
    The Entity class represents a feed or snapshot entity. It consists of entity headers, a body, and an optional piece of user-specified metadata.
    • Constructor Summary

      Constructors 
      Constructor Description
      Entity​(Header header, @NonNull Body body)
      Create a new entity with empty userData.
      Entity​(Header header, @NonNull Body body, @NonNull java.util.Optional<@NonNull java.lang.Object> userData)
      Creates a new Entity instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      @NonNull Body body()
      The entity's body.
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      Header header()
      The entity's headers.
      @NonNull HttpHeaders toHttpHeaders()
      Return all headers for this entity.
      java.lang.String toString()  
      @NonNull java.util.Optional<@NonNull java.lang.Object> userData()
      An optional piece of user-specified metadata.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Entity

        public Entity​(@NonNull
                      Header header,
                      @NonNull
                      @NonNull Body body)
        Create a new entity with empty userData.
        Parameters:
        header - the entity header
        body - the entity body
      • Entity

        public Entity​(@NonNull
                      Header header,
                      @NonNull
                      @NonNull Body body,
                      @NonNull
                      @NonNull java.util.Optional<@NonNull java.lang.Object> userData)
        Creates a new Entity instance.
        Parameters:
        header - The entity's headers. This does not include Content-Type and Content-Length which are associated with body().
        body - The entity's body. This includes the actual bytes as well as the Content-Type and Content-Length.
        userData - An optional piece of user-specified metadata. The library implementation never touches or interprets it. It exists exclusively to allow library users to carry additional information with an entity as it passes through the library. This means that it is up to the library user how to handle this field at boundaries (e.g. when storing entities in a database): it's not necessary to store and load this field if you don't ever use it.

        This field is an internal aspect of the library intended for producers: it is not part of the data format and won't be included in a consumable snapshot or feed. When consuming entities from a feed or snapshot, this field will always be empty.

    • Method Detail

      • toHttpHeaders

        @NonNull
        public @NonNull HttpHeaders toHttpHeaders()
        Return all headers for this entity. This combines the actual entity headers with the Content-Type and Content-Length headers from the body.
        Specified by:
        toHttpHeaders in interface ToHttpHeaders
        Returns:
        all headers for this entity
      • header

        @NonNull
        public Header header()
        The entity's headers. This does not include Content-Type and Content-Length which are associated with body().
      • body

        @NonNull
        public @NonNull Body body()
        The entity's body. This includes the actual bytes as well as the Content-Type and Content-Length.
      • userData

        @NonNull
        public @NonNull java.util.Optional<@NonNull java.lang.Object> userData()
        An optional piece of user-specified metadata. The library implementation never touches or interprets it. It exists exclusively to allow library users to carry additional information with an entity as it passes through the library. This means that it is up to the library user how to handle this field at boundaries (e.g. when storing entities in a database): it's not necessary to store and load this field if you don't ever use it.

        This field is an internal aspect of the library intended for producers: it is not part of the data format and won't be included in a consumable snapshot or feed. When consuming entities from a feed or snapshot, this field will always be empty.

      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object