Class Slice

  • Direct Known Subclasses:
    MultiSlice

    public class Slice
    extends Object
    A Slice is used for two purposes
    1. To specify a subset of data to extract.
    2. To specify a subset of data as specified in a constraint.
    In case two, the "last" value of the slice may be undefined (e.q. specifying [0:]) and so they must be filled in at some point. Note that first cannot be undefined because it always defaults to zero; similarly stride defaults to one. Slice Supports iteration. Note that a slice is quite similar to a scalar DataIndex. Modifiied 10/15/2016 to support zero sized slices.
    • Field Detail

      • SCALARSLICES

        public static List<Slice> SCALARSLICES
      • SCALARSLICE

        public static Slice SCALARSLICE
      • constrained

        protected boolean constrained
        Indicate that this slice's first/last/stride were specifically set; typically from a constraint. Defaults to true.
    • Method Detail

      • finish

        public Slice finish()
                     throws DapException
        Perform sanity checks on a slice and repair where possible.
        Returns:
        this (fluent interface)
        Throws:
        DapException - if slice is malformed
      • getFirst

        public int getFirst()
      • getStop

        public int getStop()
      • getLast

        public int getLast()
      • getStride

        public int getStride()
      • getSize

        public int getSize()
      • getMax

        public int getMax()
      • isScalar

        public boolean isScalar()
      • isWhole

        public Boolean isWhole()
      • isConstrained

        public Boolean isConstrained()
      • setConstrained

        public Slice setConstrained​(Boolean tf)
      • getCount

        public int getCount()
        Compute the number of elements in the slice. Note that this is different from getStop() because stride is taken into account.
      • equals

        public boolean equals​(Object o)
        Compare two slices for equality
        Overrides:
        equals in class Object
        Parameters:
        o - the other slice to compare with
        Returns:
        true if this and other are the same, false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString​(boolean withbrackets)
      • toConstraintString

        public String toConstraintString()
                                  throws DapException
        Convert this slice to a string suitable for use in a constraint
        Returns:
        constraint usable string
        Throws:
        DapException
      • compose

        public static Slice compose​(Slice target,
                                    Slice src)
                             throws DapException
        Take two slices and compose src wrt target Assume neither argument is null. This code should match ucar.ma2.Section in thredds and dceconstraint.c in the netcdf-c library.
        Parameters:
        target -
        src -
        Returns:
        new, composed Range
        Throws:
        DapException
      • getSubSlices

        public List<Slice> getSubSlices()
      • getSubSlice

        public Slice getSubSlice​(int i)