diff --git a/MPChartLib/src/main/AndroidManifest.xml b/MPChartLib/src/main/AndroidManifest.xml
index af45ebcb44..aa7350cec2 100644
--- a/MPChartLib/src/main/AndroidManifest.xml
+++ b/MPChartLib/src/main/AndroidManifest.xml
@@ -1,13 +1,8 @@
-
-
-
+ android:supportsRtl="true" />
\ No newline at end of file
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java
index 9537878522..8ef4c5e2b0 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarLineChartBase.java
@@ -1686,4 +1686,16 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mViewPortHandler.refresh(mViewPortHandler.getMatrixTouch(), this, true);
}
}
+
+ /**
+ * Sets the text color to use for the labels. Make sure to use
+ * getResources().getColor(...) when using a color from the resources.
+ *
+ * @param color
+ */
+ public void setTextColor(int color) {
+ mAxisRendererLeft.setTextColor(color);
+ mAxisRendererRight.setTextColor(color);
+ mXAxisRenderer.setTextColor(color);
+ }
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java
index e7327454d2..4c58b5ccb5 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java
@@ -603,7 +603,7 @@ public void disableGridDashedLine() {
* @return
*/
public boolean isGridDashedLineEnabled() {
- return mGridDashPathEffect == null ? false : true;
+ return mGridDashPathEffect != null;
}
/**
@@ -655,7 +655,7 @@ public void disableAxisLineDashedLine() {
* @return
*/
public boolean isAxisLineDashedLineEnabled() {
- return mAxisLineDashPathEffect == null ? false : true;
+ return mAxisLineDashPathEffect != null;
}
/**
@@ -846,4 +846,14 @@ public float[] getSpecificPositions()
{
return specificPositions;
}
+
+ /**
+ * Sets the text color to use for the labels. Make sure to use
+ * getResources().getColor(...) when using a color from the resources.
+ *
+ * @param color
+ */
+ public void setTextColor(int color) {
+ mTextColor = color;
+ }
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java
index 7e7445cac7..b2b3798b6c 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/data/BaseDataSet.java
@@ -92,8 +92,8 @@ public abstract class BaseDataSet implements IDataSet {
* Default constructor.
*/
public BaseDataSet() {
- mColors = new ArrayList();
- mValueColors = new ArrayList();
+ mColors = new ArrayList<>();
+ mValueColors = new ArrayList<>();
// default color
mColors.add(Color.rgb(140, 234, 255));
@@ -201,7 +201,7 @@ public void setColors(int[] colors, Context c) {
*/
public void addColor(int color) {
if (mColors == null)
- mColors = new ArrayList();
+ mColors = new ArrayList<>();
mColors.add(color);
}
@@ -244,7 +244,7 @@ public void setColors(int[] colors, int alpha) {
*/
public void resetColors() {
if (mColors == null) {
- mColors = new ArrayList();
+ mColors = new ArrayList<>();
}
mColors.clear();
}
@@ -499,7 +499,6 @@ protected void copy(BaseDataSet baseDataSet) {
baseDataSet.mIconsOffset = mIconsOffset;
baseDataSet.mValueColors = mValueColors;
baseDataSet.mValueFormatter = mValueFormatter;
- baseDataSet.mValueColors = mValueColors;
baseDataSet.mValueTextSize = mValueTextSize;
baseDataSet.mVisible = mVisible;
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java
index 8b6a120c7f..9d2889d9cb 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/AxisRenderer.java
@@ -290,4 +290,14 @@ else if (last == first && n == 0) {
* @param c
*/
public abstract void renderLimitLines(Canvas c);
+
+ /**
+ * Sets the text color to use for the labels. Make sure to use
+ * getResources().getColor(...) when using a color from the resources.
+ *
+ * @param color
+ */
+ public void setTextColor(int color) {
+ mAxis.setTextColor(color);
+ }
}
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java
index ba429e97da..b557b333dd 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/renderer/PieChartRenderer.java
@@ -1038,12 +1038,12 @@ protected void drawRoundedSlices(Canvas c) {
// draw only if the value is greater than zero
if ((Math.abs(e.getY()) > Utils.FLOAT_EPSILON)) {
+ double v = Math.toRadians((angle + sliceAngle)
+ * phaseY);
float x = (float) ((r - circleRadius)
- * Math.cos(Math.toRadians((angle + sliceAngle)
- * phaseY)) + center.x);
+ * Math.cos(v) + center.x);
float y = (float) ((r - circleRadius)
- * Math.sin(Math.toRadians((angle + sliceAngle)
- * phaseY)) + center.y);
+ * Math.sin(v) + center.y);
mRenderPaint.setColor(dataSet.getColor(j));
mBitmapCanvas.drawCircle(x, y, circleRadius, mRenderPaint);
@@ -1055,7 +1055,7 @@ protected void drawRoundedSlices(Canvas c) {
}
/**
- * Releases the drawing bitmap. This should be called when {@link LineChart#onDetachedFromWindow()}.
+ * Releases the drawing bitmap. This should be called when .
*/
public void releaseBitmap() {
if (mBitmapCanvas != null) {
diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java
index 110e5e321d..955e782d4f 100644
--- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java
+++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ApproximatorTest.java
@@ -1,39 +1,27 @@
package com.github.mikephil.charting.test;
+import static junit.framework.Assert.assertEquals;
+
import com.github.mikephil.charting.data.filter.Approximator;
import org.junit.Test;
-import static junit.framework.Assert.assertEquals;
-
/**
* Created by philipp on 07/06/16.
*/
public class ApproximatorTest {
- @Test
- public void testApproximation() {
+ @Test
+ public void testApproximation() {
- float[] points = new float[]{
- 10, 20,
- 20, 30,
- 25, 25,
- 30, 28,
- 31, 31,
- 33, 33,
- 40, 40,
- 44, 40,
- 48, 23,
- 50, 20,
- 55, 20,
- 60, 25};
+ float[] points = new float[]{10, 20, 20, 30, 25, 25, 30, 28, 31, 31, 33, 33, 40, 40, 44, 40, 48, 23, 50, 20, 55, 20, 60, 25};
- assertEquals(24, points.length);
+ assertEquals(24, points.length);
- Approximator a = new Approximator();
+ Approximator a = new Approximator();
- float[] reduced = a.reduceWithDouglasPeucker(points, 2);
+ float[] reduced = a.reduceWithDouglasPeucker(points, 2);
- assertEquals(18, reduced.length);
- }
+ assertEquals(18, reduced.length);
+ }
}
diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java
index 99954bce27..ce360ce3f8 100644
--- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java
+++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/BarDataTest.java
@@ -16,57 +16,57 @@
*/
public class BarDataTest {
- @Test
- public void testGroupBars() {
+ @Test
+ public void testGroupBars() {
- float groupSpace = 5f;
- float barSpace = 1f;
+ float groupSpace = 5f;
+ float barSpace = 1f;
- List values1 = new ArrayList<>();
- List values2 = new ArrayList<>();
+ List values1 = new ArrayList<>();
+ List values2 = new ArrayList<>();
- for(int i = 0; i < 5; i++) {
- values1.add(new BarEntry(i, 50));
- values2.add(new BarEntry(i, 60));
- }
+ for (int i = 0; i < 5; i++) {
+ values1.add(new BarEntry(i, 50));
+ values2.add(new BarEntry(i, 60));
+ }
- BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
- BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");
+ BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
+ BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");
- BarData data = new BarData(barDataSet1, barDataSet2);
- data.setBarWidth(10f);
+ BarData data = new BarData(barDataSet1, barDataSet2);
+ data.setBarWidth(10f);
- float groupWidth = data.getGroupWidth(groupSpace, barSpace);
- assertEquals(27f, groupWidth, 0.01f);
+ float groupWidth = data.getGroupWidth(groupSpace, barSpace);
+ assertEquals(27f, groupWidth, 0.01f);
- assertEquals(0f, values1.get(0).getX(), 0.01f);
- assertEquals(1f, values1.get(1).getX(), 0.01f);
+ assertEquals(0f, values1.get(0).getX(), 0.01f);
+ assertEquals(1f, values1.get(1).getX(), 0.01f);
- data.groupBars(1000, groupSpace, barSpace);
+ data.groupBars(1000, groupSpace, barSpace);
- // 1000 + 2.5 + 0.5 + 5
- assertEquals(1008f, values1.get(0).getX(), 0.01f);
- assertEquals(1019f, values2.get(0).getX(), 0.01f);
- assertEquals(1035f, values1.get(1).getX(), 0.01f);
- assertEquals(1046f, values2.get(1).getX(), 0.01f);
+ // 1000 + 2.5 + 0.5 + 5
+ assertEquals(1008f, values1.get(0).getX(), 0.01f);
+ assertEquals(1019f, values2.get(0).getX(), 0.01f);
+ assertEquals(1035f, values1.get(1).getX(), 0.01f);
+ assertEquals(1046f, values2.get(1).getX(), 0.01f);
- data.groupBars(-1000, groupSpace, barSpace);
+ data.groupBars(-1000, groupSpace, barSpace);
- assertEquals(-992f, values1.get(0).getX(), 0.01f);
- assertEquals(-981f, values2.get(0).getX(), 0.01f);
- assertEquals(-965f, values1.get(1).getX(), 0.01f);
- assertEquals(-954f, values2.get(1).getX(), 0.01f);
+ assertEquals(-992f, values1.get(0).getX(), 0.01f);
+ assertEquals(-981f, values2.get(0).getX(), 0.01f);
+ assertEquals(-965f, values1.get(1).getX(), 0.01f);
+ assertEquals(-954f, values2.get(1).getX(), 0.01f);
- data.setBarWidth(20f);
- groupWidth = data.getGroupWidth(groupSpace, barSpace);
- assertEquals(47f, groupWidth, 0.01f);
+ data.setBarWidth(20f);
+ groupWidth = data.getGroupWidth(groupSpace, barSpace);
+ assertEquals(47f, groupWidth, 0.01f);
- data.setBarWidth(10f);
- data.groupBars(-20, groupSpace, barSpace);
+ data.setBarWidth(10f);
+ data.groupBars(-20, groupSpace, barSpace);
- assertEquals(-12f, values1.get(0).getX(), 0.01f);
- assertEquals(-1f, values2.get(0).getX(), 0.01f);
- assertEquals(15f, values1.get(1).getX(), 0.01f);
- assertEquals(26f, values2.get(1).getX(), 0.01f);
- }
+ assertEquals(-12f, values1.get(0).getX(), 0.01f);
+ assertEquals(-1f, values2.get(0).getX(), 0.01f);
+ assertEquals(15f, values1.get(1).getX(), 0.01f);
+ assertEquals(26f, values2.get(1).getX(), 0.01f);
+ }
}
diff --git a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java
index 608f0e237c..7b6777ef21 100644
--- a/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java
+++ b/MPChartLib/src/test/java/com/github/mikephil/charting/test/ObjectPoolTest.java
@@ -14,227 +14,227 @@
*/
public class ObjectPoolTest {
- static class TestPoolable extends ObjectPool.Poolable{
+ static class TestPoolable extends ObjectPool.Poolable {
- private static final ObjectPool pool;
+ private static final ObjectPool pool;
- static {
- pool = ObjectPool.create(4, new TestPoolable(0,0));
- }
+ static {
+ pool = ObjectPool.create(4, new TestPoolable(0, 0));
+ }
- public int foo;
- public int bar;
+ public int foo;
+ public int bar;
- protected ObjectPool.Poolable instantiate(){
- return new TestPoolable(0,0);
- }
+ protected ObjectPool.Poolable instantiate() {
+ return new TestPoolable(0, 0);
+ }
- private TestPoolable(int foo, int bar){
- this.foo = foo;
- this.bar = bar;
- }
+ private TestPoolable(int foo, int bar) {
+ this.foo = foo;
+ this.bar = bar;
+ }
- public static TestPoolable getInstance(int foo, int bar){
- TestPoolable result = pool.get();
- result.foo = foo;
- result.bar = bar;
- return result;
- }
+ public static TestPoolable getInstance(int foo, int bar) {
+ TestPoolable result = pool.get();
+ result.foo = foo;
+ result.bar = bar;
+ return result;
+ }
- public static void recycleInstance(TestPoolable instance){
- pool.recycle(instance);
- }
+ public static void recycleInstance(TestPoolable instance) {
+ pool.recycle(instance);
+ }
- public static void recycleInstances(List instances){
- pool.recycle(instances);
- }
+ public static void recycleInstances(List instances) {
+ pool.recycle(instances);
+ }
- public static ObjectPool getPool(){
- return pool;
- }
+ public static ObjectPool getPool() {
+ return pool;
+ }
- }
+ }
- @Test
- public void testObjectPool(){
-
- int poolCapacity = TestPoolable.getPool().getPoolCapacity();
- int poolCount = TestPoolable.getPool().getPoolCount();
- TestPoolable testPoolable;
- ArrayList testPoolables = new ArrayList<>();
-
- Assert.assertEquals(4, poolCapacity);
- Assert.assertEquals(4, poolCount);
-
- testPoolable = TestPoolable.getInstance(6,7);
- Assert.assertEquals(6, testPoolable.foo);
- Assert.assertEquals(7, testPoolable.bar);
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
-
- Assert.assertEquals(4, poolCapacity);
- Assert.assertEquals(3, poolCount);
-
- TestPoolable.recycleInstance(testPoolable);
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(4, poolCapacity);
- Assert.assertEquals(4, poolCount);
-
-
- testPoolable = TestPoolable.getInstance(20,30);
- Assert.assertEquals(20, testPoolable.foo);
- Assert.assertEquals(30, testPoolable.bar);
-
- TestPoolable.recycleInstance(testPoolable);
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(4, poolCapacity);
- Assert.assertEquals(4, poolCount);
-
- testPoolables.add(TestPoolable.getInstance(12,24));
- testPoolables.add(TestPoolable.getInstance(1,2));
- testPoolables.add(TestPoolable.getInstance(3,5));
- testPoolables.add(TestPoolable.getInstance(6,8));
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(4, poolCapacity);
- Assert.assertEquals(0, poolCount);
-
-
- TestPoolable.recycleInstances(testPoolables);
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(4, poolCapacity);
- Assert.assertEquals(4, poolCount);
-
- testPoolables.clear();
-
-
- testPoolables.add(TestPoolable.getInstance(12,24));
- testPoolables.add(TestPoolable.getInstance(1,2));
- testPoolables.add(TestPoolable.getInstance(3,5));
- testPoolables.add(TestPoolable.getInstance(6,8));
- testPoolables.add(TestPoolable.getInstance(8,9));
- Assert.assertEquals(12, testPoolables.get(0).foo);
- Assert.assertEquals(24, testPoolables.get(0).bar);
- Assert.assertEquals(1, testPoolables.get(1).foo);
- Assert.assertEquals(2, testPoolables.get(1).bar);
- Assert.assertEquals(3, testPoolables.get(2).foo);
- Assert.assertEquals(5, testPoolables.get(2).bar);
- Assert.assertEquals(6, testPoolables.get(3).foo);
- Assert.assertEquals(8, testPoolables.get(3).bar);
- Assert.assertEquals(8, testPoolables.get(4).foo);
- Assert.assertEquals(9, testPoolables.get(4).bar);
-
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(4, poolCapacity);
- Assert.assertEquals(3, poolCount);
-
- TestPoolable.recycleInstances(testPoolables);
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(8, poolCapacity);
- Assert.assertEquals(8, poolCount);
-
- testPoolables.clear();
-
-
- testPoolables.add(TestPoolable.getInstance(0,0));
- testPoolables.add(TestPoolable.getInstance(6,8));
- testPoolables.add(TestPoolable.getInstance(1,2));
- testPoolables.add(TestPoolable.getInstance(3,5));
- testPoolables.add(TestPoolable.getInstance(8,9));
- testPoolables.add(TestPoolable.getInstance(12,24));
- testPoolables.add(TestPoolable.getInstance(12,24));
- testPoolables.add(TestPoolable.getInstance(12,24));
- testPoolables.add(TestPoolable.getInstance(6,8));
- testPoolables.add(TestPoolable.getInstance(6,8));
- Assert.assertEquals(0, testPoolables.get(0).foo);
- Assert.assertEquals(0, testPoolables.get(0).bar);
- Assert.assertEquals(6, testPoolables.get(1).foo);
- Assert.assertEquals(8, testPoolables.get(1).bar);
- Assert.assertEquals(1, testPoolables.get(2).foo);
- Assert.assertEquals(2, testPoolables.get(2).bar);
- Assert.assertEquals(3, testPoolables.get(3).foo);
- Assert.assertEquals(5, testPoolables.get(3).bar);
- Assert.assertEquals(8, testPoolables.get(4).foo);
- Assert.assertEquals(9, testPoolables.get(4).bar);
- Assert.assertEquals(12, testPoolables.get(5).foo);
- Assert.assertEquals(24, testPoolables.get(5).bar);
- Assert.assertEquals(12, testPoolables.get(6).foo);
- Assert.assertEquals(24, testPoolables.get(6).bar);
- Assert.assertEquals(12, testPoolables.get(7).foo);
- Assert.assertEquals(24, testPoolables.get(7).bar);
- Assert.assertEquals(6, testPoolables.get(8).foo);
- Assert.assertEquals(8, testPoolables.get(8).bar);
- Assert.assertEquals(6, testPoolables.get(9).foo);
- Assert.assertEquals(8, testPoolables.get(9).bar);
-
- for(TestPoolable p : testPoolables){
- TestPoolable.recycleInstance(p);
- }
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(16, poolCapacity);
- Assert.assertEquals(16, poolCount);
-
- testPoolable = TestPoolable.getInstance(9001,9001);
- Assert.assertEquals(9001, testPoolable.foo);
- Assert.assertEquals(9001, testPoolable.bar);
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(16, poolCapacity);
- Assert.assertEquals(15, poolCount);
-
-
- TestPoolable.recycleInstance(testPoolable);
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(16, poolCapacity);
- Assert.assertEquals(16, poolCount);
-
- Exception e = null;
- try{
- // expect an exception.
- TestPoolable.recycleInstance(testPoolable);
- }catch (Exception ex){
- e = ex;
- }finally{
- Assert.assertEquals(e.getMessage(), true, e != null);
- }
-
- testPoolables.clear();
-
- TestPoolable.getPool().setReplenishPercentage(0.5f);
- int i = 16;
- while(i > 0){
- testPoolables.add(TestPoolable.getInstance(0,0));
- i--;
- }
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(16, poolCapacity);
- Assert.assertEquals(0, poolCount);
-
- testPoolables.add(TestPoolable.getInstance(0,0));
-
- poolCapacity = TestPoolable.getPool().getPoolCapacity();
- poolCount = TestPoolable.getPool().getPoolCount();
- Assert.assertEquals(16, poolCapacity);
- Assert.assertEquals(7, poolCount);
-
-
- }
+ @Test
+ public void testObjectPool() {
+
+ int poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ int poolCount = TestPoolable.getPool().getPoolCount();
+ TestPoolable testPoolable;
+ ArrayList testPoolables = new ArrayList<>();
+
+ Assert.assertEquals(4, poolCapacity);
+ Assert.assertEquals(4, poolCount);
+
+ testPoolable = TestPoolable.getInstance(6, 7);
+ Assert.assertEquals(6, testPoolable.foo);
+ Assert.assertEquals(7, testPoolable.bar);
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+
+ Assert.assertEquals(4, poolCapacity);
+ Assert.assertEquals(3, poolCount);
+
+ TestPoolable.recycleInstance(testPoolable);
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(4, poolCapacity);
+ Assert.assertEquals(4, poolCount);
+
+
+ testPoolable = TestPoolable.getInstance(20, 30);
+ Assert.assertEquals(20, testPoolable.foo);
+ Assert.assertEquals(30, testPoolable.bar);
+
+ TestPoolable.recycleInstance(testPoolable);
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(4, poolCapacity);
+ Assert.assertEquals(4, poolCount);
+
+ testPoolables.add(TestPoolable.getInstance(12, 24));
+ testPoolables.add(TestPoolable.getInstance(1, 2));
+ testPoolables.add(TestPoolable.getInstance(3, 5));
+ testPoolables.add(TestPoolable.getInstance(6, 8));
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(4, poolCapacity);
+ Assert.assertEquals(0, poolCount);
+
+
+ TestPoolable.recycleInstances(testPoolables);
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(4, poolCapacity);
+ Assert.assertEquals(4, poolCount);
+
+ testPoolables.clear();
+
+
+ testPoolables.add(TestPoolable.getInstance(12, 24));
+ testPoolables.add(TestPoolable.getInstance(1, 2));
+ testPoolables.add(TestPoolable.getInstance(3, 5));
+ testPoolables.add(TestPoolable.getInstance(6, 8));
+ testPoolables.add(TestPoolable.getInstance(8, 9));
+ Assert.assertEquals(12, testPoolables.get(0).foo);
+ Assert.assertEquals(24, testPoolables.get(0).bar);
+ Assert.assertEquals(1, testPoolables.get(1).foo);
+ Assert.assertEquals(2, testPoolables.get(1).bar);
+ Assert.assertEquals(3, testPoolables.get(2).foo);
+ Assert.assertEquals(5, testPoolables.get(2).bar);
+ Assert.assertEquals(6, testPoolables.get(3).foo);
+ Assert.assertEquals(8, testPoolables.get(3).bar);
+ Assert.assertEquals(8, testPoolables.get(4).foo);
+ Assert.assertEquals(9, testPoolables.get(4).bar);
+
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(4, poolCapacity);
+ Assert.assertEquals(3, poolCount);
+
+ TestPoolable.recycleInstances(testPoolables);
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(8, poolCapacity);
+ Assert.assertEquals(8, poolCount);
+
+ testPoolables.clear();
+
+
+ testPoolables.add(TestPoolable.getInstance(0, 0));
+ testPoolables.add(TestPoolable.getInstance(6, 8));
+ testPoolables.add(TestPoolable.getInstance(1, 2));
+ testPoolables.add(TestPoolable.getInstance(3, 5));
+ testPoolables.add(TestPoolable.getInstance(8, 9));
+ testPoolables.add(TestPoolable.getInstance(12, 24));
+ testPoolables.add(TestPoolable.getInstance(12, 24));
+ testPoolables.add(TestPoolable.getInstance(12, 24));
+ testPoolables.add(TestPoolable.getInstance(6, 8));
+ testPoolables.add(TestPoolable.getInstance(6, 8));
+ Assert.assertEquals(0, testPoolables.get(0).foo);
+ Assert.assertEquals(0, testPoolables.get(0).bar);
+ Assert.assertEquals(6, testPoolables.get(1).foo);
+ Assert.assertEquals(8, testPoolables.get(1).bar);
+ Assert.assertEquals(1, testPoolables.get(2).foo);
+ Assert.assertEquals(2, testPoolables.get(2).bar);
+ Assert.assertEquals(3, testPoolables.get(3).foo);
+ Assert.assertEquals(5, testPoolables.get(3).bar);
+ Assert.assertEquals(8, testPoolables.get(4).foo);
+ Assert.assertEquals(9, testPoolables.get(4).bar);
+ Assert.assertEquals(12, testPoolables.get(5).foo);
+ Assert.assertEquals(24, testPoolables.get(5).bar);
+ Assert.assertEquals(12, testPoolables.get(6).foo);
+ Assert.assertEquals(24, testPoolables.get(6).bar);
+ Assert.assertEquals(12, testPoolables.get(7).foo);
+ Assert.assertEquals(24, testPoolables.get(7).bar);
+ Assert.assertEquals(6, testPoolables.get(8).foo);
+ Assert.assertEquals(8, testPoolables.get(8).bar);
+ Assert.assertEquals(6, testPoolables.get(9).foo);
+ Assert.assertEquals(8, testPoolables.get(9).bar);
+
+ for (TestPoolable p : testPoolables) {
+ TestPoolable.recycleInstance(p);
+ }
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(16, poolCapacity);
+ Assert.assertEquals(16, poolCount);
+
+ testPoolable = TestPoolable.getInstance(9001, 9001);
+ Assert.assertEquals(9001, testPoolable.foo);
+ Assert.assertEquals(9001, testPoolable.bar);
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(16, poolCapacity);
+ Assert.assertEquals(15, poolCount);
+
+
+ TestPoolable.recycleInstance(testPoolable);
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(16, poolCapacity);
+ Assert.assertEquals(16, poolCount);
+
+ Exception e = null;
+ try {
+ // expect an exception.
+ TestPoolable.recycleInstance(testPoolable);
+ } catch (Exception ex) {
+ e = ex;
+ } finally {
+ Assert.assertEquals(e.getMessage(), true, e != null);
+ }
+
+ testPoolables.clear();
+
+ TestPoolable.getPool().setReplenishPercentage(0.5f);
+ int i = 16;
+ while (i > 0) {
+ testPoolables.add(TestPoolable.getInstance(0, 0));
+ i--;
+ }
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(16, poolCapacity);
+ Assert.assertEquals(0, poolCount);
+
+ testPoolables.add(TestPoolable.getInstance(0, 0));
+
+ poolCapacity = TestPoolable.getPool().getPoolCapacity();
+ poolCount = TestPoolable.getPool().getPoolCount();
+ Assert.assertEquals(16, poolCapacity);
+ Assert.assertEquals(7, poolCount);
+
+
+ }
}