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:com.flexive.tests.embedded.SearchEngineTest.java

/**
 * Tests all available value comparators for the given datatype. Note that no semantic
 * tests are performed, each comparator is executed with a random value.
 *
 * @param name     the base property name
 * @param dataType the datatype of the property
 * @throws com.flexive.shared.exceptions.FxApplicationException
 *          on search engine errors/*w w  w. j a  v  a  2  s .c o  m*/
 */
@Test(dataProvider = "testProperties")
public void genericConditionTest(String name, FxDataType dataType) throws FxApplicationException {
    final FxPropertyAssignment assignment = getTestPropertyAssignment(name);
    final Random random = new Random(0);

    // need to get some folder IDs for the reference property
    final List<FxPK> folderPks = getFolderPks();

    for (PropertyValueComparator comparator : PropertyValueComparator.getAvailable(dataType)) {
        for (String prefix : new String[] { TEST_TYPE + "/", TEST_TYPE + "/groupTop/",
                TEST_TYPE + "/groupTop/groupNested/" }) {
            final String assignmentName = prefix + getTestPropertyName(name);
            try {
                // submit a query with the given property/comparator combination
                final FxValue value;
                switch (dataType) {
                case Reference:
                    value = new FxReference(
                            new ReferencedContent(folderPks.get(random.nextInt(folderPks.size()))));
                    break;
                case DateRange:
                    // a query is always performed against a particular date, but not a date range
                    value = new FxDate(new Date());
                    break;
                case DateTimeRange:
                    value = new FxDateTime(new Date());
                    break;
                default:
                    value = dataType.getRandomValue(random, assignment);
                }
                new SqlQueryBuilder().condition(assignmentName, comparator, value).getResult();
                // no exception thrown, consider it a success
            } catch (Exception e) {
                fail("Failed to submit for property " + dataType + " with comparator " + comparator + ":\n"
                        + e.getMessage() + ", thrown at:\n" + StringUtils.join(e.getStackTrace(), '\n'));
            }
        }
    }
}

From source file:base.BasePlayer.AminoTable.java

