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

org.graylog2.restclient.lib.timeranges.RelativeRange Maven / Gradle / Ivy

The newest version!
/**
 * This file is part of Graylog.
 *
 * Graylog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Graylog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graylog.  If not, see .
 */
package org.graylog2.restclient.lib.timeranges;

import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class RelativeRange extends TimeRange {

    private final int range;

    public RelativeRange(int range) throws InvalidRangeParametersException {
        if (range < 0) {
            throw new InvalidRangeParametersException();
        }

        this.range = range;
    }

    public TimeRange.Type getType() {
        return Type.RELATIVE;
    }

    @Override
    public Map getQueryParams() {
        return ImmutableMap.of(
                "range_type", getType().toString().toLowerCase(),
                "range", String.valueOf(range));
    }

    @Override
    public String toString() {
        return "Relative time range [" + this.getClass().getCanonicalName() + "] - range: " + this.range;
    }

    /* Indicates if the range value is 0 */
    public boolean isEmptyRange() {
        return range == 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy