Package generic

Class Span.DefaultSpanMap<N,S extends Span<N,S>,V>

java.lang.Object
generic.Span.DefaultSpanMap<N,S,V>
Type Parameters:
N - the type of endpoints
S - the type of spans
V - the type of values
All Implemented Interfaces:
Span.MutableSpanMap<N,S,V>, Span.SpanMap<N,S,V>
Direct Known Subclasses:
ULongSpan.DefaultULongSpanMap
Enclosing interface:
Span<N,S extends Span<N,S>>

public static class Span.DefaultSpanMap<N,S extends Span<N,S>,V> extends Object implements Span.MutableSpanMap<N,S,V>
The default implementation of Span.SpanMap and Span.MutableSpanMap using an interval tree

The interfaces can prevent accidental mutation of a map where it shouldn't be allowed; however, nothing prevents a client from casting to the mutable interface. If proper immutability is required, this will need to be wrapped or extended to prevent mutation.

  • Constructor Details

    • DefaultSpanMap

      public DefaultSpanMap(Span.Domain<N,S> domain)
      Create a span map on the given domain

      Extensions should invoke this as a super constructor with a fixed domain. See ULongSpan.DefaultULongSpanMap for an example.

      Parameters:
      domain - the domain
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

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

      public boolean isEmpty()
      Description copied from interface: Span.SpanMap
      Check if this map has any entries
      Specified by:
      isEmpty in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Returns:
      true if empty
    • spans

      public Set<S> spans()
      Description copied from interface: Span.SpanMap
      Get the spans in this map

      Note that the behavior regarding a copy versus a view is not specified. Clients should not rely on one or the other.

      Specified by:
      spans in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Returns:
      the set of spans
    • bound

      public S bound()
      Description copied from interface: Span.SpanMap
      Get a span which encloses all spans in the map
      Specified by:
      bound in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Returns:
      the bounding span
    • values

      public Collection<V> values()
      Description copied from interface: Span.SpanMap
      Get the values in this map

      Note that the behavior regarding a copy versus a view is not specified. Clients should not rely on one of the other.

      Specified by:
      values in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Returns:
      the collection of values
    • entries

      public Set<Map.Entry<S,V>> entries()
      Description copied from interface: Span.SpanMap
      Get the entries in this map

      Note that the behavior regarding a copy versus a view is not specified. Clients should not rely on one or the other.

      Specified by:
      entries in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Returns:
      the set of entries
    • getEntry

      public Map.Entry<S,V> getEntry(N n)
      Description copied from interface: Span.SpanMap
      Get the entry whose span contains the given key
      Specified by:
      getEntry in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Parameters:
      n - the key
      Returns:
      the entry, or null
    • get

      public V get(N n)
      Description copied from interface: Span.SpanMap
      Get the value of the given key

      Note that a null return could indicate either that no entry has a span containing the given key, or that the entry whose span contains it has the null value. To distinguish the two, consider using Span.SpanMap.getEntry(Object).

      Specified by:
      get in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Parameters:
      n - the key
      Returns:
      the value, or null
    • subMap

      protected NavigableMap<N,Map.Entry<S,V>> subMap(N min, N max)
      Get the portion of the interval tree whose entries intersect the given span
      Parameters:
      min - the lower endpoint of the span
      max - the upper endpoint of the span
      Returns:
      the sub map
    • intersectingEntries

      public Collection<Map.Entry<S,V>> intersectingEntries(S s)
      Description copied from interface: Span.SpanMap
      Iterate over all entries whose spans intersect the given span
      Specified by:
      intersectingEntries in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Parameters:
      s - the span
      Returns:
      an iterable of entries
    • intersectingSpans

      public Iterable<S> intersectingSpans(S s)
      Description copied from interface: Span.SpanMap
      Iterate over all spans in the map that intersect the given span
      Specified by:
      intersectingSpans in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Parameters:
      s - the span
      Returns:
      an iterable of spans
    • intersects

      public boolean intersects(S s)
      Description copied from interface: Span.SpanMap
      Check if any span in the map intersects the given span
      Specified by:
      intersects in interface Span.SpanMap<N,S extends Span<N,S>,V>
      Parameters:
      s - the span
      Returns:
      true if any span in the map intersects it
    • put

      public void put(S s, V v)
      Description copied from interface: Span.MutableSpanMap
      Put an entry, mapping all keys contains in the span to the given value

      Each key can only be mapped to a single value. Thus existing entries having the same value may be coalesced to this new entry. Existing entries having a different value will be truncated or deleted to make room for this entry.

      Specified by:
      put in interface Span.MutableSpanMap<N,S extends Span<N,S>,V>
      Parameters:
      s - the span
      v - the value
    • putAll

      public void putAll(Span.SpanMap<N,S,V> map)
      Description copied from interface: Span.MutableSpanMap
      Copy all entries from the given map into this one

      The entries from both maps may be coalesced when entered into this one. (The given map remains unmodified.) The entries in this map may be truncated or deleted to make room for those in the given map.

      Specified by:
      putAll in interface Span.MutableSpanMap<N,S extends Span<N,S>,V>
      Parameters:
      map - the other map
    • remove

      public void remove(S s)
      Description copied from interface: Span.MutableSpanMap
      Delete all keys in the given span

      Entries which intersect the given span are truncated. Entries which are enclosed are deleted, such that every key in the given span is no longer mapped to a value.

      Specified by:
      remove in interface Span.MutableSpanMap<N,S extends Span<N,S>,V>
      Parameters:
      s - the span
    • clear

      public void clear()
      Description copied from interface: Span.MutableSpanMap
      Remove all entries from the map
      Specified by:
      clear in interface Span.MutableSpanMap<N,S extends Span<N,S>,V>