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

org.diirt.datasource.timecache.DataChunk Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.datasource.timecache;

import java.util.SortedSet;
import java.util.TreeSet;

import org.diirt.util.time.TimeInterval;
import org.diirt.util.time.Timestamp;

/**
 * A chunk of {@link Data} ordered by {@link Timestamp} with a maximum size.
 * @author Fred Arnaud (Sopra Group) - ITER
 */
public class DataChunk {

	private SortedSet datas;
	private TimeInterval interval;

	private final Integer maxData;

	public DataChunk() {
		datas = new TreeSet();
		// TODO calculate
		this.maxData = 1000;
	}

	/**
	 * Add a data to the chunk.
	 * @param data to be added.
	 * @return true if data have been added, false
	 *         otherwise.
	 */
	public boolean add(Data data) {
		if (isFull() || data == null)
			return false;
		datas.add(data);
		interval = TimeInterval.between(
				datas.first().getTimestamp(), 
				datas.last().getTimestamp());
		return true;
	}

	/** Check if the instance is empty. */
	public boolean isEmpty() {
		return datas.isEmpty();
	}

	/** Check if the instance is full. */
	public boolean isFull() {
		return datas.size() >= maxData;
	}

	public SortedSet getDatas() {
		return datas;
	}

	public TimeInterval getInterval() {
		return interval;
	}

	@Override
	public String toString() {
		return "DataChunk [datas=" + datas + ", interval=" + interval + "]";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy