Class Exemplar


  • public class Exemplar
    extends java.lang.Object
    Immutable data class holding an Exemplar.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.regex.Pattern labelNameRegex  
      private java.lang.String[] labels  
      private java.lang.Long timestampMs  
      private double value  
    • Constructor Summary

      Constructors 
      Constructor Description
      Exemplar​(double value, java.lang.Long timestampMs, java.lang.String... labels)
      Create an Exemplar
      Exemplar​(double value, java.lang.Long timestampMs, java.util.Map<java.lang.String,​java.lang.String> labels)
      Create an Exemplar
      Exemplar​(double value, java.lang.String... labels)
      Create an Exemplar without a timestamp
      Exemplar​(double value, java.util.Map<java.lang.String,​java.lang.String> labels)
      Create an Exemplar
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      java.lang.String getLabelName​(int i)
      Get the label name at index i.
      java.lang.String getLabelValue​(int i)
      Get the label value at index i.
      int getNumberOfLabels()  
      java.lang.Long getTimestampMs()  
      double getValue()  
      int hashCode()  
      static java.lang.String[] mapToArray​(java.util.Map<java.lang.String,​java.lang.String> labelMap)
      Convert the map to an array [key1, value1, key2, value2, ...].
      private java.lang.String[] sortedCopy​(java.lang.String... labels)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • labels

        private final java.lang.String[] labels
      • value

        private final double value
      • timestampMs

        private final java.lang.Long timestampMs
      • labelNameRegex

        private static final java.util.regex.Pattern labelNameRegex
    • Constructor Detail

      • Exemplar

        public Exemplar​(double value,
                        java.lang.String... labels)
        Create an Exemplar without a timestamp
        Parameters:
        value - the observed value
        labels - name/value pairs. Expecting an even number of strings. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
      • Exemplar

        public Exemplar​(double value,
                        java.lang.Long timestampMs,
                        java.lang.String... labels)
        Create an Exemplar
        Parameters:
        value - the observed value
        timestampMs - as in System.currentTimeMillis()
        labels - name/value pairs. Expecting an even number of strings. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
      • Exemplar

        public Exemplar​(double value,
                        java.util.Map<java.lang.String,​java.lang.String> labels)
        Create an Exemplar
        Parameters:
        value - the observed value
        labels - the labels. Must not be null. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
      • Exemplar

        public Exemplar​(double value,
                        java.lang.Long timestampMs,
                        java.util.Map<java.lang.String,​java.lang.String> labels)
        Create an Exemplar
        Parameters:
        value - the observed value
        timestampMs - as in System.currentTimeMillis()
        labels - the labels. Must not be null. The combined length of the label names and values must not exceed 128 UTF-8 characters. Neither a label name nor a label value may be null.
    • Method Detail

      • getNumberOfLabels

        public int getNumberOfLabels()
      • getLabelName

        public java.lang.String getLabelName​(int i)
        Get the label name at index i.
        Parameters:
        i - the index, must be >= 0 and < getNumberOfLabels().
        Returns:
        the label name at index i
      • getLabelValue

        public java.lang.String getLabelValue​(int i)
        Get the label value at index i.
        Parameters:
        i - the index, must be >= 0 and < getNumberOfLabels().
        Returns:
        the label value at index i
      • getValue

        public double getValue()
      • getTimestampMs

        public java.lang.Long getTimestampMs()
        Returns:
        Unix timestamp or null if no timestamp is present.
      • sortedCopy

        private java.lang.String[] sortedCopy​(java.lang.String... labels)
      • mapToArray

        public static java.lang.String[] mapToArray​(java.util.Map<java.lang.String,​java.lang.String> labelMap)
        Convert the map to an array [key1, value1, key2, value2, ...].
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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