Class ItemsByTag


  • public final class ItemsByTag
    extends java.lang.Object
    A heterogeneous map from Tag<E> to E, where E can be different for each tag. The value associated with a tag may be null.

    This is a less type-safe, but more flexible alternative to a tuple. The tuple has a fixed number of integer-indexed, statically-typed fields, and ItemsByTag has a variable number of tag-indexed fields whose whose static type is encoded in the tags.

    Since:
    Jet 3.0
    • Constructor Summary

      Constructors 
      Constructor Description
      ItemsByTag()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      <E> E get​(Tag<E> tag)
      Retrieves the value associated with the supplied tag and throws an exception if there is none.
      int hashCode()  
      static ItemsByTag itemsByTag​(java.lang.Object... tagsAndVals)
      Accepts an argument list of alternating tags and values, interprets them as a list of tag-value pairs, and returns an ItemsByTag populated with these pairs.
      <E> void put​(Tag<E> tag, E value)
      Associates the supplied value with the supplied tag.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • ItemsByTag

        public ItemsByTag()
    • Method Detail

      • itemsByTag

        @Nonnull
        public static ItemsByTag itemsByTag​(@Nonnull
                                            java.lang.Object... tagsAndVals)
        Accepts an argument list of alternating tags and values, interprets them as a list of tag-value pairs, and returns an ItemsByTag populated with these pairs.
      • get

        @Nullable
        public <E> E get​(@Nonnull
                         Tag<E> tag)
        Retrieves the value associated with the supplied tag and throws an exception if there is none. The tag argument must not be null, but the returned value may be, if a null value is explicitly associated with a tag.
        Throws:
        java.lang.IllegalArgumentException - if there is no value associated with the supplied tag
      • put

        public <E> void put​(@Nonnull
                            Tag<E> tag,
                            @Nullable
                            E value)
        Associates the supplied value with the supplied tag. The tag must not be null, but the value may be, and in that case the tag will be associated with a null value.
      • 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