Class Links

java.lang.Object
org.springframework.hateoas.Links
All Implemented Interfaces:
Iterable<Link>

public class Links extends Object implements Iterable<Link>
Value object to represent a list of Links.
Author:
Oliver Gierke, Greg Turnquist
  • Field Details

    • NONE

      public static final Links NONE
  • Method Details

    • of

      public static Links of(Link... links)
      Creates a new Links instance from the given Links.
      Parameters:
      links -
    • of

      public static Links of(Iterable<Link> links)
      Creates a new Links instance from the given Links.
      Parameters:
      links -
    • parse

      public static Links parse(@Nullable String source)
      Creates a Links instance from the given RFC-8288-compatible link format.
      Parameters:
      source - a comma separated list of Link representations.
      Returns:
      the Links represented by the given String.
    • and

      public Links and(Link... links)
      Creates a new Links instance with all given Links added. For conditional adding see merge(Link...).
      Parameters:
      links - must not be null.
      Returns:
      See Also:
    • andIf

      @SafeVarargs public final Links andIf(boolean condition, Link... links)
      Adds the given links if the given condition is true. The given Links will only be resolved if the given condition is true. Essentially syntactic sugar to write:
      if (a > 3) { links = links.and(…); } as links = link.andIf(a > 3, …);
      Parameters:
      condition -
      links - must not be null.
      Returns:
    • andIf

      @SafeVarargs public final Links andIf(boolean condition, Supplier<Link>... links)
      Adds the given links if the given condition is true. The given Suppliers will only be resolved if the given condition is true. Essentially syntactic sugar to write:
      if (a > 3) { links = links.and(…); } as links = link.andIf(a > 3, …);
      Parameters:
      condition -
      links - must not be null.
      Returns:
    • andIf

      public final Links andIf(boolean condition, Stream<Link> links)
      Adds the given links if the given condition is true. The given Stream will only be resolved if the given condition is true. Essentially syntactic sugar to write:
      if (a > 3) { links = links.and(…); } as links = link.andIf(a > 3, …);
      Parameters:
      condition -
      links - must not be null.
      Returns:
    • and

      public Links and(Iterable<Link> links)
      Creates a new Links instance with all given Links added. For conditional adding see merge(Iterable).
      Parameters:
      links - must not be null.
      Returns:
      See Also:
    • and

      public Links and(Stream<Link> links)
      Creates a new Links instance with all given Links added. For conditional adding see merge(Iterable).
      Parameters:
      links - must not be null.
      Returns:
      See Also:
    • merge

      public Links merge(Link... links)
      Merges the current Links with the given ones, skipping Links already contained in the current instance. For unconditional combination see and(Link...).
      Parameters:
      links - the Links to be merged, must not be null.
      Returns:
      See Also:
    • merge

      public Links merge(Stream<Link> links)
      Merges the current Links with the given ones, skipping Links already contained in the current instance. For unconditional combination see and(Stream).
      Parameters:
      links - the Links to be merged, must not be null.
      Returns:
      See Also:
    • merge

      public Links merge(Iterable<Link> links)
      Merges the current Links with the given ones, skipping Links already contained in the current instance. For unconditional combination see and(Iterable).
      Parameters:
      links - the Links to be merged, must not be null.
      Returns:
      See Also:
    • merge

      public Links merge(Links.MergeMode mode, Link... links)
      Merges the current Links with the given ones applying the given Links.MergeMode.
      Parameters:
      mode - must not be null.
      links - must not be null.
      Returns:
    • merge

      public Links merge(Links.MergeMode mode, Stream<Link> links)
      Merges the current Links with the given ones applying the given Links.MergeMode.
      Parameters:
      mode - must not be null.
      links - must not be null.
      Returns:
    • merge

      public Links merge(Links.MergeMode mode, Iterable<Link> links)
      Merges the current Links with the given ones applying the given Links.MergeMode.
      Parameters:
      mode - must not be null.
      links - must not be null.
      Returns:
    • without

      public Links without(LinkRelation relation)
      Returns a Links with all Links with the given LinkRelation removed.
      Parameters:
      relation - must not be null.
      Returns:
    • getLink

      public Optional<Link> getLink(String relation)
      Returns a Link with the given relation if contained in the current Links instance, Optional.empty() otherwise.
      Parameters:
      relation - must not be null or empty.
      Returns:
    • getLink

      public Optional<Link> getLink(LinkRelation rel)
      Returns the Link with the given rel.
      Parameters:
      rel - the relation type to lookup a link for.
      Returns:
      the link with the given rel or Optional#empty() if none found.
    • getRequiredLink

      public Link getRequiredLink(String rel)
      Returns the Link with the given relation.
      Parameters:
      rel - the relation type to lookup a link for.
      Returns:
      Throws:
      IllegalArgumentException - if no link with the given relation was present.
      Since:
      1.0
    • getRequiredLink

      public Link getRequiredLink(LinkRelation relation)
      Returns the Link with the given relation.
      Parameters:
      relation - the relation type to lookup a link for.
      Returns:
      Throws:
      IllegalArgumentException - if no link with the given relation was present.
    • hasLink

      public boolean hasLink(String relation)
      Returns whether the Links container contains a Link with the given relation.
      Parameters:
      relation - must not be null or empty.
      Returns:
    • hasLink

      public boolean hasLink(LinkRelation relation)
      Returns whether the current Links contains a Link with the given relation.
      Parameters:
      relation - must not be null.
      Returns:
    • isEmpty

      public boolean isEmpty()
      Returns whether the Links container is empty.
      Returns:
    • hasSize

      public boolean hasSize(long size)
      Returns whether the current Links has the given size.
      Parameters:
      size -
      Returns:
    • hasSingleLink

      public boolean hasSingleLink()
      Returns whether the Links contain a single Link.
      Returns:
    • stream

      public Stream<Link> stream()
      Creates a Stream of the current Links.
      Returns:
    • toList

      public List<Link> toList()
      Returns the current Links as List.
      Returns:
    • contains

      public boolean contains(Link... links)
      Returns whether the current Links contain all given Links (but potentially others).
      Parameters:
      links - must not be null.
      Returns:
    • contains

      public boolean contains(Iterable<Link> links)
      Returns whether the current Links contain all given Links (but potentially others).
      Parameters:
      links - must not be null.
      Returns:
    • containsSameLinksAs

      public boolean containsSameLinksAs(Iterable<Link> links)
      Returns whether the current Links instance contains exactly the same Link as the given one.
      Parameters:
      links - must not be null.
      Returns:
    • collector

      public static Collector<Link,?,Links> collector()
      Creates a new Collector to collect a Stream of Links into a Links instance.
      Returns:
      will never be null.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • iterator

      public Iterator<Link> iterator()
      Specified by:
      iterator in interface Iterable<Link>
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object