void getAminos(Gene gene) {

    try {/*from  w ww .  j a  va2 s. c  o  m*/
        aminoarray.clear();

        VarNode varnode = null;
        Map.Entry<String, ArrayList<SampleNode>> entry;

        for (int t = 0; t < gene.varnodes.size(); t++) {

            varnode = gene.varnodes.get(t);

            if (gene.intergenic) {

                for (int v = 0; v < varnode.vars.size(); v++) {
                    entry = varnode.vars.get(v);
                    mutcount = 0;
                    for (int m = 0; m < entry.getValue().size(); m++) {
                        if (entry.getValue().get(m).alleles != null) {
                            break;
                        }
                        if (entry.getValue().get(m).getSample().annotation) {
                            entry.getValue().remove(m);
                            m--;
                            continue;
                        }
                        if (!Main.drawCanvas.hideVar(entry.getValue().get(m), entry.getKey().length() > 1)
                                && !entry.getValue().get(m).getSample().annotation) {
                            if (!VariantHandler.none.isSelected()) {
                                if (!entry.getValue().get(m).inheritance) {
                                    if (!entry.getValue().get(m).getSample()
                                            .equals(Main.drawCanvas.selectedSample)) {
                                        entry.getValue().remove(m);
                                        m--;
                                        continue;
                                    }
                                }
                                //mutcount++;
                            }
                            if (VariantHandler.onlyselected.isSelected()) {
                                if (!entry.getValue().get(m).getSample()
                                        .equals(Main.drawCanvas.selectedSample)) {
                                    entry.getValue().remove(m);
                                    m--;
                                    continue;
                                }
                            }
                            mutcount++;
                        } else {
                            entry.getValue().remove(m);
                            m--;
                        }
                    }

                    if (mutcount == 0) {
                        continue;
                    }

                    base = entry.getKey();
                    String[] addrow = new String[9];

                    if (varnode.getTranscripts() == null) {
                        addrow[0] = gene.getName();
                    } else if (varnode.getTranscripts().size() == 2) {
                        addrow[0] = gene.getName() + " ... " + varnode.getTranscripts().get(1).getGenename();
                    } else if (varnode.getPosition() < gene.getStart()) {
                        addrow[0] = "... " + varnode.getTranscripts().get(1).getGenename();
                    } else {
                        addrow[0] = gene.getName() + " ...";
                    }

                    addrow[1] = "" + mutcount;
                    addrow[2] = gene.getChrom() + ":" + MethodLibrary.formatNumber((varnode.getPosition() + 1));
                    addrow[3] = "Intergenic";
                    if (varnode.isRscode() != null) {
                        addrow[4] = varnode.rscode;
                    } else {
                        addrow[4] = "N/A";
                    }
                    addrow[5] = base;
                    addrow[6] = "Intergenic";
                    addrow[7] = "Intergenic";
                    addrow[8] = "Intergenic";
                    AminoEntry aminoentry = new AminoEntry(addrow, varnode);
                    aminoarray.add(aminoentry);
                }
                continue;
            }
            if (varnode.getExons() != null) {

                //   for(int exon = 0; exon<varnode.getExons().size(); exon++) {
                /*   if(!VariantHandler.allIsoforms.isSelected() && varnode.getExons().get(exon).getTranscript().getGene().getCanonical() != null && !varnode.getExons().get(exon).getTranscript().isCanonical()) {
                      continue;
                   }*/
                /*if(!gene.equals(varnode.getExons().get(exon).getTranscript().getGene())) {
                   continue;
                }
                */
                if (!varnode.coding && !VariantHandler.utr.isSelected()) {

                    continue;
                }

                for (int v = 0; v < varnode.vars.size(); v++) {

                    entry = varnode.vars.get(v);
                    mutcount = 0;
                    for (int m = 0; m < entry.getValue().size(); m++) {
                        if (entry.getValue().get(m).alleles != null) {
                            continue;
                        }
                        if (entry.getValue().get(m).getSample().annotation) {

                            continue;
                        }
                        if (!VariantHandler.none.isSelected()) {

                            if (!entry.getValue().get(m).inheritance) {
                                entry.getValue().remove(m);
                                m--;
                                continue;
                            }
                        }

                        if (!Main.drawCanvas.hideVar(entry.getValue().get(m), entry.getKey().length() > 1)) {

                            if (VariantHandler.onlyselected.isSelected()) {
                                if (!entry.getValue().get(m).getSample()
                                        .equals(Main.drawCanvas.selectedSample)) {
                                    entry.getValue().remove(m);
                                    m--;
                                    continue;
                                }
                            }
                            mutcount++;
                        } else {

                            entry.getValue().remove(m);
                            m--;
                        }
                    }

                    if (mutcount == 0) {
                        continue;
                    }

                    base = entry.getKey();
                    String[] addrow = new String[9];
                    StringBuffer aminos = new StringBuffer(""), transcripts = new StringBuffer(""),
                            exons = new StringBuffer(""), biotypes = new StringBuffer("");
                    addrow[0] = gene.getName();
                    addrow[1] = "" + mutcount;
                    addrow[2] = gene.getChrom() + ":" + MethodLibrary.formatNumber((varnode.getPosition() + 1));
                    String aminochange;
                    for (int exon = 0; exon < varnode.getExons().size(); exon++) {

                        if (!varnode.getExons().get(exon).getTranscript().getGene().equals(gene)) {
                            continue;
                        }
                        aminochange = Main.chromDraw.getAminoChange(varnode, base,
                                varnode.getExons().get(exon));
                        if (aminochange.contains("UTR") && !VariantHandler.utr.isSelected()) {
                            continue;
                        }
                        if (VariantHandler.nonsense.isSelected()) {
                            if (!MethodLibrary.aminoEffect(aminochange).contains("nonsense")) {
                                continue;
                            }
                        } else if (VariantHandler.synonymous.isSelected()) {

                            if (MethodLibrary.aminoEffect(aminochange).contains("synonymous")) {
                                continue;
                            }
                        }

                        if (aminos.length() == 0) {
                            aminos.append(aminochange);
                            transcripts.append(varnode.getExons().get(exon).getTranscript().getENST());
                            biotypes.append(varnode.getExons().get(exon).getTranscript().getBiotype());
                            exons.append(varnode.getExons().get(exon).getNro());
                        } else {
                            aminos.append(";" + aminochange);
                            transcripts.append(";" + varnode.getExons().get(exon).getTranscript().getENST());
                            biotypes.append(";" + varnode.getExons().get(exon).getTranscript().getBiotype());
                            exons.append(";" + varnode.getExons().get(exon).getNro());
                        }
                    }
                    addrow[3] = aminos.toString();

                    if (varnode.isRscode() != null) {
                        addrow[4] = varnode.rscode;
                    } else {
                        addrow[4] = "N/A";
                    }
                    addrow[5] = base;
                    addrow[6] = transcripts.toString();
                    addrow[7] = biotypes.toString();
                    addrow[8] = exons.toString();
                    //      varAdd.putNext(null);
                    //      varAdd.putPrev(null);

                    AminoEntry aminoentry = new AminoEntry(addrow, varnode);
                    /*if(varnode.getPosition() == 127796784) {
                       System.out.println("Jou");
                    }*/
                    aminoarray.add(aminoentry);

                }

                //   }
            }
            if (VariantHandler.intronic.isSelected() && varnode.isInGene() && varnode.getTranscripts() != null
                    && varnode.getExons() == null) {

                for (int v = 0; v < varnode.vars.size(); v++) {
                    entry = varnode.vars.get(v);
                    base = entry.getKey();
                    mutcount = 0;
                    for (int m = 0; m < entry.getValue().size(); m++) {
                        if (entry.getValue().get(m).alleles != null) {

                            break;
                        }
                        if (entry.getValue().get(m).getSample().annotation) {
                            entry.getValue().remove(m);
                            m--;
                            continue;
                        }
                        if (!Main.drawCanvas.hideVar(entry.getValue().get(m), entry.getKey().length() > 1)) {
                            if (VariantHandler.onlyselected.isSelected()) {
                                if (!entry.getValue().get(m).getSample()
                                        .equals(Main.drawCanvas.selectedSample)) {
                                    entry.getValue().remove(m);
                                    m--;
                                    continue;
                                }
                            }
                            mutcount++;
                        } else {
                            entry.getValue().remove(m);
                            m--;
                        }
                    }
                    if (mutcount == 0) {
                        continue;
                    }
                    StringBuffer transcripts = new StringBuffer(""), biotypes = new StringBuffer("");

                    String[] addrow = new String[9];
                    addrow[0] = gene.getName();
                    addrow[1] = "" + mutcount;
                    addrow[2] = gene.getChrom() + ":" + MethodLibrary.formatNumber((varnode.getPosition() + 1));
                    addrow[3] = Main.getBase.get(varnode.getRefBase()) + "->" + base + " (intronic)";

                    if (varnode.isRscode() != null) {
                        addrow[4] = varnode.rscode;
                    } else {
                        addrow[4] = "N/A";
                    }
                    addrow[5] = base;
                    for (int trans = 0; trans < varnode.getTranscripts().size(); trans++) {
                        if (!varnode.getTranscripts().get(trans).getGene().equals(gene)) {
                            continue;
                        }

                        if (transcripts.length() == 0) {

                            transcripts.append(varnode.getTranscripts().get(trans).getENST());
                            biotypes.append(varnode.getTranscripts().get(trans).getBiotype());

                        } else {

                            transcripts.append(";" + varnode.getTranscripts().get(trans).getENST());
                            biotypes.append(";" + varnode.getTranscripts().get(trans).getBiotype());

                        }
                    }

                    if (varnode.isRscode() != null) {
                        addrow[4] = varnode.rscode;
                    } else {
                        addrow[4] = "N/A";
                    }
                    addrow[5] = base;
                    addrow[6] = transcripts.toString();
                    addrow[7] = biotypes.toString();
                    addrow[8] = "Intronic";
                    AminoEntry aminoentry = new AminoEntry(addrow, varnode);
                    aminoarray.add(aminoentry);

                }
            }

        }

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

}

From source file:com.chinamobile.bcbsp.sync.GeneralSSController.java

@Override
public void cleanup() {
    List<String> list = new ArrayList<String>();
    List<String> tmpList = new ArrayList<String>();
    try {/*from  www  .  ja v a 2  s .  co m*/
        try {
            list.clear();
            list = bspzk.getChildren(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-s", false);
            for (String e : list) {
                bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-s" + "/" + e, bspzk
                        .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-s" + "/" + e, false)
                        .getVersion());
            }
        } catch (Exception e) {
            LOG.info("The exception is " + e.getStackTrace());
        } finally {
            bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-s", bspzk
                    .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-s", false).getVersion());
        }
        jip.reportLOG(jobId.toString() + "delete the -s");
        try {
            list.clear();
            list = bspzk.getChildren(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-d", false);
            for (String e : list) {
                bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-d" + "/" + e, bspzk
                        .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-d" + "/" + e, false)
                        .getVersion());
            }
        } catch (Exception e) {
            LOG.info("The exception is " + e.getStackTrace());
        } finally {
            bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-d", bspzk
                    .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-d", false).getVersion());
        }
        jip.reportLOG(jobId.toString() + "delete the -d");
        try {
            list.clear();
            list = bspzk.getChildren(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-migrate", false);
            for (String e : list) {
                bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-migrate" + "/" + e,
                        bspzk.exists(
                                this.bspZKRoot + "/" + jobId.toString().substring(17) + "-migrate" + "/" + e,
                                false).getVersion());
            }
        } catch (Exception e) {
            LOG.info("The exception is " + e.getStackTrace());
        } finally {
            bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-migrate",
                    bspzk.exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-migrate", false)
                            .getVersion());
        }
        jip.reportLOG(jobId.toString() + "delete the -migrate");
        list.clear();
        list = bspzk.getChildren(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss", false);
        for (String e : list) {
            try {
                tmpList.clear();
                tmpList = bspzk.getChildren(
                        this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss" + "/" + e, false);
                for (String ee : tmpList) {
                    bspzk.delete(
                            this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss" + "/" + e + "/" + ee,
                            bspzk.exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss" + "/" + e
                                    + "/" + ee, false).getAversion());
                }
            } catch (Exception exc) {
                exc.printStackTrace();
            } finally {
                bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss" + "/" + e, bspzk
                        .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss" + "/" + e, false)
                        .getVersion());
            }
        }
        bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss", bspzk
                .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-ss", false).getVersion());
        jip.reportLOG(jobId.toString() + "delete the -ss");
        list.clear();
        list = bspzk.getChildren(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc", false);
        for (String e : list) {
            try {
                tmpList.clear();
                tmpList = bspzk.getChildren(
                        this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc" + "/" + e, false);
                for (String ee : tmpList) {
                    bspzk.delete(
                            this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc" + "/" + e + "/" + ee,
                            bspzk.exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc" + "/" + e
                                    + "/" + ee, false).getAversion());
                }
            } catch (Exception exc) {
                LOG.info("The exception is " + exc.getStackTrace());
            } finally {
                bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc" + "/" + e, bspzk
                        .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc" + "/" + e, false)
                        .getVersion());
            }
        }
        bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc", bspzk
                .exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-sc", false).getVersion());
        jip.reportLOG(jobId.toString() + "delete the -sc");
        list.clear();
        list = bspzk.getChildren(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters", false);
        for (String e : list) {
            try {
                tmpList.clear();
                tmpList = bspzk.getChildren(
                        this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters" + "/" + e, false);
                for (String ee : tmpList) {
                    bspzk.delete(
                            this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters" + "/" + e + "/"
                                    + ee,
                            bspzk.exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters"
                                    + "/" + e + "/" + ee, false).getAversion());
                }
            } catch (Exception exc) {
                LOG.info("The exception is " + exc.getStackTrace());
            } finally {
                bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters" + "/" + e,
                        bspzk.exists(
                                this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters" + "/" + e,
                                false).getVersion());
            }
        }
        bspzk.delete(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters",
                bspzk.exists(this.bspZKRoot + "/" + jobId.toString().substring(17) + "-counters", false)
                        .getVersion());
        jip.reportLOG(jobId.toString() + "delete the -counters");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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

/**
 * {@link jp.furplag.util.commons.NumberUtils#valueOf(java.lang.Object, java.lang.Class, boolean)}.
 */// w ww  . ja v  a2 s.  com
@SuppressWarnings("unchecked")
@Test
public void testValueOfObjectClassOfTBoolean() {
    assertEquals("null", null, valueOf(null, null, false));
    assertEquals("null: fallback", null, valueOf(null, null, true));
    try {
        for (Class<?> type : NUMBERS) {
            Object o = null;
            Object expected = null;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            if (type.isPrimitive())
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            assertEquals("null: " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            } else {
                expected = wrapper.getField("ZERO").get(null);
            }
            assertEquals("null: fallback: " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("null: typeEquals: " + type.getSimpleName(),
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = Float.NaN;
            expected = !type.isPrimitive() ? null
                    : wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class))
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "NaN");
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "NaN");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            } else {
                expected = wrapper.getField("ZERO").get(null);
            }
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals(o + "(" + o.getClass() + "): typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = Double.NaN;
            expected = !type.isPrimitive() ? null
                    : wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class))
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "NaN");
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "NaN");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            } else {
                expected = wrapper.getField("ZERO").get(null);
            }
            assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals(o + "(" + o.getClass() + "): typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "1");
            } else {
                expected = wrapper.getField("ONE").get(null);
            }

            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(), expected,
                        valueOf(o, (Class<? extends Number>) type, false));
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                        valueOf(o, (Class<? extends Number>) type, true));
                assertEquals(o + "(" + o.getClass() + "): typeEquals: " + type,
                        ClassUtils.primitiveToWrapper(expected.getClass()),
                        valueOf(o, (Class<? extends Number>) type, true).getClass());
            }

            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "-123");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance("-123");
            }
            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(), expected,
                        valueOf(o, (Class<? extends Number>) type, false));
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                        valueOf(o, (Class<? extends Number>) type, true));
                assertEquals(o + "(" + o.getClass() + "): typeEquals: " + type,
                        ClassUtils.primitiveToWrapper(expected.getClass()),
                        valueOf(o, (Class<? extends Number>) type, true).getClass());
            }

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "123.456");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "123");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance(BigInteger.class.equals(type) ? "123" : "123.456");
            }
            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(), expected,
                        valueOf(o, (Class<? extends Number>) type, false));
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                        valueOf(o, (Class<? extends Number>) type, true));
                assertEquals(o + "(" + o.getClass() + "): typeEquals: " + type,
                        ClassUtils.primitiveToWrapper(expected.getClass()),
                        valueOf(o, (Class<? extends Number>) type, true).getClass());
            }

            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "-123.456");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "-123");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance(BigInteger.class.equals(type) ? "-123" : "-123.456");
            }
            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(), expected,
                        valueOf(o, (Class<? extends Number>) type, false));
                assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                        valueOf(o, (Class<? extends Number>) type, true));
                assertEquals(o + "(" + o.getClass() + "): typeEquals: " + type,
                        ClassUtils.primitiveToWrapper(expected.getClass()),
                        valueOf(o, (Class<? extends Number>) type, true).getClass());
            }

            o = INFINITY_DOUBLE.pow(2);
            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);
            } else {
                expected = BigInteger.class.equals(type) ? INFINITY_DOUBLE.pow(2).toBigInteger()
                        : INFINITY_DOUBLE.pow(2);
            }
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("Huge: (" + o.getClass() + "): typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = INFINITY_DOUBLE.pow(2).negate();
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("NEGATIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MIN_VALUE").get(null);
            } else {
                expected = BigInteger.class.equals(type) ? INFINITY_DOUBLE.pow(2).toBigInteger().negate()
                        : INFINITY_DOUBLE.pow(2).negate();
            }
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("Huge: (" + o.getClass() + "): typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = INFINITY_DOUBLE.pow(2).toBigInteger();
            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);
            } else {
                expected = BigInteger.class.equals(type) ? INFINITY_DOUBLE.pow(2).toBigInteger()
                        : INFINITY_DOUBLE.pow(2);
            }
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("Huge: (" + o.getClass() + "): typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = INFINITY_DOUBLE.pow(2).toBigInteger().negate();
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("NEGATIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MIN_VALUE").get(null);
            } else {
                expected = BigInteger.class.equals(type) ? INFINITY_DOUBLE.pow(2).toBigInteger().negate()
                        : INFINITY_DOUBLE.pow(2).negate();
            }
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("Huge: (" + o.getClass() + "): typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = "";
            expected = !type.isPrimitive() ? null
                    : wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "0");
            } else {
                expected = wrapper.getField("ZERO").get(null);
            }
            assertEquals("\"" + o + "\": fallback: " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("\"" + o + "\": typeEquals: " + type.getSimpleName(),
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

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

            o = "-123456E-3";
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "-123.456");
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "-123");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance(BigInteger.class.equals(type) ? "-123" : "-123.456");
            }
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("\"" + o + "\": typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = "Infinity";
            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);
            } else {
                expected = BigInteger.class.equals(type) ? INFINITY_DOUBLE.toBigInteger() : INFINITY_DOUBLE;
            }
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("\"" + o + "\": typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());

            o = "-Infinity";
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("NEGATIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MIN_VALUE").get(null);
            } else {
                expected = BigInteger.class.equals(type) ? INFINITY_DOUBLE.toBigInteger().negate()
                        : INFINITY_DOUBLE.negate();
            }
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, false));
            assertEquals("\"" + o + "\": " + type.getSimpleName(), expected,
                    valueOf(o, (Class<? extends Number>) type, true));
            assertEquals("\"" + o + "\": typeEquals: " + type,
                    ClassUtils.primitiveToWrapper(expected.getClass()),
                    valueOf(o, (Class<? extends Number>) type, true).getClass());
        }
    } 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.NumberObject}
 *//*from  ww w.  jav  a  2 s .  c  o m*/
