All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arpnetworking.metrics.impl.TsdEvent Maven / Gradle / Ivy

/**
 * Copyright 2015 Groupon.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.arpnetworking.metrics.impl;

import com.arpnetworking.metrics.Event;
import com.arpnetworking.metrics.Quantity;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Default implementation of Event.
 *
 * @author Ville Koskela (vkoskela at groupon dot com)
 */
/* package private */ final class TsdEvent implements Event {

    /**
     * Public constructor.
     *
     * NOTE: This method does not perform a deep copy of the provided
     * data structures. Callers are expected to not modify these data
     * structures after passing them to this constructor. This is acceptable
     * since this class is for internal implementation only.
     *
     * @param annotations The annotations.
     * @param timerSamples The timer samples.
     * @param counterSamples The counter samples.
     * @param gaugeSamples The gauge samples.
     */
    /* package private */ TsdEvent(
            final Map annotations,
            final Map> timerSamples,
            final Map> counterSamples,
            final Map> gaugeSamples) {
        _annotations = annotations;
        _timerSamples = timerSamples;
        _counterSamples = counterSamples;
        _gaugeSamples = gaugeSamples;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Map getAnnotations() {
        return Collections.unmodifiableMap(_annotations);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Map> getTimerSamples() {
        return Collections.unmodifiableMap(_timerSamples);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Map> getCounterSamples() {
        return Collections.unmodifiableMap(_counterSamples);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Map> getGaugeSamples() {
        return Collections.unmodifiableMap(_gaugeSamples);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof TsdEvent)) {
            return false;
        }
        final TsdEvent otherEvent = (TsdEvent) other;
        return Objects.equals(_annotations, otherEvent._annotations)
                && Objects.equals(_counterSamples, otherEvent._counterSamples)
                && Objects.equals(_timerSamples, otherEvent._timerSamples)
                && Objects.equals(_gaugeSamples, otherEvent._gaugeSamples);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return Objects.hash(_annotations, _counterSamples, _timerSamples, _gaugeSamples);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return String.format(
                "TsdEvent{Annotations=%s, TimerSamples=%s, CounterSamples=%s, GaugeSamples=%s}",
                _annotations,
                _timerSamples,
                _counterSamples,
                _gaugeSamples);
    }

    private final Map _annotations;
    private final Map> _timerSamples;
    private final Map> _counterSamples;
    private final Map> _gaugeSamples;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy