diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.java deleted file mode 100644 index 958d12afba..0000000000 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.java +++ /dev/null @@ -1,91 +0,0 @@ - -package com.github.mikephil.charting.buffer; - -import java.util.List; - -/** - * Buffer class to boost performance while drawing. Concept: Replace instead of - * recreate. - * - * @author Philipp Jahoda - * @param The data the buffer accepts to be fed with. - */ -public abstract class AbstractBuffer { - - /** index in the buffer */ - protected int index = 0; - - /** float-buffer that holds the data points to draw, order: x,y,x,y,... */ - public final float[] buffer; - - /** animation phase x-axis */ - protected float phaseX = 1f; - - /** animation phase y-axis */ - protected float phaseY = 1f; - - /** indicates from which x-index the visible data begins */ - protected int mFrom = 0; - - /** indicates to which x-index the visible data ranges */ - protected int mTo = 0; - - /** - * Initialization with buffer-size. - * - * @param size - */ - public AbstractBuffer(int size) { - index = 0; - buffer = new float[size]; - } - - /** limits the drawing on the x-axis */ - public void limitFrom(int from) { - if (from < 0) - from = 0; - mFrom = from; - } - - /** limits the drawing on the x-axis */ - public void limitTo(int to) { - if (to < 0) - to = 0; - mTo = to; - } - - /** - * Resets the buffer index to 0 and makes the buffer reusable. - */ - public void reset() { - index = 0; - } - - /** - * Returns the size (length) of the buffer array. - * - * @return - */ - public int size() { - return buffer.length; - } - - /** - * Set the phases used for animations. - * - * @param phaseX - * @param phaseY - */ - public void setPhases(float phaseX, float phaseY) { - this.phaseX = phaseX; - this.phaseY = phaseY; - } - - /** - * Builds up the buffer with the provided data and resets the buffer-index - * after feed-completion. This needs to run FAST. - * - * @param data - */ - public abstract void feed(T data); -} diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.kt b/MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.kt new file mode 100644 index 0000000000..e779aea050 --- /dev/null +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/buffer/AbstractBuffer.kt @@ -0,0 +1,91 @@ +package com.github.mikephil.charting.buffer + +/** + * Buffer class to boost performance while drawing. Concept: Replace instead of recreate. + * + * @param The data the buffer accepts to be fed with. + */ +abstract class AbstractBuffer(size: Int) { + /** index in the buffer */ + @JvmField + protected var index: Int = 0 + + /** float-buffer that holds the data points to draw, order: x,y,x,y,... */ + @JvmField + val buffer: FloatArray + + /** animation phase x-axis */ + @JvmField + protected var phaseX: Float = 1f + + /** animation phase y-axis */ + @JvmField + protected var phaseY: Float = 1f + + /** indicates from which x-index the visible data begins */ + protected var from: Int = 0 + + /** indicates to which x-index the visible data ranges */ + protected var to: Int = 0 + + /** + * Initialization with buffer-size. + * + * @param size + */ + init { + index = 0 + buffer = FloatArray(size) + } + + /** limits the drawing on the x-axis */ + fun limitFrom(fromGiven: Int) { + from = if (fromGiven < 0) + 0 + else + fromGiven + } + + /** limits the drawing on the x-axis */ + fun limitTo(toGiven: Int) { + to = if (toGiven < 0) + 0 + else + toGiven + } + + /** + * Resets the buffer index to 0 and makes the buffer reusable. + */ + fun reset() { + index = 0 + } + + /** + * Returns the size (length) of the buffer array. + * + * @return + */ + fun size(): Int { + return buffer.size + } + + /** + * Set the phases used for animations. + * + * @param phaseX + * @param phaseY + */ + fun setPhases(phaseX: Float, phaseY: Float) { + this.phaseX = phaseX + this.phaseY = phaseY + } + + /** + * Builds up the buffer with the provided data and resets the buffer-index + * after feed-completion. This needs to run FAST. + * + * @param data + */ + abstract fun feed(data: T) +}