Save This Page
Home » mahout-collections-1.0-src » org.apache.mahout.math.buffer » [javadoc | source]
    1   /*
    2   Copyright 1999 CERN - European Organization for Nuclear Research.
    3   Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose 
    4   is hereby granted without fee, provided that the above copyright notice appear in all copies and 
    5   that both that copyright notice and this permission notice appear in supporting documentation. 
    6   CERN makes no representations about the suitability of this software for any purpose. 
    7   It is provided "as is" without expressed or implied warranty.
    8   */
    9   package org.apache.mahout.math.buffer;
   10   
   11   import org.apache.mahout.math.PersistentObject;
   12   import org.apache.mahout.math.list.DoubleArrayList;
   13   
   14   /** @deprecated until unit tests are in place.  Until this time, this class/interface is unsupported. */
   15   @Deprecated
   16   public class DoubleBuffer3D extends PersistentObject implements DoubleBuffer3DConsumer {
   17   
   18     private final DoubleBuffer3DConsumer target;
   19     private final double[] xElements;
   20     private final double[] yElements;
   21     private final double[] zElements;
   22   
   23     // vars cached for speed
   24     private final DoubleArrayList xList;
   25     private final DoubleArrayList yList;
   26     private final DoubleArrayList zList;
   27     private final int capacity;
   28     private int size;
   29   
   30     /**
   31      * Constructs and returns a new buffer with the given target.
   32      *
   33      * @param target   the target to flush to.
   34      * @param capacity the number of points the buffer shall be capable of holding before overflowing and flushing to the
   35      *                 target.
   36      */
   37     public DoubleBuffer3D(DoubleBuffer3DConsumer target, int capacity) {
   38       this.target = target;
   39       this.capacity = capacity;
   40       this.xElements = new double[capacity];
   41       this.yElements = new double[capacity];
   42       this.zElements = new double[capacity];
   43       this.xList = new DoubleArrayList(xElements);
   44       this.yList = new DoubleArrayList(yElements);
   45       this.zList = new DoubleArrayList(zElements);
   46       this.size = 0;
   47     }
   48   
   49     /**
   50      * Adds the specified point (x,y,z) to the receiver.
   51      *
   52      * @param x the x-coordinate of the point to add.
   53      * @param y the y-coordinate of the point to add.
   54      * @param z the z-coordinate of the point to add.
   55      */
   56     public void add(double x, double y, double z) {
   57       if (this.size == this.capacity) {
   58         flush();
   59       }
   60       this.xElements[this.size] = x;
   61       this.yElements[this.size] = y;
   62       this.zElements[this.size++] = z;
   63     }
   64   
   65     /**
   66      * Adds all specified (x,y,z) points to the receiver.
   67      *
   68      * @param xElements the x-coordinates of the points.
   69      * @param yElements the y-coordinates of the points.
   70      * @param zElements the y-coordinates of the points.
   71      */
   72     @Override
   73     public void addAllOf(DoubleArrayList xElements, DoubleArrayList yElements, DoubleArrayList zElements) {
   74       int listSize = xElements.size();
   75       if (this.size + listSize >= this.capacity) {
   76         flush();
   77       }
   78       this.target.addAllOf(xElements, yElements, zElements);
   79     }
   80   
   81     /** Sets the receiver's size to zero. In other words, forgets about any internally buffered elements. */
   82     public void clear() {
   83       this.size = 0;
   84     }
   85   
   86     /** Adds all internally buffered points to the receiver's target, then resets the current buffer size to zero. */
   87     public void flush() {
   88       if (this.size > 0) {
   89         xList.setSize(this.size);
   90         yList.setSize(this.size);
   91         zList.setSize(this.size);
   92         this.target.addAllOf(xList, yList, zList);
   93         this.size = 0;
   94       }
   95     }
   96   }

Save This Page
Home » mahout-collections-1.0-src » org.apache.mahout.math.buffer » [javadoc | source]