Package simtools.data.buffer

Source Code of simtools.data.buffer.BufferedDataSource

/* ==============================================
* Simtools : The tools library used in JSynoptic
* ==============================================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2003, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: BufferedDataSource.java,v 1.4 2006/02/15 18:29:07 cazenave Exp $
*
* Changes
* -------
* 25-Sep-2003 : Initial public release (NB);
*
*/

package simtools.data.buffer;

import simtools.data.CollectiveDataSource;
import simtools.data.DataException;
import simtools.data.DataInfo;
import simtools.data.DataSource;
import simtools.data.DataSourceListener;
import simtools.data.EndNotificationListener;
import simtools.data.UnsupportedOperation;

/**
* A data source providing a buffering service
* Designed to be a wrapper around a DataSource, somewhat like what's done
* for the java InputStreams.
* @author Nicolas Brodu
* @version 1.0 2001
*/
public class BufferedDataSource extends DataSource {

  protected Buffer buffer;
  public DataSource dataSource;

  /* (non-Javadoc)
   * @see java.lang.Object#equals(java.lang.Object)
   */
  public boolean equals(Object obj) {
    return dataSource.equals(obj) || super.equals(obj);
  }

  public BufferedDataSource(DataSource ds) {
    this(new SimpleBuffer(ds));
  }

  public BufferedDataSource(DataSource ds, int bufferSize) {
    this(new SimpleBuffer(ds, bufferSize));
  }

  public BufferedDataSource(Buffer b) {
    dataSource = (DataSource)b.provider; // or class cast exception
    if (dataSource instanceof CollectiveDataSource) {
      CollectiveDataSource c = ((CollectiveDataSource)dataSource);
      c.getCollection().attachBuffer(c.getPosition(), b);
    }
    buffer = b;
  }

  public Buffer getBuffer() {
    return buffer;
  }

// Method using the buffer

  public Object getValue(long index) throws DataException {
    return buffer.getValue(index);
  }

///  public type getTypeValue(long index) throws DataException {
///    return buffer.getTypeValue(index);
///  }
///
// ------ START of perl-generated corresponding code --------
  public byte getByteValue(long index) throws DataException {
    return buffer.getByteValue(index);
  }

  public short getShortValue(long index) throws DataException {
    return buffer.getShortValue(index);
  }

  public int getIntegerValue(long index) throws DataException {
    return buffer.getIntegerValue(index);
  }

  public long getLongValue(long index) throws DataException {
    return buffer.getLongValue(index);
  }

  public float getFloatValue(long index) throws DataException {
    return buffer.getFloatValue(index);
  }

  public double getDoubleValue(long index) throws DataException {
    return buffer.getDoubleValue(index);
  }

// -------- END of perl-generated corresponding code --------

  public void setSlice(long min, long max) {
    buffer.setSlice(min,max);
    dataSource.setSlice(min,max);
  }

// Methods using the data source

  public DataInfo getInformation() {
    return dataSource.getInformation();
  }

  public Object getMin() throws UnsupportedOperation {
    return dataSource.getMin();
  }

  public Object getMax() throws UnsupportedOperation {
    return dataSource.getMax();
  }

///  public type getTypeMin() throws DataException {
///    return dataSource.getTypeMin();
///  }
///
///  public type getTypeMax() throws DataException {
///    return dataSource.getTypeMax();
///  }
///
// ------ START of perl-generated corresponding code --------
  public byte getByteMin() throws DataException {
    return dataSource.getByteMin();
  }

  public byte getByteMax() throws DataException {
    return dataSource.getByteMax();
  }

  public short getShortMin() throws DataException {
    return dataSource.getShortMin();
  }

  public short getShortMax() throws DataException {
    return dataSource.getShortMax();
  }

  public int getIntegerMin() throws DataException {
    return dataSource.getIntegerMin();
  }

  public int getIntegerMax() throws DataException {
    return dataSource.getIntegerMax();
  }

  public long getLongMin() throws DataException {
    return dataSource.getLongMin();
  }

  public long getLongMax() throws DataException {
    return dataSource.getLongMax();
  }

  public float getFloatMin() throws DataException {
    return dataSource.getFloatMin();
  }

