Example usage for java.lang Exception getStackTrace

List of usage examples for java.lang Exception getStackTrace

Introduction

In this page you can find the example usage for java.lang Exception getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#ceil(java.lang.Object, java.lang.Number, java.lang.Class)}.
 *///from w  ww .j a  va 2s .  com
@SuppressWarnings("unchecked")
@Test
public void testCeilObjectNumberClassOfT() {
    assertEquals("null", null, ceil(null, null, null));
    assertEquals("null", null, ceil(null, 2, null));
    assertEquals("null", 4f, ceil(3.14f, 0, null));
    assertEquals("null", 3.15d, ceil(Math.PI, 2, null));
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            if (Double.class.equals(wrapper)) {
                expected = 3.15d;
            } else if (Float.class.equals(wrapper)) {
                expected = 3.15f;
            } else if (BigDecimal.class.equals(wrapper)) {
                expected = new BigDecimal("3.15");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "3");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance("3");
            }
            for (Class<?> scaleType : OBJECTS) {
                Object o = null;
                if (ClassUtils.isPrimitiveWrapper(scaleType)) {
                    o = scaleType.getMethod("valueOf", String.class).invoke(null, "2");
                } else {
                    Constructor<?> c = scaleType.getDeclaredConstructor(String.class);
                    o = c.newInstance("2");
                }
                assertEquals(
                        "PI: Float: " + type.getSimpleName() + "(scale: " + scaleType.getSimpleName() + ")",
                        expected, ceil(3.141592653589793f, (Number) o, typeOfN));
                assertEquals(
                        "PI: Double: " + type.getSimpleName() + "(scale: " + scaleType.getSimpleName() + ")",
                        expected, ceil(Math.PI, (Number) o, typeOfN));
                assertEquals("PI: BigDecimal: " + type.getSimpleName() + "(scale: " + scaleType.getSimpleName()
                        + ")", expected, ceil(new BigDecimal(Math.PI), (Number) o, typeOfN));
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#contains(java.lang.Object, java.lang.Number, java.lang.Number)}.
 *///from w ww.j a  v  a  2s . c  o m
@SuppressWarnings("unchecked")
@Test
public void testContains() {
    assertEquals("null", false, contains(null, null, null));
    assertEquals("null", false, contains(null, 0, null));
    assertEquals("null", false, contains(null, null, 10));
    assertEquals("null", false, contains(null, 0, 10));
    assertEquals("null: from", true, contains(0, null, 10));
    assertEquals("null: from: overflow", false, contains(11, null, 10));
    assertEquals("null: to", true, contains(0, 0, null));
    assertEquals("null: to", true, contains(11, 10, null));
    assertEquals("null: to: less", false, contains(1, 10, null));
    assertEquals("fraction: Double", true, contains(Math.PI, 0, 10));
    assertEquals("fraction: Float", true, contains(Float.MIN_VALUE, 0, 10));
    assertEquals("NaN", false, contains(Float.NaN, -Float.MAX_VALUE, Float.MAX_VALUE));
    assertEquals("NaN", false, contains(Float.NaN, null, Float.POSITIVE_INFINITY));
    assertEquals("NaN", true, contains(Float.NaN, Float.NaN, Float.POSITIVE_INFINITY));
    assertEquals("NaN", true, contains(Float.NaN, null, Float.NaN));
    assertEquals("NaN", true, contains(Float.NaN, Double.NaN, Float.NaN));
    assertEquals("-Infinity: from", true, contains(1, Float.NEGATIVE_INFINITY, null));
    assertEquals("-Infinity: to", false, contains(1, null, Float.NEGATIVE_INFINITY));
    assertEquals("Infinity: from", false, contains(1, Float.POSITIVE_INFINITY, null));
    assertEquals("Infinity: to", true, contains(1, null, Float.POSITIVE_INFINITY));
    assertEquals("Infinity: only", false, contains(1, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    assertEquals("Infinity: only", true,
            contains(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    assertEquals("Infinity: only", true,
            contains(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    for (Class<?> type : NUMBERS) {
        Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
        Object o = null;
        try {
            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                o = wrapper.getField("MAX_VALUE").get(null);
            } else {
                o = INFINITY_DOUBLE.pow(2);
                if (BigInteger.class.equals(type))
                    o = ((BigDecimal) o).toBigInteger();
            }
            assertEquals("Infinity: all: " + type.getSimpleName(), true,
                    contains(o, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#floor(java.lang.Object, java.lang.Class)}.
 *///w w  w . j a  va2 s  .  co  m
@SuppressWarnings("unchecked")
@Test
public void testFloorObjectClassOfT() {
    assertEquals("null", null, floor(null, null));
    assertEquals("null", null, floor("", null));
    assertEquals("null", null, floor("not a number.", null));
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "3");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance("3");
            }
            assertEquals("PI: String: " + type.getSimpleName(), expected, floor("3.14", typeOfN));
            assertEquals("PI: Float: " + type.getSimpleName(), expected, floor(3.141592653589793f, typeOfN));
            assertEquals("PI: Double: " + type.getSimpleName(), expected, floor(Math.PI, typeOfN));
            assertEquals("PI: BigDecimal: " + type.getSimpleName(), expected,
                    floor(BigDecimal.valueOf(Math.PI), typeOfN));
            assertEquals("(Double) (10 / 3): " + type.getSimpleName(), expected, floor(
                    (Object) (BigDecimal.TEN.divide(new BigDecimal("3"), MathContext.DECIMAL128)), typeOfN));
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MAX_VALUE").get(null);
                assertEquals("Huge: " + type.getSimpleName(), expected,
                        floor((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128), typeOfN));
            } else if (BigDecimal.class.equals(type)) {
                expected = INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128).toPlainString();
                Object actual = floor((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128),
                        BigDecimal.class).toPlainString();
                assertEquals("Huge: " + type.getSimpleName(), expected, actual);
            } else {
                expected = INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128).toBigInteger();
                Object actual = floor((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128),
                        BigInteger.class);
                assertEquals("Huge: " + type.getSimpleName(), expected, actual);
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#floor(java.lang.Object, java.lang.Number, java.lang.Class)}.
 *///from w w w  .  j a v a  2s. c  om
@SuppressWarnings("unchecked")
@Test
public void testFloorObjectNumberClassOfT() {
    assertEquals("null", null, floor(null, null, null));
    assertEquals("null", null, floor(null, 2, null));
    assertEquals("null", 3f, floor(3.14f, 0, null));
    assertEquals("null", 3.14d, floor(Math.PI, 2, null));
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            if (Double.class.equals(wrapper)) {
                expected = 3.14d;
            } else if (Float.class.equals(wrapper)) {
                expected = 3.14f;
            } else if (BigDecimal.class.equals(wrapper)) {
                expected = new BigDecimal("3.14");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "3");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance("3");
            }
            for (Class<?> scaleType : OBJECTS) {
                Object o = null;
                if (ClassUtils.isPrimitiveWrapper(scaleType)) {
                    o = scaleType.getMethod("valueOf", String.class).invoke(null, "2");
                } else {
                    Constructor<?> c = scaleType.getDeclaredConstructor(String.class);
                    o = c.newInstance("2");
                }
                assertEquals(
                        "PI: Float: " + type.getSimpleName() + "(scale: " + scaleType.getSimpleName() + ")",
                        expected, floor(3.141592653589793f, (Number) o, typeOfN));
                assertEquals(
                        "PI: Double: " + type.getSimpleName() + "(scale: " + scaleType.getSimpleName() + ")",
                        expected, floor(Math.PI, (Number) o, typeOfN));
                assertEquals("PI: BigDecimal: " + type.getSimpleName() + "(scale: " + scaleType.getSimpleName()
                        + ")", expected, floor(new BigDecimal(Math.PI), (Number) o, typeOfN));
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#subtract(java.lang.Object, java.lang.Number, java.lang.Class)}.
 *//*from   w w w.  ja  v  a 2 s .c om*/
@SuppressWarnings("unchecked")
@Test
public void testSubtractObjectNumberClassOfT() {
    assertEquals("null", null, subtract(null, null, null));
    assertEquals("null", null, subtract("123.456", null, null));
    assertEquals("null", null, subtract("123.456", 1, null));
    assertEquals("null", null, subtract("", 10, null));
    assertEquals("null", null, subtract(null, 10, null));
    assertEquals("null", null, subtract(123.456, 10, null));
    assertEquals("123.456 - .456", (Object) 123, subtract(123.456, .456, int.class));
    assertEquals("123.456 - .456: Float", (Object) 123f, subtract(123.456, .456, Float.class));

    assertEquals("123.912 - .456: Float", (Object) 123.456d, subtract(123.912, .456, Double.class));
    assertEquals("123.912 - .456: Float", (Object) 123, subtract(123.912, .456, Integer.class));

    assertEquals("123.456 - .456: Float", (Object) Float.class,
            subtract(123.912d, .456, Float.class).getClass());
    assertEquals("123.456 - .456: Float", (Object) Float.class,
            subtract(123.456, .456d, Float.class).getClass());
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            assertEquals("null: default: " + type.getSimpleName(), valueOf(null, typeOfN),
                    subtract(null, null, typeOfN));
            assertEquals("123.456: " + type.getSimpleName(), valueOf(123.912 - .456, typeOfN),
                    subtract("123.912", .456, typeOfN));
            assertEquals("123.456 - NaN: " + type.getSimpleName(), valueOf(123.456, typeOfN),
                    subtract(123.456, Float.NaN, typeOfN));
            assertEquals("NaN - 123.456: " + type.getSimpleName(), valueOf(123.456, typeOfN),
                    subtract("NaN", 123.456, typeOfN));
            assertEquals("invalid - 123.456: " + type.getSimpleName(), valueOf(123.456, typeOfN),
                    subtract("not a number", 123.456, typeOfN));
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = valueOf(-Double.MAX_VALUE, typeOfN);
            } else if (ClassUtils.isPrimitiveOrWrapper(type)) {
                expected = wrapper.getField("MIN_VALUE").get(null);
            } else {
                expected = new BigDecimal("123.456").subtract(INFINITY_DOUBLE);
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123.456 - Infinity: " + type.getSimpleName(), expected,
                    subtract(123.456, Double.POSITIVE_INFINITY, typeOfN));

            if (ObjectUtils.isAny(wrapper, Float.class)) {
                expected = valueOf("Infinity", typeOfN);
            } else if (ClassUtils.isPrimitiveOrWrapper(type)) {
                expected = wrapper.getField("MAX_VALUE").get(null);
            } else {
                expected = INFINITY_DOUBLE.subtract(new BigDecimal("123.456"));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("Infinity - 123.456: " + type.getSimpleName(), expected,
                    subtract("Infinity", 123.456, typeOfN));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#add(java.lang.Object, java.lang.Number, java.lang.Class)}.
 *///from  w  w  w. ja v a  2 s. co m
@SuppressWarnings("unchecked")
@Test
public void testAddObjectNumberClassOfT() {
    assertEquals("null", null, add(null, null, null));
    assertEquals("null", null, add("123.456", null, null));
    assertEquals("null", null, add("123.456", 1, null));
    assertEquals("null", null, add("", 10, null));
    assertEquals("null", null, add(null, 10, null));
    assertEquals("null", null, add(123.456, 10, null));
    assertEquals("123 + .456: Float", (Object) 123.456f, add(123, .456, Float.class));
    assertEquals("123 + .456: Float", (Object) Float.class, add(123, .456, Float.class).getClass());
    assertEquals("123 + .456: Float", (Object) Float.class, add(123L, .456d, Float.class).getClass());
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            assertEquals("null: default: " + type.getSimpleName(), valueOf(null, typeOfN),
                    add(null, null, typeOfN));
            assertEquals("123.456: " + type.getSimpleName(), valueOf(123 + .456, typeOfN),
                    add("123", .456, typeOfN));
            assertEquals("NaN + 123: " + type.getSimpleName(), valueOf(123, typeOfN), add("NaN", 123, typeOfN));
            assertEquals("123 + NaN: " + type.getSimpleName(), valueOf("123", typeOfN),
                    add("123", Float.NaN, typeOfN));
            assertEquals("invalid + 123: " + type.getSimpleName(), valueOf(123, typeOfN),
                    add("not a number", 123, typeOfN));
            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("-Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("-Infinity", 123, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("Infinity: Double: + 123: " + type.getSimpleName(), expected,
                    add("Infinity", 123, typeOfN));

            if (Double.class.equals(wrapper)) {
                expected = (wrapper.getField("MAX_VALUE").getDouble(null) * -1) + 123;
            } else if (Float.class.equals(wrapper)) {
                expected = Float.NEGATIVE_INFINITY;
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("-Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.negate().add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 - Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.NEGATIVE_INFINITY, typeOfN));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = valueOf("Infinity", typeOfN);
            } else {
                expected = INFINITY_DOUBLE.add(BigDecimal.valueOf(123));
                if (BigInteger.class.equals(type))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("123 + Infinity: Double: " + type.getSimpleName(), expected,
                    add("123", Double.POSITIVE_INFINITY, typeOfN));
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#valueOf(java.lang.Object)}.
 */// w w  w  .j  a  v a  2  s.c o  m
@SuppressWarnings("unchecked")
@Test
public void testValueOfObject() {
    try {
        for (Class<?> type : NUMBERS) {
            Object o = null;
            Object expected = null;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);

            assertEquals("null", expected, valueOf(null));

            o = Float.NaN;
            expected = o;
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o));

            o = Double.NaN;
            expected = o;
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o));

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                o = wrapper.getMethod("valueOf", String.class).invoke(null, "123.456");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                o = wrapper.getMethod("valueOf", String.class).invoke(null, "123");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                o = c.newInstance(BigInteger.class.equals(type) ? "123" : "123.456");
            }
            expected = o;
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o));

            o = INFINITY_DOUBLE.pow(2);
            expected = o;
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o,
                    valueOf(o));

            o = INFINITY_DOUBLE.pow(2).negate();
            expected = o;
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o,
                    valueOf(o));

            o = INFINITY_DOUBLE.pow(2).toBigInteger();
            expected = o;
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o,
                    valueOf(o));

            o = INFINITY_DOUBLE.pow(2).toBigInteger().negate();
            expected = o;
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o,
                    valueOf(o));

            o = "";
            expected = null;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "not a number.";
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = new Object[] { 1, 2, 3 };
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "NaN";
            expected = Double.NaN;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "Infinity";
            expected = Double.POSITIVE_INFINITY;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "-Infinity";
            expected = Double.NEGATIVE_INFINITY;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "123.456f";
            expected = (Float) 123.456f;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "123.456d";
            expected = (Double) 123.456d;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "1.23456E2d";
            expected = (Double) 123.456d;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "1.23456E+2d";
            expected = (Double) 123.456d;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "1000000000000";
            expected = 1000000000000L;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "1E12";
            expected = (Float) 1000000000000f;
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));

            o = "1E600";
            expected = new BigDecimal("1E600");
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
    }
}

