001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2010–2011 ApexIdentity Inc.
015 * Portions Copyright 2011-2014 ForgeRock AS.
016 */
017
018package org.forgerock.openig.log;
019
020/**
021 * Log entry data that provides a measurement.
022 */
023public class LogMetric {
024
025    /** The unit of measurement the metric is expressed in. */
026    private final String units;
027
028    /** The numeric value of the metric. */
029    private final Number value;
030
031    /**
032     * Constructs a new metric with the specific value and units.
033     *
034     * @param value
035     *            the numeric value of the metric.
036     * @param units
037     *            the unit of measurement that the metric is expressed in.
038     */
039    public LogMetric(final Number value, final String units) {
040        this.value = value;
041        this.units = units;
042    }
043
044    /**
045     * Returns the unit of measurement the metric is expressed in.
046     *
047     * @return The unit of measurement the metric is expressed in.
048     */
049    public String getUnits() {
050        return units;
051    }
052
053    /**
054     * Returns the numeric value of the metric.
055     *
056     * @return The numeric value of the metric.
057     */
058    public Number getValue() {
059        return value;
060    }
061
062    /**
063     * Returns the metric in the form <em>value</em> SP <em>units</em>. For
064     * example, if value is {@code 100} and units are {@code "ms"}, then the
065     * returned value would be {@code "100 ms"}.
066     *
067     * @return the metric in the form <em>value</em> SP <em>units</em>.
068     */
069    @Override
070    public String toString() {
071        return getValue().toString() + ' ' + getUnits();
072    }
073}