Class ResourceAttributes

java.lang.Object
com.janeirodigital.shapetrees.core.resources.ResourceAttributes
Direct Known Subclasses:
RelationAttributes

public class ResourceAttributes extends Object
The HttpClientHeaders object is a multi-map with some constructors and put-ers tailored to the shapetrees-java libraries. The only behavior that's at all HTTP-specific is the parseLinkHeaders factory which includes logic for HTTP Link headers.
  • Field Details

  • Constructor Details

    • ResourceAttributes

      public ResourceAttributes()
      construct a case-insensitive ResourceAttributes container
    • ResourceAttributes

      public ResourceAttributes(String attr, String value)
      construct a case-insensitive ResourceAttributes container and set attr to value if both are not null.
      Parameters:
      attr - attribute (header) name to set
      value - String value to assign to attr
    • ResourceAttributes

      public ResourceAttributes(Map<String,List<String>> newMap)
      Construct ResourceAttributes with passed map, which may be case-sensitive.
      Parameters:
      newMap - replacement for myMapOfLists
  • Method Details

    • parseLinkHeaders

      public static RelationAttributes parseLinkHeaders(List<String> headerValues)
      Re-use HttpClientHeaders to capture link headers as a mapping from link relation to list of values This is really a constructor but a named static function clarifies its intention.
      Parameters:
      headerValues - Header values for Link headers
      Returns:
      subset of this matching the pattern
    • maybePlus

      public ResourceAttributes maybePlus(String attr, String value)
      make a new HttpClientHeaders with the additional attr/value set.
      Parameters:
      attr - attribute (header) name to set
      value - String value to assign to attr
      Returns:
      original HttpClientHeaders if no change is made; otherwise a new copy.
    • maybeSet

      public void maybeSet(String attr, String value)
      set attr to value if both are not null.
      Parameters:
      attr - attribute (header) name to set
      value - String value to assign to attr
    • setAll

      public void setAll(String attr, List<String> values)
      replaces the list of attrs (without regard to nulls)
      Parameters:
      attr - attribute (header) name to set
      values - String values to assign to attr
    • toMultimap

      public Map<String,List<String>> toMultimap()
      Returns a map of attributes to lists of values
    • toList

      public String[] toList(String... exclusions)
      Returns an array with alternating attributes and values.
      Parameters:
      exclusions - set of headers to exclude from returned array. (This is useful for HttpRequest.Builder().)
    • firstValue

      public Optional<String> firstValue(String name)
      Returns an Optional containing the first header string value of the given named (and possibly multi-valued) header. If the header is not present, then the returned Optional is empty.
      Parameters:
      name - the header name
      Returns:
      an Optional<String> containing the first named header string value, if present
    • allValues

      public List<String> allValues(String name)
      Returns an unmodifiable List of all of the header string values of the given named header. Always returns a List, which may be empty if the header is not present.
      Parameters:
      name - the header name
      Returns:
      a List of headers string values
    • isEmpty

      public boolean isEmpty()
      Identifies whether the ResourceAttributes are empty
      Returns:
      True when there are no attributes
    • toString

      public String toString()
      Overrides:
      toString in class Object