Search in sources :

Example 6 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class TableIterator method getDataArray.

protected BNewArray getDataArray(Array array) throws SQLException {
    Object[] dataArray = generateArrayDataResult(array);
    if (dataArray == null || dataArray.length == 0) {
        return null;
    }
    Object obj = dataArray[0];
    int length = dataArray.length;
    if (obj instanceof String) {
        BStringArray stringDataArray = new BStringArray();
        for (int i = 0; i < length; i++) {
            stringDataArray.add(i, (String) dataArray[i]);
        }
        return stringDataArray;
    } else if (obj instanceof Boolean) {
        BBooleanArray boolDataArray = new BBooleanArray();
        for (int i = 0; i < length; i++) {
            boolDataArray.add(i, ((Boolean) dataArray[i]) ? 1 : 0);
        }
        return boolDataArray;
    } else if (obj instanceof Integer) {
        BIntArray intDataArray = new BIntArray();
        for (int i = 0; i < length; i++) {
            intDataArray.add(i, ((Integer) dataArray[i]));
        }
        return intDataArray;
    } else if (obj instanceof Long) {
        BIntArray longDataArray = new BIntArray();
        for (int i = 0; i < length; i++) {
            longDataArray.add(i, (Long) dataArray[i]);
        }
        return longDataArray;
    } else if (obj instanceof Float) {
        BFloatArray floatDataArray = new BFloatArray();
        for (int i = 0; i < length; i++) {
            floatDataArray.add(i, (Float) dataArray[i]);
        }
        return floatDataArray;
    } else if (obj instanceof Double) {
        BFloatArray doubleDataArray = new BFloatArray();
        for (int i = 0; i < dataArray.length; i++) {
            doubleDataArray.add(i, (Double) dataArray[i]);
        }
        return doubleDataArray;
    } else {
        return null;
    }
}
Also used : BStringArray(org.ballerinalang.model.values.BStringArray) BIntArray(org.ballerinalang.model.values.BIntArray) BBooleanArray(org.ballerinalang.model.values.BBooleanArray) BFloatArray(org.ballerinalang.model.values.BFloatArray)

Example 7 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class TableTest method testArrayData.

@Test(groups = "TableTest", description = "Check array data types.")
public void testArrayData() {
    BValue[] returns = BRunUtil.invoke(result, "testArrayData");
    Assert.assertEquals(returns.length, 5);
    Assert.assertTrue(returns[0] instanceof BIntArray);
    BIntArray intArray = (BIntArray) returns[0];
    Assert.assertEquals(intArray.get(0), 1);
    Assert.assertEquals(intArray.get(1), 2);
    Assert.assertEquals(intArray.get(2), 3);
    Assert.assertTrue(returns[1] instanceof BIntArray);
    BIntArray longArray = (BIntArray) returns[1];
    Assert.assertEquals(longArray.get(0), 100000000);
    Assert.assertEquals(longArray.get(1), 200000000);
    Assert.assertEquals(longArray.get(2), 300000000);
    Assert.assertTrue(returns[2] instanceof BFloatArray);
    BFloatArray doubleArray = (BFloatArray) returns[2];
    Assert.assertEquals(doubleArray.get(0), 245.23);
    Assert.assertEquals(doubleArray.get(1), 5559.49);
    Assert.assertEquals(doubleArray.get(2), 8796.123);
    Assert.assertTrue(returns[3] instanceof BStringArray);
    BStringArray stringArray = (BStringArray) returns[3];
    Assert.assertEquals(stringArray.get(0), "Hello");
    Assert.assertEquals(stringArray.get(1), "Ballerina");
    Assert.assertTrue(returns[4] instanceof BBooleanArray);
    BBooleanArray booleanArray = (BBooleanArray) returns[4];
    Assert.assertEquals(booleanArray.get(0), 1);
    Assert.assertEquals(booleanArray.get(1), 0);
    Assert.assertEquals(booleanArray.get(2), 1);
}
Also used : BBooleanArray(org.ballerinalang.model.values.BBooleanArray) BValue(org.ballerinalang.model.values.BValue) BFloatArray(org.ballerinalang.model.values.BFloatArray) BStringArray(org.ballerinalang.model.values.BStringArray) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 8 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class TypeCastExprTest method testIntArrayToLongArray.

@Test
public void testIntArrayToLongArray() {
    BValue[] returns = BRunUtil.invoke(result, "intarrtofloatarr");
    Assert.assertTrue(returns[0] instanceof BFloatArray);
    BFloatArray result = (BFloatArray) returns[0];
    Assert.assertEquals(result.get(0), 999.0, DELTA);
    Assert.assertEquals(result.get(1), 95.0, DELTA);
    Assert.assertEquals(result.get(2), 889.0, DELTA);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloatArray(org.ballerinalang.model.values.BFloatArray) Test(org.testng.annotations.Test)

Example 9 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class ValueTypeCastExprTest method testIntArrayToLongArray.

@Test
public void testIntArrayToLongArray() {
    BValue[] returns = BRunUtil.invoke(result, "intarrtofloatarr", new BValue[] {});
    Assert.assertTrue(returns[0] instanceof BFloatArray);
    BFloatArray result = (BFloatArray) returns[0];
    Assert.assertEquals(result.get(0), 999.0, DELTA);
    Assert.assertEquals(result.get(1), 95.0, DELTA);
    Assert.assertEquals(result.get(2), 889.0, DELTA);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloatArray(org.ballerinalang.model.values.BFloatArray) Test(org.testng.annotations.Test)

Example 10 with BFloatArray

use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.

the class ArrayInitializerExprTest method testFloatArrayInitWithIntExpr.

@Test(description = "Test float array initialization with integer values")
public void testFloatArrayInitWithIntExpr() {
    BValue[] args = {};
    BValue[] returns = BRunUtil.invoke(compileResult, "floatArrayInitWithInt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloatArray.class);
    BFloatArray arrayValue = (BFloatArray) returns[0];
    Assert.assertEquals(arrayValue.size(), 3);
    Assert.assertEquals(arrayValue.get(0), 2.0);
    Assert.assertEquals(arrayValue.get(1), 4.0);
    Assert.assertEquals(arrayValue.get(2), 5.0);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloatArray(org.ballerinalang.model.values.BFloatArray) Test(org.testng.annotations.Test)

Aggregations

BFloatArray (org.ballerinalang.model.values.BFloatArray)14 BValue (org.ballerinalang.model.values.BValue)9 BIntArray (org.ballerinalang.model.values.BIntArray)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 Test (org.testng.annotations.Test)8 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)7 BBlobArray (org.ballerinalang.model.values.BBlobArray)4 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)4 BString (org.ballerinalang.model.values.BString)4 BJSON (org.ballerinalang.model.values.BJSON)3 BRefType (org.ballerinalang.model.values.BRefType)3 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)3 BMapType (org.ballerinalang.model.types.BMapType)2 BInteger (org.ballerinalang.model.values.BInteger)2 BStruct (org.ballerinalang.model.values.BStruct)2 StructureType (org.ballerinalang.model.values.StructureType)2 TypeRefCPEntry (org.ballerinalang.util.codegen.cpentries.TypeRefCPEntry)2 StringJoiner (java.util.StringJoiner)1 BEnumType (org.ballerinalang.model.types.BEnumType)1 BStructType (org.ballerinalang.model.types.BStructType)1