From source file:org.apache.sysml.test.integration.AutomatedTestBase.java

/**
 * <p>/*from   www  . j  a v a 2  s  .  co  m*/
 * Runs a test for which the exception expectation can be specified as well
 * as the specific expectation which is expected. If SystemML executes more
 * MR jobs than specified in maxMRJobs this test will fail.
 * </p>
 * @param newWay
 *            in the new way if it is set to true
 * @param exceptionExpected
 *            exception expected
 * @param expectedException
 *            expected exception
 * @param maxMRJobs
 *            specifies a maximum limit for the number of MR jobs. If set to
 *            -1 there is no limit.
 */
protected void runTest(boolean newWay, boolean exceptionExpected, Class<?> expectedException, int maxMRJobs) {

    String executionFile = sourceDirectory + selectedTest + ".dml";

    if (!newWay) {
        executionFile = executionFile + "t";
        ParameterBuilder.setVariablesInScript(sourceDirectory, selectedTest + ".dml", testVariables);
    }

    //cleanup scratch folder (prevent side effect between tests)
    cleanupScratchSpace();

    ArrayList<String> args = new ArrayList<String>();
    // setup arguments to SystemML

    if (DEBUG) {
        args.add("-Dsystemml.logging=trace");
    }

    if (scriptType != null) { // DML/PYDML tests have newWay==true and a non-null scriptType
        switch (scriptType) {
        case DML:
            // Need a null pointer check because some tests read DML from a string.
            if (null != fullDMLScriptName) {
                args.add("-f");
                args.add(fullDMLScriptName);
            }
            break;
        case PYDML:
            if (null != fullDMLScriptName) {
                args.add("-f");
                args.add(fullDMLScriptName);
            }
            break;
        }
    } else if (newWay) {
        // Need a null pointer check because some tests read DML from a string.
        if (null != fullDMLScriptName) {
            args.add("-f");
            args.add(fullDMLScriptName);
        }
    } else {
        if (null != executionFile) {
            args.add("-f");
            args.add(executionFile);
        }
    }
    // program-independent parameters
    if (VISUALIZE)
        args.add("-v");
    args.add("-exec");
    if (rtplatform == RUNTIME_PLATFORM.HADOOP)
        args.add("hadoop");
    else if (rtplatform == RUNTIME_PLATFORM.HYBRID)
        args.add("hybrid");
    else if (rtplatform == RUNTIME_PLATFORM.SINGLE_NODE)
        args.add("singlenode");
    else if (rtplatform == RUNTIME_PLATFORM.SPARK)
        args.add("spark");
    else if (rtplatform == RUNTIME_PLATFORM.HYBRID_SPARK)
        args.add("hybrid_spark");
    else {
        throw new RuntimeException("Unknown runtime platform: " + rtplatform);
    }
    //use optional config file since default under SystemML/DML
    args.add("-config=" + getCurConfigFile().getPath());

    if (TEST_GPU)
        args.add("-gpu");

    // program-specific parameters
    if (newWay) {
        for (int i = 0; i < programArgs.length; i++)
            args.add(programArgs[i]);
    }

    if (DEBUG) {
        if (!newWay)
            TestUtils.printDMLScript(executionFile);
        else {
            if (scriptType == null) {
                TestUtils.printDMLScript(fullDMLScriptName);
            } else if (scriptType == ScriptType.DML) {
                TestUtils.printDMLScript(fullDMLScriptName);
            } else if (scriptType == ScriptType.PYDML) {
                TestUtils.printPYDMLScript(fullDMLScriptName);
            }
        }
    }

    try {
        String[] dmlScriptArgs = args.toArray(new String[args.size()]);
        System.out.println("arguments to DMLScript: " + Arrays.toString(dmlScriptArgs));
        DMLScript.main(dmlScriptArgs);

        /** check number of MR jobs */
        if (maxMRJobs > -1 && maxMRJobs < Statistics.getNoOfCompiledMRJobs())
            fail("Limit of MR jobs is exceeded: expected: " + maxMRJobs + ", occurred: "
                    + Statistics.getNoOfCompiledMRJobs());

        if (exceptionExpected)
            fail("expected exception which has not been raised: " + expectedException);
    } catch (Exception e) {
        if (!exceptionExpected || (expectedException != null && !(e.getClass().equals(expectedException)))) {
            e.printStackTrace();
            StringBuilder errorMessage = new StringBuilder();
            errorMessage.append("failed to run script " + executionFile);
            errorMessage.append("\nexception: " + e.toString());
            errorMessage.append("\nmessage: " + e.getMessage());
            errorMessage.append("\nstack trace:");
            for (StackTraceElement ste : e.getStackTrace()) {
                errorMessage.append("\n>" + ste);
            }
            fail(errorMessage.toString());
        }
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#valueOf(java.lang.Object, java.lang.Class)}.
 *//* ww  w.j  a va 2 s.c  om*/
@SuppressWarnings("unchecked")
@Test
public void testValueOfObjectClassOfT() {
    assertEquals("null", valueOf(null, null, false), valueOf(null, null));
    try {
        for (Class<?> type : NUMBERS) {
            Object o = null;
            assertEquals("null: " + type.getSimpleName(), valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = Float.NaN;
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = Double.NaN;
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            for (Class<?> valueType : OBJECTS) {
                if (ClassUtils.isPrimitiveWrapper(valueType)) {
                    o = valueType.getMethod("valueOf", String.class).invoke(null, "1");
                } else {
                    o = valueType.getField("ONE").get(null);
                }
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                        valueOf(o, (Class<? extends Number>) type, false),
                        valueOf(o, (Class<? extends Number>) type));
            }

            for (Class<?> valueType : OBJECTS) {
                if (ClassUtils.isPrimitiveWrapper(valueType)) {
                    o = valueType.getMethod("valueOf", String.class).invoke(null, "-123");
                } else {
                    Constructor<?> c = valueType.getDeclaredConstructor(String.class);
                    o = c.newInstance("-123");
                }
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                        valueOf(o, (Class<? extends Number>) type, false),
                        valueOf(o, (Class<? extends Number>) type));
            }

            for (Class<?> valueType : OBJECTS) {
                if (ObjectUtils.isAny(valueType, Double.class, Float.class)) {
                    o = valueType.getMethod("valueOf", String.class).invoke(null, "123.456");
                } else if (BigDecimal.class.equals(valueType)) {
                    Constructor<?> c = valueType.getDeclaredConstructor(String.class);
                    o = c.newInstance("123.456");
                } else {
                    continue;
                }
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                        valueOf(o, (Class<? extends Number>) type, false),
                        valueOf(o, (Class<? extends Number>) type));
            }

            for (Class<?> valueType : OBJECTS) {
                if (ObjectUtils.isAny(valueType, Double.class, Float.class)) {
                    o = valueType.getMethod("valueOf", String.class).invoke(null, "-123.456");
                } else if (BigDecimal.class.equals(valueType)) {
                    Constructor<?> c = valueType.getDeclaredConstructor(String.class);
                    o = c.newInstance("-123.456");
                } else {
                    continue;
                }
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                        valueOf(o, (Class<? extends Number>) type, false),
                        valueOf(o, (Class<? extends Number>) type));
            }

            o = INFINITY_DOUBLE.pow(2);
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = INFINITY_DOUBLE.pow(2).negate();
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = INFINITY_DOUBLE.pow(2).toBigInteger();
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = INFINITY_DOUBLE.pow(2).toBigInteger().negate();
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = "";
            assertEquals("\"" + o + "\": " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = "1";
            assertEquals("\"" + o + "\": " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = "-123456E-3";
            assertEquals("\"" + o + "\": " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = "Infinity";
            assertEquals("\"" + o + "\": " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));

            o = "-Infinity";
            assertEquals("\"" + o + "\": " + type.getSimpleName(),
                    valueOf(o, (Class<? extends Number>) type, false),
                    valueOf(o, (Class<? extends Number>) type));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
    }
}

From source file:base.BasePlayer.ClusterTable.java

void drawScreen(Graphics g) {
    try {//w  w w  .  j a v  a  2  s .c o m

        buf.setColor(Color.black);
        buf.fillRect(0, 0, this.getWidth(), tablescroll.getViewport().getHeight());
        genemutcount = 0;
        hoverVar = null;
        hoverSample = -1;
        headerHover = -1;
        geneHeaderHover = -1;

        if (!mouseDrag) {
            resizeColumn = -1;
        }
        if (Main.drawCanvas.clusterNodes != null) {
            firstrow = tablescroll.getVerticalScrollBar().getValue() / rowHeight - 1
                    - Main.drawCanvas.clusterNodes.size();

            if (firstrow < 0) {
                firstrow = 0;
            }
            for (int i = 0; i < Main.drawCanvas.clusterNodes.size(); i++) {
                dot = false;

                if ((i + 1 + samplecount + Main.drawCanvas.clusterNodes.size()) * rowHeight < tablescroll
                        .getVerticalScrollBar().getValue()) {
                    continue;
                }

                if (i * rowHeight > tablescroll.getVerticalScrollBar().getValue()
                        + tablescroll.getViewport().getHeight()) {
                    break;
                }

                if (mouseY >= (rowHeight * (i + genemutcount + 1))
                        && mouseY < (rowHeight * (i + genemutcount + 2))) {
                    hoverNode = Main.drawCanvas.clusterNodes.get(i);
                }
                try {
                    buf.setColor(Color.darkGray);
                    buf.drawLine(4,
                            (rowHeight * (i + genemutcount + 1)) - tablescroll.getVerticalScrollBar().getValue()
                                    + 3,
                            this.getWidth(), (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 3);

                    buf.setColor(linecolor);
                    cluster = Main.drawCanvas.clusterNodes.get(i);
                    if (cluster.varnodes.get(0).getTranscripts() != null) {
                        if (!chrom.equals(cluster.varnodes.get(0).getTranscripts().get(0).getChrom())) {
                            chrom = cluster.varnodes.get(0).getTranscripts().get(0).getChrom();
                        }
                    } else {
                        if (!chrom.equals(cluster.varnodes.get(0).getExons().get(0).transcript.getChrom())) {
                            chrom = cluster.varnodes.get(0).getExons().get(0).transcript.getChrom();
                        }
                    }

                    for (int c = 0; c < header.size(); c++) {

                        if (Main.drawCanvas.clusterNodes.get(i).equals(hoverNode)
                                || Main.drawCanvas.clusterNodes.get(i).equals(selectedNode)) {

                            buf.setColor(Color.yellow);
                        } else {
                            buf.setColor(Color.white);
                        }

                        if (c == 0) {

                            buf.drawString("" + cluster.ID, (int) header.get(c)[1] + 5,
                                    (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 1) {
                            buf.drawString("" + cluster.nodecount, (int) header.get(c)[1] + 5,
                                    (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 2) {
                            buf.drawString("" + cluster.width, (int) header.get(c)[1] + 5,
                                    (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 3) {
                            buf.drawString(
                                    chrom + ":"
                                            + MethodLibrary.formatNumber(cluster.varnodes.get(0).getPosition()),
                                    (int) header.get(c)[1] + 5, (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 4) {
                            buf.drawString(
                                    "" + MethodLibrary.round((cluster.nodecount / (double) cluster.width), 4),
                                    (int) header.get(c)[1] + 5, (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                        } else if (c == 5) {
                            if (cluster.varnodes.get(0).getExons() != null) {

                                if (cluster.varnodes.get(0).coding) {
                                    buf.setColor(Color.red);
                                    buf.drawString(
                                            cluster.varnodes.get(0).getExons().get(0).getTranscript()
                                                    .getGenename() + " (Coding)",
                                            (int) header.get(c)[1] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                } else {
                                    buf.setColor(Color.lightGray);
                                    buf.drawString(
                                            cluster.varnodes.get(0).getExons().get(0).getTranscript()
                                                    .getGenename() + " (UTR)",
                                            (int) header.get(c)[1] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                }
                            } else if (cluster.varnodes.get(0).isInGene()) {
                                buf.setColor(Color.lightGray);
                                buf.drawString(
                                        cluster.varnodes.get(0).getTranscripts().get(0).getGenename()
                                                + " (Intronic)",
                                        (int) header.get(c)[1] + 5, (rowHeight * (i + 1 + genemutcount))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            } else {
                                buf.setColor(Color.gray);
                                if (!cluster.varnodes.get(0).getTranscripts().get(0)
                                        .equals(cluster.varnodes.get(0).getTranscripts().get(1))) {
                                    buf.drawString(
                                            cluster.varnodes.get(0).getTranscripts().get(0).getGenename()
                                                    + " ... "
                                                    + cluster.varnodes
                                                            .get(0).getTranscripts().get(1).getGenename(),
                                            (int) header.get(c)[1] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                } else {
                                    if (cluster.varnodes.get(0).getTranscripts().get(0)
                                            .getEnd() > cluster.varnodes.get(0).getPosition()) {
                                        buf.drawString(
                                                " ... " + cluster.varnodes
                                                        .get(0).getTranscripts().get(0).getGenename(),
                                                (int) header.get(c)[1] + 5,
                                                (rowHeight * (i + 1 + genemutcount))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                    } else {
                                        buf.drawString(
                                                cluster.varnodes.get(0).getTranscripts().get(0).getGenename()
                                                        + " ... ",
                                                (int) header.get(c)[1] + 5,
                                                (rowHeight * (i + 1 + genemutcount))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);

                                    }
                                }
                            }
                        } else if (c == 6) {

                            if (cluster.varnodes.get(0).getBedHits() != null) {
                                bedarray = MethodLibrary.makeTrackArray(cluster.varnodes.get(0), null);
                                for (int b = 0; b < bedarray.length; b++) {
                                    buf.setColor(Color.black);
                                    if (b == bedarray.length - 1) {
                                        buf.fillRect((int) header.get(c + b)[1] + 1,
                                                (rowHeight * (i + genemutcount + 1))
                                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                this.getWidth() - (int) header.get(c + b)[1], rowHeight - 1);
                                    } else {
                                        buf.fillRect((int) header.get(c + b)[1] + 1,
                                                (rowHeight * (i + genemutcount + 1))
                                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                (int) header.get(c + b)[2], rowHeight - 1);

                                    }
                                    buf.setColor(Color.white);
                                    if (bedarray[b] != null) {
                                        buf.drawString(bedarray[b].toString(), (int) header.get(c + b)[1] + 5,
                                                (rowHeight * (i + 1 + genemutcount))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);

                                    }
                                }
                            }
                        }
                        if (c < header.size() - 1 - Main.bedCanvas.bedTrack.size()) {
                            buf.setColor(Color.black);
                            buf.fillRect((int) header.get(c + 1)[1] + 1,
                                    (rowHeight * (i + genemutcount + 1))
                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                    (int) header.get(c + 1)[2], rowHeight - 1);

                        }
                    }
                    buf.setColor(Color.darkGray);
                    buf.drawLine(3, rowHeight + 3, 3, (rowHeight * (i + genemutcount + 2))
                            - tablescroll.getVerticalScrollBar().getValue() + 3);

                    for (int r = 0; r < header.size(); r++) {
                        buf.drawLine((int) header.get(r)[1],
                                (rowHeight * (i + genemutcount + 1))
                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                (int) header.get(r)[1], (rowHeight * (i + genemutcount + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + 3);
                    }
                    if (selectedNode != null && selectedNode.equals(cluster)) {

                        hoverSample = -1;
                        genemutcount = aminoarray.size() + 1;
                        listAdd = 1;
                        buf.drawLine(20,
                                (rowHeight * (i + listAdd + 2)) - tablescroll.getVerticalScrollBar().getValue()
                                        + 3,
                                this.getWidth(), (rowHeight * (i + listAdd + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + 3);
                        drawGeneheader((rowHeight * (i + listAdd + 1))
                                - tablescroll.getVerticalScrollBar().getValue() + 3);

                        for (int s = 0; s < aminoarray.size(); s++) {

                            buf.setColor(Color.darkGray);
                            buf.drawLine(21,
                                    (rowHeight * (i + s + listAdd + 3))
                                            - tablescroll.getVerticalScrollBar().getValue() + 3,
                                    this.getWidth(), (rowHeight * (i + s + listAdd + 3))
                                            - tablescroll.getVerticalScrollBar().getValue() + 3);

                            if (mouseY >= (rowHeight * (i + s + listAdd + 2))
                                    && mouseY < (rowHeight * (i + s + listAdd + 3))) {
                                hoverNode = null;
                                hoverVar = aminoarray.get(s).getNode();
                                hoverString = aminoarray.get(s).getRow();
                                buf.setColor(Color.white);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        hoverSample = aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .getSample().getIndex();
                                        break;
                                    }
                                }
                            } else {
                                if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("nonsense")) {
                                    buf.setColor(Color.red);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("missense")) {
                                    buf.setColor(Color.yellow);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("synonymous")) {
                                    buf.setColor(Color.green);
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("UTR")) {
                                    buf.setColor(Color.lightGray);
                                } else {
                                    buf.setColor(Color.gray);
                                }
                            }
                            if (!aminoarray.get(s).getRow()[1].equals("1")) {

                                buf.drawString("Multiple", 24, (rowHeight * (i + s + listAdd + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                            } else {
                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {

                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {

                                        buf.drawString(
                                                aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                        .getSample().getName(),
                                                24,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                        break;
                                    }
                                }

                            }

                            if (hoverVar != null && hoverString.equals(aminoarray.get(s).getRow())) {
                                //TODO
                                textcolor = Color.white;

                            } else {
                                if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("nonsense")) {
                                    textcolor = Color.red;
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("missense")) {
                                    textcolor = Color.yellow;
                                } else if (MethodLibrary.aminoEffect(aminoarray.get(s).getRow()[3])
                                        .equals("synonymous")) {
                                    textcolor = Color.green;
                                } else if (aminoarray.get(s).getRow()[3].contains("UTR")) {
                                    textcolor = Color.lightGray;
                                } else {
                                    textcolor = Color.gray;
                                }
                            }
                            for (int h = 1; h < 4; h++) {
                                buf.setColor(Color.black);
                                buf.fillRect((int) geneheader.get(h)[1] + 10,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        (int) geneheader.get(h)[2], rowHeight - 1);
                                buf.setColor(textcolor);
                                buf.drawString(aminoarray.get(s).getRow()[h], (int) geneheader.get(h)[1] + 14,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            }

                            if (aminoarray.get(s).getRow()[1].equals("1")) {
                                buf.setColor(Color.black);
                                buf.fillRect((int) geneheader.get(4)[1] + 10,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        this.getWidth(), rowHeight - 1);
                                buf.setColor(textcolor);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        if (aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .isHomozygous()) {
                                            buf.drawString(
                                                    "Hom (" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(0).getCalls() + "/"
                                                            + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                                    .get(0).getCoverage()
                                                            + ")",
                                                    (int) geneheader.get(4)[1] + 14,
                                                    (rowHeight * (i + s + listAdd + 2))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            if (Control.controlData.controlsOn) {
                                                cases = 2;
                                                casefreq = 2 / (double) (Main.varsamples * 2);
                                            }
                                        } else {
                                            buf.drawString(
                                                    "Het (" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(0).getCalls() + "/"
                                                            + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                                    .get(0).getCoverage()
                                                            + ")",
                                                    (int) geneheader.get(4)[1] + 14,
                                                    (rowHeight * (i + s + listAdd + 2))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            if (Control.controlData.controlsOn) {
                                                cases = 1;
                                                casefreq = 1 / (double) (Main.varsamples * 2);
                                            }

                                        }
                                        buf.setColor(Color.black);
                                        buf.fillRect((int) geneheader.get(5)[1] + 1,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                this.getWidth(), rowHeight - 1);
                                        buf.setColor(textcolor);
                                        buf.drawString(
                                                "" + aminoarray.get(s).getNode().vars
                                                        .get(v).getValue().get(0).getQuality(),
                                                (int) geneheader.get(5)[1] + 14,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);

                                    }
                                }
                            }

                            if (Control.controlData.controlsOn) {
                                cases = 0;
                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        if (aminoarray.get(s).getNode().vars.get(v).getValue().get(0)
                                                .isHomozygous()) {
                                            cases += Integer.parseInt(aminoarray.get(s).getRow()[1]) * 2;
                                        } else {
                                            cases += Integer.parseInt(aminoarray.get(s).getRow()[1]);
                                        }
                                    }
                                }
                                casefreq = cases / (double) (Main.varsamples * 2);
                            }

                            buf.setColor(textcolor);
                            buf.drawString(aminoarray.get(s).getRow()[4], (int) geneheader.get(6)[1] + 14,
                                    (rowHeight * (i + s + listAdd + 2))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            if (Control.controlData.controlsOn) {
                                buf.setColor(textcolor);

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(aminoarray.get(s).getRow()[5])) {
                                        vararray = aminoarray.get(s).getNode().vars.get(v).getValue();
                                        controlarray = new SampleNode[Control.controlData.fileArray.size()];
                                        if (vararray.get(vararray.size() - 1).alleles != null) {

                                            for (int e = vararray.size() - 1; e > 0; e--) {

                                                if (vararray.get(e).alleles == null) {
                                                    break;
                                                }
                                                controlarray[vararray.get(e).getControlSample()
                                                        .getIndex()] = vararray.get(e);

                                            }
                                        }
                                        for (int e = 0; e < controlarray.length; e++) {
                                            if (Control.controlData.fileArray.get(e).controlOn) {
                                                if (controlarray[e] == null) {
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("0",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("-",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);

                                                } else {
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString(
                                                            "" + MethodLibrary.round(controlarray[e].alleles
                                                                    / (double) controlarray[e].allelenumber, 2),
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2)[1] + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                    buf.setColor(Color.black);
                                                    buf.fillRect(
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 11,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue() + 4,
                                                            this.getWidth(), rowHeight - 1);
                                                    buf.setColor(textcolor);
                                                    buf.drawString("" + MethodLibrary
                                                            .round(casefreq / (controlarray[e].alleles
                                                                    / (double) controlarray[e].allelenumber), 2)
                                                            + " (p="
                                                            + MethodLibrary.round(
                                                                    VariantHandler.table.fe.getRightTailedP(
                                                                            cases, Main.varsamples * 2 - cases,
                                                                            controlarray[e].alleles,
                                                                            controlarray[e].allelenumber
                                                                                    - controlarray[e].alleles),
                                                                    2)
                                                            + ")",
                                                            (int) geneheader
                                                                    .get(this.geneheaderlength + e * 2 + 1)[1]
                                                                    + 14,
                                                            (rowHeight * (i + s + listAdd + 2)) - tablescroll
                                                                    .getVerticalScrollBar().getValue()
                                                                    + rowHeight);
                                                }
                                            } else {
                                                buf.setColor(Color.black);
                                                buf.fillRect(
                                                        (int) geneheader.get(this.geneheaderlength + e * 2)[1]
                                                                + 11,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth(), rowHeight - 1);
                                                buf.setColor(Color.darkGray);
                                                buf.drawString("Apply controls",
                                                        (int) geneheader.get(this.geneheaderlength + e * 2)[1]
                                                                + 14,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);
                                                buf.setColor(Color.black);
                                                buf.fillRect(
                                                        (int) geneheader
                                                                .get(this.geneheaderlength + e * 2 + 1)[1] + 11,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth(), rowHeight - 1);
                                                buf.setColor(Color.darkGray);
                                                buf.drawString("-",
                                                        (int) geneheader
                                                                .get(this.geneheaderlength + e * 2 + 1)[1] + 14,
                                                        (rowHeight * (i + s + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            }
                                        }
                                    }
                                }
                            } else {
                                buf.setColor(Color.darkGray);

                                for (int e = geneheaderlength; e < geneheader.size(); e++) {
                                    if (geneheader.get(e)[0] instanceof ControlFile) {
                                        buf.drawString("Apply controls", (int) geneheader.get(e)[1] + 14,
                                                (rowHeight * (i + s + listAdd + 2))
                                                        - tablescroll.getVerticalScrollBar().getValue()
                                                        + rowHeight);
                                    }
                                }
                                buf.setColor(Color.lightGray);
                            }
                            vararray = null;
                            if (Main.bedCanvas.bedOn) {
                                for (int a = 0; a < aminoarray.size(); a++) {
                                    bedarray = MethodLibrary.makeTrackArray(aminoarray.get(a).getNode(),
                                            aminoarray.get(a).getRow()[5]);
                                    if (bedarray != null) {
                                        for (int b = 0; b < bedarray.length; b++) {
                                            buf.setColor(Color.black);
                                            if (b == bedarray.length - 1) {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth() - (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1],
                                                        rowHeight - 1);
                                            } else {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[2],
                                                        rowHeight - 1);
                                            }
                                            buf.setColor(Color.white);
                                            if (bedarray[b] != null) {
                                                buf.drawString(bedarray[b].toString(),
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + b)[1] + 14,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            }
                                        }
                                    }
                                }
                            }
                            buf.setColor(Color.darkGray);
                            for (int j = 0; j < geneheader.size(); j++) {

                                buf.drawLine((int) geneheader.get(j)[1] + 11,
                                        (rowHeight * (i + s + listAdd + 2))
                                                - tablescroll.getVerticalScrollBar().getValue() + 4,
                                        (int) geneheader.get(j)[1] + 11, (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3);
                            }
                            if (selectedVar != null && selectedString.equals(aminoarray.get(s).getRow())
                                    && Integer.parseInt(selectedString[1]) > 1) {
                                //hoverSample = -1;
                                pointer = 0;
                                //TODO

                                for (int v = 0; v < aminoarray.get(s).getNode().vars.size(); v++) {
                                    if (aminoarray.get(s).getNode().vars.get(v).getKey()
                                            .equals(selectedString[5])) {

                                        for (int l = 0; l < aminoarray.get(s).getNode().vars.get(v).getValue()
                                                .size(); l++) {
                                            if (aminoarray.get(s).getNode().vars.get(v).getValue()
                                                    .get(l).alleles != null) {
                                                break;
                                            }
                                            if (mouseY > (rowHeight * (i + s + pointer + 4))
                                                    && mouseY < (rowHeight * (i + s + pointer + 5))) {
                                                textcolor = Color.white;

                                                hoverVar = aminoarray.get(s).getNode();
                                                hoverString = aminoarray.get(s).getRow();
                                                hoverSample = aminoarray.get(s).getNode().vars.get(v).getValue()
                                                        .get(l).getSample().getIndex();
                                            } else {
                                                textcolor = Color.lightGray;
                                            }

                                            //   if(aminoarray.get(s).getNode().getSamples().get(l).getVariation().equals(selectedString[5])) {                           
                                            buf.setColor(textcolor);
                                            buf.drawString(
                                                    aminoarray.get(s).getNode().vars.get(v).getValue().get(l)
                                                            .getSample().getName(),
                                                    30,
                                                    (rowHeight * (i + s + pointer + 4))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            pointer++;
                                            //   }   

                                            buf.setColor(Color.black);
                                            buf.fillRect((int) geneheader.get(4)[1] + 10,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                    this.getWidth(), rowHeight - 1);
                                            buf.setColor(textcolor);
                                            if (aminoarray.get(s).getNode().vars.get(v).getValue().get(l)
                                                    .isHomozygous()) {
                                                buf.drawString(
                                                        "Hom (" + aminoarray.get(s).getNode().vars.get(v)
                                                                .getValue().get(l).getCalls() + "/"
                                                                + aminoarray.get(s).getNode().vars.get(v)
                                                                        .getValue().get(l).getCoverage()
                                                                + ")",
                                                        (int) geneheader.get(4)[1] + 14,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            } else {
                                                buf.drawString(
                                                        "Het (" + aminoarray.get(s).getNode().vars.get(v)
                                                                .getValue().get(l).getCalls() + "/"
                                                                + aminoarray.get(s).getNode().vars.get(v)
                                                                        .getValue().get(l).getCoverage()
                                                                + ")",
                                                        (int) geneheader.get(4)[1] + 14,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);
                                            }

                                            buf.setColor(Color.black);
                                            buf.fillRect((int) geneheader.get(5)[1] + 10,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue() + 4,
                                                    this.getWidth(), rowHeight - 1);
                                            buf.setColor(textcolor);
                                            buf.drawString(
                                                    "" + aminoarray.get(s).getNode().vars.get(v).getValue()
                                                            .get(l).getQuality(),
                                                    (int) geneheader.get(5)[1] + 14,
                                                    (rowHeight * (i + s + pointer + 3))
                                                            - tablescroll.getVerticalScrollBar().getValue()
                                                            + rowHeight);
                                            buf.setColor(Color.darkGray);
                                            for (int j = 4; j < 7; j++) {

                                                buf.drawLine((int) geneheader.get(j)[1] + 11,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue(),
                                                        (int) geneheader.get(j)[1] + 11,
                                                        (rowHeight * (i + s + pointer + 3))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight + 2);
                                            }

                                        }
                                    }
                                }
                                listAdd = Integer.parseInt(selectedString[1]) + 1;
                                genemutcount = aminoarray.size() + listAdd;
                                buf.setColor(Color.darkGray);
                                buf.drawLine(21,
                                        (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3,
                                        this.getWidth(), (rowHeight * (i + s + listAdd + 3))
                                                - tablescroll.getVerticalScrollBar().getValue() + 3);

                            }

                        }
                    }

                } catch (Exception e) {
                    ErrorLog.addError(e.getStackTrace());
                    e.printStackTrace();
                }

            }
            buf.setColor(Color.darkGray);
            buf.drawLine(4,
                    (rowHeight * (Main.drawCanvas.clusterNodes.size() + genemutcount + 1))
                            - tablescroll.getVerticalScrollBar().getValue() + 3,
                    this.getWidth(), (rowHeight * (Main.drawCanvas.clusterNodes.size() + genemutcount + 1))
                            - tablescroll.getVerticalScrollBar().getValue() + 3);

        }
        drawHeader();

        if (headerHover == -1 && geneHeaderHover == -1) {

            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        } else {
            if (resizeColumn == -1) {
                setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            } else {
                setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
            }
        }

        g.drawImage(bufImage, 0, tablescroll.getVerticalScrollBar().getValue(), null);

    } catch (Exception e) {
        e.printStackTrace();
    }
}