@SuppressWarnings("unchecked")
@Test
public void NumberObjectTest() {
    try {
        Class<?> numberObject = ClassLoader.getSystemClassLoader()
                .loadClass(NumberUtils.class.getName() + "$NumberObject");

        Constructor<?> c = numberObject.getDeclaredConstructor(Class.class);
        c.setAccessible(true);

        Method ofType = numberObject.getMethod("of", Class.class);
        ofType.setAccessible(true);

        Method ofN = numberObject.getMethod("of", Number.class);
        ofN.setAccessible(true);

        Method parsable = numberObject.getDeclaredMethod("parsable", Number.class);
        parsable.setAccessible(true);

        Method contains = numberObject.getDeclaredMethod("contains", Number.class);
        contains.setAccessible(true);

        Method valueOf = numberObject.getDeclaredMethod("valueOf", Number.class);
        valueOf.setAccessible(true);

        for (Class<?> type : NUMBERS) {
            Object o = c.newInstance(type);
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            Object numob = ofType.invoke(null, type);
            assertEquals("ofType: " + type.getSimpleName(), o, numob);
            Number n = null;
            if (!type.isPrimitive()) {
                if (ClassUtils.isPrimitiveWrapper(type)) {
                    n = (Number) ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class)
                            .invoke(null, "1");
                } else {
                    n = (Number) type.getField("ONE").get(null);
                }
                if (type.equals(byte.class))
                    assertEquals("ofN: 1: " + type.getSimpleName(), o, ofN.invoke(null, n));
            }
            assertEquals("parsable: -1: " + type.getSimpleName(), true, parsable.invoke(numob, -1));
            assertEquals("parsable: 0: " + type.getSimpleName(), true, parsable.invoke(numob, 0));
            assertEquals("parsable: 1: " + type.getSimpleName(), true, parsable.invoke(numob, 1));

            assertEquals("parsable: null: " + type.getSimpleName(), !type.isPrimitive(),
                    parsable.invoke(numob, (Number) null));

            Object expected = ObjectUtils.isAny(wrapper, Float.class, Double.class, BigDecimal.class,
                    BigInteger.class);
            assertEquals("parsable: Infinity: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.POSITIVE_INFINITY));
            assertEquals("parsable: Infinity: Double: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE));
            assertEquals("parsable: Infinity: Double: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.toBigInteger()));
            assertEquals("parsable: Infinity: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.POSITIVE_INFINITY));
            assertEquals("parsable: Infinity: Float: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT));
            assertEquals("parsable: Infinity: Float: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.toBigInteger()));
            assertEquals("parsable: -Infinity: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.NEGATIVE_INFINITY));
            assertEquals("parsable: -Infinity: Double: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.negate()));
            assertEquals("parsable: -Infinity: Double: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.negate().toBigInteger()));
            assertEquals("parsable: -Infinity: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.NEGATIVE_INFINITY));
            assertEquals("parsable: -Infinity: Float: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.negate()));
            assertEquals("parsable: -Infinity: Float: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.negate().toBigInteger()));

            expected = ObjectUtils.isAny(wrapper, Float.class, Double.class);
            assertEquals("parsable: NaN: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.NaN));
            assertEquals("parsable: NaN: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.NaN));

            if (Byte.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getByte(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getByte(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Short.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Short.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getByte(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getByte(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Short.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Short.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123.456f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 1234.56f));
            }
            if (Short.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getShort(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getShort(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Integer.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Integer.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getShort(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getShort(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Integer.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Integer.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 12345.6f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 123456.789f));
            }
            if (Integer.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getInt(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getInt(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Long.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Long.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123456.789f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getInt(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getInt(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Long.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Long.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123456.789f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 12345678912345678912.3456d));
            }
            if (Long.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getLong(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getLong(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, BigInteger.valueOf(Long.MIN_VALUE).pow(2)));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, BigInteger.valueOf(Long.MAX_VALUE).pow(2)));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getLong(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getLong(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, BigInteger.valueOf(Long.MIN_VALUE).pow(2)));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, BigInteger.valueOf(Long.MAX_VALUE).pow(2)));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123456.789f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 12345678912345678912.3456f));
            }
            if (Float.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, -wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, -Double.MAX_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Double.MAX_VALUE));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, -wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, -Double.MAX_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Double.MAX_VALUE));
            }
            if (Double.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, -wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN).negate()));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN)));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, -wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN).negate()));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN)));
            }
            if (!ClassUtils.isPrimitiveWrapper(wrapper)) {
                assertEquals("parsable: fraction: " + type.getSimpleName(), BigDecimal.class.equals(type),
                        parsable.invoke(numob, 123.456f));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123.456f));
            }

            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "123");
            } else {
                expected = new BigDecimal("123");
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            for (Class<?> valueType : OBJECTS) {
                if (ClassUtils.isPrimitiveWrapper(valueType)) {
                    n = (Number) valueType.getMethod("valueOf", String.class).invoke(null, "123");
                } else {
                    n = new BigDecimal("123");
                    if (BigInteger.class.equals(valueType))
                        n = ((BigDecimal) n).toBigInteger();
                }
                assertEquals(
                        "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                        expected, valueOf.invoke(numob, n));
                assertEquals(
                        "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: "
                                + type.getSimpleName(),
                        expected.getClass(), valueOf.invoke(numob, n).getClass());
            }

            n = 123.456f;
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, n.toString());
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null,
                        Integer.toString(((Float) n).intValue()));
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    expected, valueOf.invoke(numob, n));
            assertEquals(
                    "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: " + type.getSimpleName(),
                    expected.getClass(), valueOf.invoke(numob, n).getClass());

            n = 1.23456789E-6d;
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, n.toString());
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null,
                        Integer.toString(((Double) n).intValue()));
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    expected, valueOf.invoke(numob, n));
            assertEquals(
                    "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: " + type.getSimpleName(),
                    expected.getClass(), valueOf.invoke(numob, n).getClass());

            n = INFINITY_DOUBLE.pow(2);
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MAX_VALUE").get(null);
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: Huge: " + type.getSimpleName(), expected, valueOf.invoke(numob, n));
            assertEquals("valueOf: Huge: class: " + type.getSimpleName(), expected.getClass(),
                    valueOf.invoke(numob, n).getClass());

            n = INFINITY_DOUBLE.pow(2).negate();
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getField("NEGATIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MIN_VALUE").get(null);
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: Huge: negative: " + type.getSimpleName(), expected,
                    valueOf.invoke(numob, n));
            assertEquals("valueOf: Huge: negative: class: " + type.getSimpleName(), expected.getClass(),
                    valueOf.invoke(numob, n).getClass());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void createModeSwitcher() {
    LayoutInflater inflator = ApplicationScreen.instance.getLayoutInflater();
    modeSwitcher = (com.almalence.ui.Switch.Switch) inflator
            .inflate(R.layout.plugin_capture_standard_modeswitcher, null, false);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    ModePreference = prefs.getString("modeVideoDROPref", "1");
    modeSwitcher.setTextOn(ApplicationScreen.instance.getString(R.string.Pref_Video_DRO_ON));
    modeSwitcher.setTextOff(ApplicationScreen.instance.getString(R.string.Pref_Video_DRO_OFF));
    modeSwitcher.setChecked(ModePreference.compareTo("0") == 0 ? true : false);
    modeSwitcher.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*from   ww  w .  j av a2 s  .com*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(ApplicationScreen.getMainContext());

            if (isChecked) {
                ModePreference = "0";
                if (CameraController.isNexus6) {
                    Toast.makeText(ApplicationScreen.getMainContext(),
                            "Not suported currently on your device. Will be available later.",
                            Toast.LENGTH_LONG).show();
                    ModePreference = "1";
                    modeSwitcher.setChecked(false);
                    return;
                }
            } else {
                ModePreference = "1";
            }

            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("modeVideoDROPref", ModePreference);
            editor.commit();

            if (modeDRO()) {
                int quality = Integer.parseInt(prefs.getString(
                        CameraController.getCameraIndex() == 0 ? ApplicationScreen.sImageSizeVideoBackPref
                                : ApplicationScreen.sImageSizeVideoFrontPref,
                        DEFAULT_VIDEO_QUALITY));
                if (quality > CamcorderProfile.QUALITY_720P || maxQuality()) {
                    quality = CamcorderProfile.QUALITY_720P;
                    quickControlIconID = R.drawable.gui_almalence_video_720;
                    editor.putString(
                            CameraController.getCameraIndex() == 0 ? ApplicationScreen.sImageSizeVideoBackPref
                                    : ApplicationScreen.sImageSizeVideoFrontPref,
                            String.valueOf(quality));
                    editor.commit();
                    VideoCapturePlugin.this.refreshQuickControl();
                }
            }

            try {
                CameraController.stopCameraPreview();
                setCameraPreviewSize();
                if (VideoCapturePlugin.this.modeDRO()) {
                    takePictureButton.setVisibility(View.GONE);
                    timeLapseButton.setVisibility(View.GONE);
                    ApplicationScreen.instance.showOpenGLLayer(2);
                    ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
                } else {
                    if (!CameraController.isRemoteCamera()) {
                        if (displayTakePicture)
                            takePictureButton.setVisibility(View.VISIBLE);
                        timeLapseButton.setVisibility(View.VISIBLE);
                    }

                    droEngine.onPause();
                    ApplicationScreen.instance.hideOpenGLLayer();
                    if (!CameraController.isUseCamera2()) {
                        CameraController.setupCamera(ApplicationScreen.getPreviewSurfaceHolder(), true);
                    }
                    CameraController.startCameraPreview();
                }
            } catch (final Exception e) {
                Log.e(TAG, Util.toString(e.getStackTrace(), '\n'));
                e.printStackTrace();
            }
        }
    });

}

