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

io.deepsense.neptune.clientlibrary.models.impl.charts.OnlineChart Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
/**
 * Copyright (c) 2016, CodiLime Inc.
 */

package io.deepsense.neptune.clientlibrary.models.impl.charts;

import com.google.common.base.Preconditions;
import io.deepsense.neptune.apiclient.ApiException;
import io.deepsense.neptune.clientlibrary.models.Channel;
import io.deepsense.neptune.clientlibrary.models.Chart;
import io.deepsense.neptune.clientlibrary.models.ChartSeries;
import io.deepsense.neptune.clientlibrary.models.ChartSeriesType;
import io.deepsense.neptune.clientlibrary.services.apiservice.ApiService;
import io.deepsense.neptune.clientlibrary.utils.exceptions.ApiExceptionWrapper;

import java.util.Collection;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class OnlineChart implements Chart {

    private final ApiService apiService;
    private final UUID jobId;
    private final UUID id;
    private final String name;
    private final Collection seriesCollection;

    public OnlineChart(ApiService apiService,
                       UUID jobId,
                       UUID id,
                       String name,
                       Iterable seriesCollection) {
        this.apiService = Preconditions.checkNotNull(apiService);
        this.jobId = Preconditions.checkNotNull(jobId);
        this.id = Preconditions.checkNotNull(id);
        this.name = Preconditions.checkNotNull(name);
        this.seriesCollection = StreamSupport
                .stream(Preconditions.checkNotNull(seriesCollection).spliterator(), false)
                .collect(Collectors.toList());
    }

    @Override
    public UUID getId() {
        return id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public Iterable getSeries() {
        return seriesCollection;
    }

    @Override
    public void addSeries(String name, Channel channel) {
        this.addSeries(name, channel, ChartSeriesType.LINE);
    }

    @Override
    public void addSeries(String name, Channel channel, ChartSeriesType type) {
        ChartSeries series = new ChartSeries(name, channel, type);
        this.seriesCollection.add(series);
        try {
            apiService.updateChart(jobId, id, this);
        } catch (ApiException exc) {
            throw ApiExceptionWrapper.wrappedApiException(exc);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        OnlineChart chart = (OnlineChart) o;
        return Objects.equals(id, chart.id)
                && Objects.equals(name, chart.name)
                && Objects.equals(seriesCollection, chart.seriesCollection);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, seriesCollection);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy