Package de.sciss.io

Class Span

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class Span
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    A struct class: a span between a start and end point in one dimensional space. The start point is considered inclusive while the end point is considered exclusive. In Meloncillo, it is mainly used to describe a time span in sense rate frames.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      long start
      The span start should be treated as if it was immutable!
      static java.util.Comparator startComparator  
      long stop
      The span start should be treated as if it was immutable!
      static java.util.Comparator stopComparator  
    • Constructor Summary

      Constructors 
      Constructor Description
      Span()
      Create a new empty span whose start and stop are zero.
      Span​(long start, long stop)
      Creates a span with the given start and stop points.
      Span​(Span span)
      Create a span with the start and stop points copied from another span.
    • Field Detail

      • startComparator

        public static final java.util.Comparator startComparator
      • stopComparator

        public static final java.util.Comparator stopComparator
      • start

        public final long start
        The span start should be treated as if it was immutable!
      • stop

        public final long stop
        The span start should be treated as if it was immutable!
    • Constructor Detail

      • Span

        public Span()
        Create a new empty span whose start and stop are zero.
      • Span

        public Span​(long start,
                    long stop)
        Creates a span with the given start and stop points. The caller has to ensure that start <= stop (this is not checked)
        Parameters:
        start - beginning of the span
        stop - end of the span
      • Span

        public Span​(Span span)
        Create a span with the start and stop points copied from another span.
        Parameters:
        span - template span whose start and end are copied
    • Method Detail

      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a new span which is equal to this one. CloneNotSupportedException is never thrown.
        Overrides:
        clone in class java.lang.Object
        Returns:
        a new span with the same start and stop as this span
        Throws:
        java.lang.CloneNotSupportedException
      • contains

        public boolean contains​(long position)
        Checks if a position lies within the span.
        Returns:
        true, if start <= position < stop
      • contains

        public boolean contains​(Span anotherSpan)
        Checks if another span lies within the span.
        Parameters:
        anotherSpan - second span, may be null (in this case returns false)
        Returns:
        true, if anotherSpan.start >= this.span && anotherSpan.stop <= this.stop
      • overlaps

        public boolean overlaps​(Span anotherSpan)
        Checks if a two spans overlap each other.
        Parameters:
        anotherSpan - second span, may be null (in this case returns false)
        Returns:
        true, if the spans overlap each other
      • touches

        public boolean touches​(Span anotherSpan)
        Checks if a two spans overlap or touch each other.
        Parameters:
        anotherSpan - second span, may be null (in this case returns false)
        Returns:
        true, if the spans overlap each other
      • isEmpty

        public boolean isEmpty()
        Checks if the span is empty.
        Returns:
        true, if start == stop
      • equals

        public boolean equals​(java.lang.Object o)
        Checks if this span is equal to an object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - an object to compare to this span
        Returns:
        true, if o is a span with the same start and end point
      • hashCode

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

        public long getStart()
        Queries the span's start.
        Returns:
        the start point of the span
      • getStop

        public long getStop()
        Queries the span's end.
        Returns:
        the end point of the span
      • getLength

        public long getLength()
        Queries the span's extent (duration, length etc.)
        Returns:
        length of the span, i.e. stop - start
      • toString

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

        public static Span union​(Span span1,
                                 Span span2)
        Union operation on two spans.
        Parameters:
        span1 - first span to fuse (may be null)
        span2 - second span to fuse (may be null)
        Returns:
        a new span whose extension covers both span1 and span2, or null if both span1 and span2 are null
      • union

        public Span union​(Span anotherSpan)
      • intersection

        public static Span intersection​(Span span1,
                                        Span span2)
      • intersection

        public Span intersection​(Span anotherSpan)
      • clip

        public long clip​(long pos)
      • replaceStart

        public Span replaceStart​(long newStart)
      • replaceStop

        public Span replaceStop​(long newStop)
      • shift

        public Span shift​(long delta)