From source file:net.naijatek.myalumni.modules.members.presentation.action.MaintainMemberAction.java

public ActionForward addMember(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ActionMessages errors = new ActionMessages();
    SystemConfigVO sysConfigVO = sysConfigSerivce.getSystemConfig();

    try {/*from   ww w .j a  va 2 s  . c  om*/
        MemberForm memberForm = (MemberForm) form;
        MemberVO memberVO = new MemberVO();
        BeanUtils.copyProperties(memberVO, memberForm);

        memberVO.setLastModifiedBy(memberVO.getMemberUserName());

        // Member
        memService.createMember(memberVO, request);
        ////////
        final String memberId = memberVO.getMemberId();
        // Messengers
        List<MessengerVO> messengers = new ArrayList<MessengerVO>();
        MessengerVO mesgerVO = null;
        for (String str : memberVO.getLstSelectedIMs()) {
            mesgerVO = new MessengerVO();
            mesgerVO.setLastModifiedBy(memberVO.getMemberUserName());
            mesgerVO.setMemberId(memberId);
            mesgerVO.setLookupCodeId(str);
            messengers.add(mesgerVO);
        }
        messengerService.saveAll(messengers, memberId);

        // Message Folders
        mfService.createMemberMessageFolders(memberId, SystemConfigConstants.MESSAGE_FOLDERS,
                memberVO.getMemberUserName());

        StringBuffer message = new StringBuffer();
        message.append("Thank you " + StringUtil.capitalize(memberVO.getFirstName()) + " "
                + StringUtil.capitalize(memberVO.getLastName()) + " for registering and Welcome to "
                + sysConfigVO.getOrganizationName() + "'s owns space in cyberspace.");
        message.append(
                "Your account should be active within the next 24 hours. So please try logging into the system as soon as you get your activation confirmation email.");
        setSessionObject(request, BaseConstants.MESSAGE, message.toString());

        // send email to registrant
        try {
            SendMailUtil.sendWelcomeNotice(memberVO.getEmail(), memberVO.getMemberUserName(), sysConfigVO);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            errors.add(BaseConstants.FATAL_KEY, new ActionMessage("error.mailserver"));
            saveMessages(request, errors);
            return mapping.findForward(BaseConstants.FWD_SUCCESS);
        }

        // send email to administrator about new registrant
        try {
            SendMailUtil.notifyAdminAboutNewMember(memberVO, sysConfigVO);
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            errors.add(BaseConstants.FATAL_KEY, new ActionMessage("error.mailserver"));
            saveMessages(request, errors);
            return mapping.findForward(BaseConstants.FWD_SUCCESS);
        }

    } catch (DuplicateMemberException e) {
        errors.add(BaseConstants.WARN_KEY, new ActionMessage("error.duplicate.member"));
        saveMessages(request, errors);
        logger.info("DUPLICATE USER NAME - " + e.getMessage());
        return mapping.getInputForward();
    } catch (DuplicateEmailException e) {
        errors.add(BaseConstants.WARN_KEY, new ActionMessage("error.duplicate.email"));
        saveMessages(request, errors);
        logger.info("DUPLICATE EMAIL - " + e.getMessage());
        return mapping.getInputForward();
    } catch (CreateException e) {
        errors.add(BaseConstants.WARN_KEY, new ActionMessage("errors.technical.difficulty"));
        saveMessages(request, errors);
        logger.fatal("SYSTEM ERROR - " + e.getMessage());
        return mapping.getInputForward();
    } catch (Exception ex) {
        errors.add(BaseConstants.FATAL_KEY, new ActionMessage("errors.technical.difficulty"));
        saveMessages(request, errors);
        logger.fatal("SYSTEM ERROR - " + ex.getStackTrace());
        return mapping.getInputForward();
    }
    return mapping.findForward(BaseConstants.FWD_SUCCESS);
}

