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.

QuPath v0.4.0: MeasurementList was updated to have more map-like behavior, while still using primitive values. In particular, addMeasurement(String, double) was deprecated and now simply defers to put(String, double).

Additionally, the wordy putMeasurement(String, double) and getMeasurementValue(String) were deprecated in favor of put(String, double) and get(String) - which do the same thing, but with more familiar syntax.

Author:
Pete Bankhead
  • Method Details

    • addMeasurement

      @Deprecated default boolean addMeasurement(String name, double value)
      Deprecated.
      v0.4.0 use put(String, double) instead
      Add a new measurement. No check is made to ensure the name is unique, and in general put(String, double) is to be preferred.
      Parameters:
      name -
      value -
      Returns:
      See Also:
    • putMeasurement

      @Deprecated Measurement putMeasurement(Measurement measurement)
      Deprecated.
      since v0.4.0, since there is no real need to create a Measurement object and we don't currently use dynamic measurements
      Put a measurement into the list, replacing any previous measurement with the same name.

      This is similar to add, 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).

      While it's probably a good idea for measurements to always have unique names, for some implementations putMeasurement can be must slower than add or addMeasurement - so adding should be preferred if it is known that a measurement with the same name is not present.

      Parameters:
      measurement -
      Returns:
    • 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
    • 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
    • containsNamedMeasurement

      @Deprecated default boolean containsNamedMeasurement(String name)
      Deprecated.
      since v0.4.0; replaced by containsKey(String)
      Query if a value with the specified name is in the list.
      Parameters:
      name -
      Returns:
    • values

      default double[] values()
      Get all measurement values as a double array
      Returns:
      Since:
      v0.4.0
    • getMeasurementValue

      @Deprecated default double getMeasurementValue(String name)
      Deprecated.
      since v0.4.0; use get(String) instead
      Get the measurement with the specified name.
      Parameters:
      name -
      Returns:
      the value, or Double.NaN if no measurement is available with the specified name
    • putMeasurement

      @Deprecated default void putMeasurement(String name, double value)
      Deprecated.
      since v0.4.0; replaced by put(String, double)
      Alternative method to call putMeasurement(String, double)
      Parameters:
      name -
      value -
    • remove

      default 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 values 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:
    • getMeasurementNames

      List<String> getMeasurementNames()
      Get the names of all measurements currently in the list.
      Returns:
    • getMeasurementName

      @Deprecated String getMeasurementName(int ind)
      Deprecated.
      since v0.4.0; using names is preferred over indexing but getMeasurementNames() can still be used
      Get name for the measurement at the specified index in the list.
      Parameters:
      ind -
      Returns:
    • getMeasurementValue

      @Deprecated double getMeasurementValue(int ind)
      Deprecated.
      since v0.4.0; using get(String) is preferred over using an index
      Get value for the measurement at the specified index in the list.
      Parameters:
      ind -
      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

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

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

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

      @Deprecated boolean supportsDynamicMeasurements()
      Deprecated.
      since v0.4.0; the initial implementation of dynamic measurements was never used
      Returns true if the list supports dynamic measurements. Dynamic measurements can change their values, and in the interests of efficiency are not supported by all MeasurementList implementations.

      Use of this is strongly discouraged.

      Returns:
    • close

      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
    • removeMeasurements

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

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

      default 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