  public float getFloatMax() throws DataException {
    return dataSource.getFloatMax();
  }

  public double getDoubleMin() throws DataException {
    return dataSource.getDoubleMin();
  }

  public double getDoubleMax() throws DataException {
    return dataSource.getDoubleMax();
  }

// -------- END of perl-generated corresponding code --------


  public long getStartIndex() throws UnsupportedOperation {
    return dataSource.getStartIndex();
  }

  public long getLastIndex() throws UnsupportedOperation {
    return dataSource.getLastIndex();
  }

  /**
   * Force the computation if possible. The operation may take some time.
   */
  public Object computeMin() throws UnsupportedOperation {
    return dataSource.computeMin();
  }

  public Object computeMax() throws UnsupportedOperation {
    return dataSource.computeMax();
  }

  public long computeStartIndex() throws UnsupportedOperation {
    return dataSource.computeStartIndex();
  }

  public long computeLastIndex() throws UnsupportedOperation {
    return dataSource.computeLastIndex();
  }

  public int sortedOrder() {
    return dataSource.sortedOrder();
  }
 
  public boolean isComparable() {
    return dataSource.isComparable();
  }

  /* (non-Javadoc)
   * @see simtools.data.DataSource#addListener(simtools.data.DataSourceListener)
   */
  public void addListener(DataSourceListener dsl) {
    dataSource.addListener(dsl);
  }

  /* (non-Javadoc)
   * @see simtools.data.DataSource#notifyListenersForIndexRangeChange(long, long)
   */
  public void notifyListenersForIndexRangeChange(
    long startIndex,
    long lastIndex) {
    dataSource.notifyListenersForIndexRangeChange(startIndex, lastIndex);
  }

  /* (non-Javadoc)
   * @see simtools.data.DataSource#notifyListenersForInfoChange(simtools.data.DataInfo)
   */
  public void notifyListenersForInfoChange(DataInfo newInfo) {
    dataSource.notifyListenersForInfoChange(newInfo);
  }

  /* (non-Javadoc)
   * @see simtools.data.DataSource#notifyListenersForOrderChange(int)
   */
  public void notifyListenersForOrderChange(int newOrder) {
    dataSource.notifyListenersForOrderChange(newOrder);
  }

  /* (non-Javadoc)
   * @see simtools.data.DataSource#notifyListenersForValueChange(long, long)
   */
  public void notifyListenersForValueChange(
    long minIndex,
    long maxIndex) {
    dataSource.notifyListenersForValueChange(minIndex, maxIndex);
  }

  /* (non-Javadoc)
   * @see simtools.data.DataSource#notifyListenersForValueRangeChange(java.lang.Object, java.lang.Object)
   */
  public void notifyListenersForValueRangeChange() {
    dataSource.notifyListenersForValueRangeChange();
  }

  /* (non-Javadoc)
   * @see simtools.data.DataSource#notifyListenersForDataReplaced(simtools.data.DataSource)
   */
  public void notifyListenersForDataReplaced(DataSource newData) {
    dataSource.notifyListenersForDataReplaced(this, newData);
  }
 
  /* (non-Javadoc)
   * @see simtools.data.DataSource#removeListener(simtools.data.DataSourceListener)
   */
  public void removeListener(DataSourceListener dsl) {
    dataSource.removeListener(dsl);
  }

    /* (non-Javadoc)
     * @see simtools.data.DataSource#addEndNotificationListener(simtools.data.EndNotificationListener)
     */
    public void addEndNotificationListener(EndNotificationListener enl) {
        dataSource.addEndNotificationListener(enl);
    }
   
    /* (non-Javadoc)
     * @see simtools.data.DataSource#notifyEndNotificationListeners()
     */
    public void notifyEndNotificationListeners() {
        dataSource.notifyEndNotificationListeners();
    }
   
    /* (non-Javadoc)
     * @see simtools.data.DataSource#removeEndNotificationListener(simtools.data.EndNotificationListener)
     */
    public void removeEndNotificationListener(EndNotificationListener enl) {
        dataSource.removeEndNotificationListener(enl);
    }
}
TOP

Related Classes of simtools.data.buffer.BufferedDataSource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.