From source file:base.BasePlayer.BedTable.java

void drawScreen(Graphics g) {
    try {/*from   w  ww  . j a v  a  2  s. c om*/
        buf.setColor(Color.black);

        buf.fillRect(0, 0, this.getWidth(), this.getHeight());
        if (width != this.getWidth()) {
            width = this.getWidth();
            createPolygon();
            resizeTable();
        }

        genemutcount = 0;
        if (!bedtrack.intersect) {
            buf.setColor(Color.white);
            buf.drawString("Press play on bed track to annotate variants", 5, 40);
        } else if (getTableSize() > 0) {

            hoverVar = null;
            hoverSample = -1;
            headerHover = -1;
            geneHeaderHover = -1;
            if (!mouseDrag) {
                resizeColumn = -1;
            }

            if (aminoarray == null) {
                aminoarray = new ArrayList<AminoEntry>();
            }

            firstrow = tablescroll.getVerticalScrollBar().getValue() / rowHeight - samplecount - listAdd
                    - aminoarray.size();

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

                if ((i + 1 + samplecount + listAdd + aminoarray.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 = bedarray.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);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {
                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }

                    if (bedarray.get(i).getTrack().hasvalues) {
                        buf.drawString(
                                (i + 1) + ".  " + MethodLibrary.shortString(bedarray.get(i).name, 10) + "="
                                        + MethodLibrary.round(bedarray.get(i).value, 3),
                                5, (rowHeight * (i + 1 + genemutcount))
                                        - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    } else {
                        buf.drawString((i + 1) + ".  " + MethodLibrary.shortString(bedarray.get(i).name, 10), 5,
                                (rowHeight * (i + 1 + genemutcount))
                                        - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                    }
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[1][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            headerlengths[1][1], rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {
                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }
                    mutcountbuffer = new StringBuffer("" + bedarray.get(i).mutations + " ");
                    buf.drawString(mutcountbuffer.toString(), headerlengths[1][0] + 5,
                            (rowHeight * (i + 1 + genemutcount)) - tablescroll.getVerticalScrollBar().getValue()
                                    + rowHeight);
                    //      lastpos = Integer.toString(bedarray.get(i).mutations).length() +2;
                    //TODO      textWidth = (int)fm.getStringBounds("", buf).getWidth();

                    //   textWidth = (int)fm.getStringBounds(mutcountbuffer.toString(), buf).getWidth();
                    //   buf.drawString("  ", headerlengths[1][0]+5+textWidth, (rowHeight*(i+1+genemutcount))-tablescroll.getVerticalScrollBar().getValue()+rowHeight);      

                    //   buf.setColor(Color.gray);
                    //   textWidth = (int)fm.getStringBounds(mutcountbuffer.toString() , buf).getWidth();
                    //   buf.drawString(" " +bedarray.get(i).varnodes.size() +" samples",  headerlengths[1][0]+5+textWidth, (rowHeight*(i+1+genemutcount))-tablescroll.getVerticalScrollBar().getValue()+rowHeight);      

                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[2][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {
                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }

                    buf.drawString(
                            bedarray.get(i).getChrom() + ":"
                                    + MethodLibrary.formatNumber(bedarray.get(i).getPosition() + 1) + "-"
                                    + MethodLibrary.formatNumber(
                                            bedarray.get(i).getPosition() + 1 + bedarray.get(i).getLength()),
                            headerlengths[2][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                    - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[3][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {

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

                    buf.drawString(MethodLibrary.formatNumber(bedarray.get(i).getLength()),
                            headerlengths[3][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                    - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[4][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {

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

                    buf.drawString("" + MethodLibrary
                            .round((bedarray.get(i).mutations / (double) bedarray.get(i).getLength()) * 100, 4),
                            headerlengths[4][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                    - tablescroll.getVerticalScrollBar().getValue() + rowHeight);
                    buf.setColor(Color.black);
                    buf.fillRect(
                            headerlengths[5][0] + 1, (rowHeight * (i + genemutcount + 1))
                                    - tablescroll.getVerticalScrollBar().getValue() + 4,
                            this.getWidth(), rowHeight - 1);

                    if (bedarray.get(i).equals(hoverNode) || bedarray.get(i).equals(selectedNode)) {

                        buf.setColor(Color.yellow);
                    } else {
                        buf.setColor(Color.white);
                    }
                    firstvisible = 0;
                    if (bedarray.get(i).varnodes != null) {

                        for (int f = 0; f < bedarray.get(i).varnodes.size(); f++) {
                            if (!Main.drawCanvas.hideNode(bedarray.get(i).varnodes.get(f))) {
                                firstvisible = f;
                                break;
                            }
                        }
                        if (bedarray.get(i).varnodes.get(firstvisible).getExons() != null) {

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

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

                            }
                        } else if (bedarray.get(i).varnodes.get(firstvisible).isInGene()) {

                            buf.setColor(Color.lightGray);
                            buf.drawString(
                                    bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                            .getGenename() + " (Intronic)",
                                    headerlengths[5][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                            - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

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

                            if (!bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0).equals(
                                    bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(1))) {

                                buf.drawString(
                                        bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                                .getGenename()
                                                + " ... "
                                                + bedarray.get(i).varnodes.get(firstvisible).getTranscripts()
                                                        .get(1).getGenename(),
                                        headerlengths[5][0] + 5, (rowHeight * (i + 1 + genemutcount))
                                                - tablescroll.getVerticalScrollBar().getValue() + rowHeight);

                            } else {
                                if (bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                        .getEnd() > bedarray.get(i).varnodes.get(firstvisible).getPosition()) {

                                    buf.drawString(
                                            " ... " + bedarray.get(i).varnodes.get(firstvisible)
                                                    .getTranscripts().get(0).getGenename(),
                                            headerlengths[5][0] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);
                                } else {
                                    buf.drawString(
                                            bedarray.get(i).varnodes.get(firstvisible).getTranscripts().get(0)
                                                    .getGenename() + " ... ",
                                            headerlengths[5][0] + 5,
                                            (rowHeight * (i + 1 + genemutcount))
                                                    - tablescroll.getVerticalScrollBar().getValue()
                                                    + rowHeight);

                                }
                            }
                        }
                    }

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

                    for (int r = 0; r < headerlengths.length; r++) {
                        buf.drawLine(headerlengths[r][0],
                                (rowHeight * (i + genemutcount + 1))
                                        - tablescroll.getVerticalScrollBar().getValue() + 4,
                                headerlengths[r][0], (rowHeight * (i + genemutcount + 2))
                                        - tablescroll.getVerticalScrollBar().getValue() + 3);
                    }

                    if (selectedNode != null && selectedNode.equals(bedarray.get(i))) {

                        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++) {

                                    StringBuffer[] bedarraytemp = MethodLibrary.makeTrackArray(
                                            aminoarray.get(a).getNode(), aminoarray.get(a).getRow()[5]);
                                    if (bedarraytemp != null) {
                                        int h = 0;
                                        for (int b = 0; b < bedarraytemp.length; b++) {
                                            if (b == bedtrack.trackIndex) {
                                                continue;
                                            }
                                            buf.setColor(Color.black);
                                            if (b == bedarraytemp.length - 1) {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        this.getWidth() - (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1],
                                                        rowHeight - 1);
                                            } else {
                                                buf.fillRect(
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1] + 12,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + 4,
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[2],
                                                        rowHeight - 1);
                                            }
                                            buf.setColor(Color.white);
                                            if (bedarraytemp[b] != null) {
                                                buf.drawString(bedarraytemp[b].toString(),
                                                        (int) geneheader.get(geneheaderlength
                                                                + Control.controlData.fileArray.size() * 2
                                                                + h)[1] + 14,
                                                        (rowHeight * (i + a + listAdd + 2))
                                                                - tablescroll.getVerticalScrollBar().getValue()
                                                                + rowHeight);

                                            }
                                            h++;

                                            //   buf.drawLine((int)geneheader.get(geneheaderlength+Control.controlData.fileArray.size()*2+h)[1], (rowHeight*(i+a+listAdd+2))-tablescroll.getVerticalScrollBar().getValue()+4, (int)geneheader.get(geneheaderlength+Control.controlData.fileArray.size()*2+h)[1], (rowHeight*(i+a+listAdd+2))-tablescroll.getVerticalScrollBar().getValue()+10);   

                                        }
                                    }
                                }
                            }

                            buf.setColor(Color.darkGray);
                            for (int j = 0; j < geneheader.size(); j++) {
                                buf.drawLine((int) geneheader.get(j)[1] + 11,
                                        (rowHeight * (i + 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 * (bedarray.size() + genemutcount + 1))
                            - tablescroll.getVerticalScrollBar().getValue() + 3,
                    this.getWidth(), (rowHeight * (bedarray.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();
    }
}

From source file:ome.services.blitz.fire.SessionManagerI.java

public Glacier2.SessionPrx create(String userId, Glacier2.SessionControlPrx control, Ice.Current current)
        throws CannotCreateSessionException {

    if (!loaded.get()) {
        WrappedCreateSessionException wrapped = new WrappedCreateSessionException();
        wrapped.backOff = 1000L;//w ww.j a va  2  s.c o m
        wrapped.concurrency = true;
        wrapped.reason = "Server not fully initialized";
        wrapped.type = "ApiUsageException";
        throw wrapped;
    }

    try {

        // First thing we do is guarantee that the client is giving us
        // the required information.
        ServiceFactoryI.clientId(current); // throws ApiUsageException

        // Before asking the ring, see if we already have the
        // session locally.
        boolean local = false;
        try {
            Object o = sessionManager.find(userId);
            local = (o != null);
            log.info("Found session locally: " + userId);
        } catch (Exception e) {
            log.debug("Exception while waiting on " + "SessionManager.find " + e);
        }

        // If not, then give the ring a chance to redirect to
        // other instances which may already have it.
        if (!local) {
            Glacier2.SessionPrx sf = ring.getProxyOrNull(userId, control, current);
            if (sf != null) {
                return sf; // EARLY EXIT
            }
        }

        // Defaults
        Roles roles = securitySystem.getSecurityRoles();

        String group = getGroup(current);
        if (group == null) {
            group = roles.getUserGroupName();
        }
        String event = getEvent(current);
        if (event == null) {
            event = "User"; // FIXME This should be in Roles as well.
        }
        String agent = getAgent(current);

        // Create the session for this ServiceFactory
        Principal p = new Principal(userId, group, event);
        ome.model.meta.Session s = sessionManager.createWithAgent(p, agent);
        Principal sp = new Principal(s.getUuid(), group, event);
        // Event raised to add to Ring

        // Create the ServiceFactory
        ServiceFactoryI session = new ServiceFactoryI(local /* ticket:911 */, current, control, context,
                sessionManager, executor, sp, CPTORS, topicManager, registry);

        Ice.Identity id = session.sessionId();

        if (control != null) {
            // Not having a control implies that this is an internal
            // call, not coming through Glacier, so we can trust it.
            StringSetPrx cat = control.categories();
            cat.add(new String[] { id.category });
            cat.add(new String[] { id.name });
        }

        Ice.ObjectPrx _prx = current.adapter.add(session, id); // OK Usage
        _prx = current.adapter.createDirectProxy(id);

        // Logging & sessionToClientIds addition
        if (!sessionToClientIds.containsKey(s.getUuid())) {
            sessionToClientIds.put(s.getUuid(), new HashSet<String>());
            log.info(String.format("Created session %s for user %s (agent=%s)", session, userId, agent));
        } else {
            if (log.isInfoEnabled()) {
                log.info(String.format("Rejoining session %s (agent=%s)", session, agent));
            }
        }
        sessionToClientIds.get(s.getUuid()).add(session.clientId);
        return Glacier2.SessionPrxHelper.uncheckedCast(_prx);

    } catch (Exception t) {

        // Then we are good to go.
        if (t instanceof CannotCreateSessionException) {
            throw (CannotCreateSessionException) t;
        }

        // These need special handling as well.
        else if (t instanceof ome.conditions.ConcurrencyException || t instanceof omero.ConcurrencyException) {

            // Parse out the back off, then everything is generic.
            long backOff = (t instanceof omero.ConcurrencyException) ? ((omero.ConcurrencyException) t).backOff
                    : ((ome.conditions.ConcurrencyException) t).backOff;

            WrappedCreateSessionException wrapped = new WrappedCreateSessionException();
            wrapped.backOff = backOff;
            wrapped.type = t.getClass().getName();
            wrapped.concurrency = true;
            wrapped.reason = "ConcurrencyException: " + t.getMessage() + "\nPlease retry in " + backOff
                    + "ms. Cause: " + t.getMessage();
            throw wrapped;

        }

        ConvertToBlitzExceptionMessage convert = new ConvertToBlitzExceptionMessage(this, t);
        try {
            // TODO Possibly provide context.convert(ConversionMsg) methd.
            context.publishMessage(convert);
        } catch (Throwable t2) {
            log.error("Error while converting exception:", t2);
        }

        if (convert.to instanceof CannotCreateSessionException) {
            throw (CannotCreateSessionException) convert.to;
        }

        // We make an exception for some more or less "expected" exception
        // types. Everything else gets logged as an error which we need
        // to review.
        if (!(t instanceof omero.ApiUsageException || t instanceof ome.conditions.ApiUsageException
                || t instanceof ome.conditions.SecurityViolation)) {
            log.error("Error while creating ServiceFactoryI", t);
        }

        WrappedCreateSessionException wrapped = new WrappedCreateSessionException();
        wrapped.backOff = -1;
        wrapped.concurrency = false;
        wrapped.reason = t.getMessage();
        wrapped.type = t.getClass().getName();
        wrapped.setStackTrace(t.getStackTrace());
        throw wrapped;
    }
}

From source file:au.org.theark.study.model.dao.StudyDao.java

public void update(Consent consent) throws ArkSystemException, EntityNotFoundException {
    try {/*w ww  .ja  v  a2s  .  com*/
        Session session = getSession();
        session.merge(consent);
    } catch (HibernateException someHibernateException) {
        log.error("An Exception occured while trying to update this consent "
                + someHibernateException.getStackTrace());
    } catch (Exception e) {
        log.error("An Exception occured while trying to update this consent " + e.getStackTrace());
        throw new ArkSystemException(
                "A System Error has occured. We wil have someone contact you regarding this issue");
    }

}