Interface MeasurementList

All Superinterfaces:
AutoCloseable, Serializable

public interface MeasurementList extends Serializable, AutoCloseable
Interface defining a feature measurement list, consisting of key value pairs.

To help enable efficiency for large sets of PathObjects requiring measurement lists, only String keys and numeric values are included.

In QuPath v0.4.0 several methods were deprecated, and these were removed in v0.6.0. The main aim was to make the API more consistent and easier to use.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Enum representing different types of measurement list, with different priorities regarding flexibility and efficiency.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get a map view of this measurements list.
    void
    Remove all the measurements from the list.
    default void
    Close the list.
    default boolean
    Returns true if this list contains a measurement with the specified name.
    double
    get(String name)
    Get value for the measurement with the specified name.
    getByIndex(int ind)
    Get an immutable representation of a single measurement.
    default List<String>
    Deprecated.
    v0.6.0 use getNames() instead
    Get an unmodifiable list of all measurements.
    Get the names of all measurements currently in the list.
    default double
    getOrDefault(String name, double defaultValue)
    Get the specified measurement, or the provided default value if it is not contained in the list.
    default boolean
    Returns true if the list does not contain any measurements.
    default Set<String>
    Get all available names as a set.
    void
    put(String name, double value)
    Put a measurement value into the list, replacing any previous measurement with the same name.
    default void
    putAll(Collection<? extends Measurement> list)
    Put all the measurements from the specified list into this one
    default void
    putAll(Map<String,? extends Number> map)
    Put all the values from the specified map into this list
    default void
    Put all the measurements from the specified list into this one
    double
    remove(String name)
    Remove a named measurement
    void
    removeAll(String... measurementNames)
    Remove all the measurements with the specified names.
    default void
    removeMeasurements(String... measurementNames)
    Deprecated.
    v0.6.0 use removeAll(String...) instead
    default int
    Returns the number of measurements in the list.
    double[]
    Get a snapshot of all measurement values as a double array.
  • Method Details

    • put

      void put(String name, double value)
      Put a measurement value into the list, replacing any previous measurement with the same name.

      This is similar to adding, but with a check to remove any existing measurement with the same name (if multiple measurements have the same name, the first will be replaced).

      Parameters:
      name -
      value -
      Since:
      v0.4.0
    • getMeasurements

      List<Measurement> getMeasurements()
      Get an unmodifiable list of all measurements. This provides a snapshot of the current measurements, and should not be affected by changes to the list.
      Returns:
    • getByIndex

      Measurement getByIndex(int ind)
      Get an immutable representation of a single measurement. This provides a snapshot of the current measurement, and should not be affected by changes to the list.
      Returns:
    • getOrDefault

      default double getOrDefault(String name, double defaultValue)
      Get the specified measurement, or the provided default value if it is not contained in the list.

      This provides an alternative to get(String) which always uses a default of Double.NaN.

      Parameters:
      name -
      defaultValue -
      Returns:
      Since:
      v0.4.0
    • values

      double[] values()
      Get a snapshot of all measurement values as a double array. Changes to the array will not impact the measurement list.
      Returns:
      Since:
      v0.4.0
    • remove

      double remove(String name)
      Remove a named measurement
      Parameters:
      name -
      Returns:
      the value that was removed, or Double.NaN if the value was not in the list
      Since:
      v0.4.0
    • putAll

      default void putAll(Map<String,? extends Number> map)
      Put all the values from the specified map into this list
      Parameters:
      map -
      Since:
      v0.4.0
    • putAll

      default void putAll(MeasurementList list)
      Put all the measurements from the specified list into this one
      Parameters:
      list -
      Since:
      v0.4.0
    • putAll

      default void putAll(Collection<? extends Measurement> list)
      Put all the measurements from the specified list into this one
      Parameters:
      list -
      Since:
      v0.4.0
    • keySet

      default Set<String> keySet()
      Get all available names as a set.
      Returns:
      Implementation Note
      the current implementation is much less efficient than getNames(), but is included to more closely resemble Map behavior. The list of names and size of the returned set here should be identical; if they aren't, duplicate names seem to be present and a warning is logged. This shouldn't be possible with new code, but could conceivably occur if a list from a pre-v0.4.0 QuPath version is deserialized (or there is a bad bug somewhere here - if so, please report it!).
    • getNames

      List<String> getNames()
      Get the names of all measurements currently in the list. Note that this method should return an unmodifiable snapshot of the current names, and not be affected by changes to the list.
      Returns:
    • getMeasurementNames

      @Deprecated default List<String> getMeasurementNames()
      Deprecated.
      v0.6.0 use getNames() instead
      Get the names of all measurements currently in the list. Note that this method should return an unmodifiable snapshot of the current names, and not be affected by changes to the list.
      Returns:
    • get

      double get(String name)
      Get value for the measurement with the specified name.
      Parameters:
      name -
      Returns:
      the measurement value, or Double.NaN if the measurement is not available
      Since:
      v0.4.0
      See Also:
    • containsKey

      default boolean containsKey(String name)
      Returns true if this list contains a measurement with the specified name.
      Parameters:
      name -
      Returns:
      Since:
      v0.4.0
    • isEmpty

      default boolean isEmpty()
      Returns true if the list does not contain any measurements.
      Returns:
    • size

      default int size()
      Returns the number of measurements in the list.
      Returns:
    • close

      default void close()
      Close the list. Depending on the implementation, the list may then adjust its internal storage to be more efficient.
      Specified by:
      close in interface AutoCloseable
    • removeAll

      void removeAll(String... measurementNames)
      Remove all the measurements with the specified names.
      Parameters:
      measurementNames -
    • removeMeasurements

      @Deprecated default void removeMeasurements(String... measurementNames)
      Deprecated.
      v0.6.0 use removeAll(String...) instead
      Remove all the measurements with the specified names.
      Parameters:
      measurementNames -
    • clear

      void clear()
      Remove all the measurements from the list.
    • asMap

      Map<String,Number> asMap()
      Get a map view of this measurements list. This is a map that is backed by the list, which means that putting or retrieving elements modifies the list. It also means that there can be some loss of precision if the list does not support Double (e.g. it uses a float array for storage).

      Returns:
      a map view of this measurement list
      Implementation Requirements
      The returned map should already be synchronized.