Example usage for java.text NumberFormat getNumberInstance

List of usage examples for java.text NumberFormat getNumberInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getNumberInstance.

Prototype

public static NumberFormat getNumberInstance(Locale inLocale) 

Source Link

Document

Returns a general-purpose number format for the specified locale.

Usage

From source file:org.sakaiproject.tool.assessment.services.GradingService.java

/**
 * Validate a students numeric answer // w  w  w.j  av a  2 s.c o  m
 * @param The answer to validate
 * @return a Map containing either Real or Complex answer keyed by {@link #ANSWER_TYPE_REAL} or {@link #ANSWER_TYPE_COMPLEX} 
 */
public Map validate(String value) {
    HashMap map = new HashMap();
    if (value == null || value.trim().equals("")) {
        return map;
    }
    String trimmedValue = value.trim();
    boolean isComplex = true;
    boolean isRealNumber = true;

    BigDecimal studentAnswerReal = null;
    try {
        studentAnswerReal = new BigDecimal(trimmedValue);
    } catch (Exception e) {
        isRealNumber = false;
    }

    // Test for complex number only if it is not a BigDecimal
    Complex studentAnswerComplex = null;
    if (!isRealNumber) {
        try {
            DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
            df.setGroupingUsed(false);

            // Numerical format ###.## (decimal symbol is the point)
            ComplexFormat complexFormat = new ComplexFormat(df);
            studentAnswerComplex = complexFormat.parse(trimmedValue);

            // This is because there is a bug parsing complex number. 9i is parsed as 9
            if (studentAnswerComplex.getImaginary() == 0 && trimmedValue.contains("i")) {
                isComplex = false;
            }
        } catch (Exception e) {
            isComplex = false;
        }
    }

    Boolean isValid = isComplex || isRealNumber;
    if (!isValid) {
        throw new FinFormatException("Not a valid FIN Input. studentanswer=" + trimmedValue);
    }

    if (isRealNumber) {
        map.put(ANSWER_TYPE_REAL, studentAnswerReal);
    } else if (isComplex) {
        map.put(ANSWER_TYPE_COMPLEX, studentAnswerComplex);
    }

    return map;
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 * For a given axis, adjust the tick unit size, in order to 
 * have a customizable number of ticks on that axis
 *///from www.  j a va  2s.c om
protected void calculateTickUnits(Axis axis, boolean isRangeAxis) {
    Integer tickCount = null;
    Number tickInterval = null;
    boolean axisIntegerUnit = false;

    if (getChart().hasProperties()) {
        String tickCountProperty = null;
        String tickIntervalProperty = null;
        String axisIntegerUnitProperty = null;

        if (isRangeAxis) {
            tickCountProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT);
            tickIntervalProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL);
            axisIntegerUnitProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_INTEGER_UNIT);
        } else {
            tickCountProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT);
            tickIntervalProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL);
            axisIntegerUnitProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_INTEGER_UNIT);
        }
        if (tickCountProperty != null && tickCountProperty.trim().length() > 0) {
            tickCount = Integer.valueOf(tickCountProperty);
        }
        if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) {
            tickInterval = Double.valueOf(tickIntervalProperty);
        }
        if (axisIntegerUnitProperty != null && axisIntegerUnitProperty.trim().length() > 0) {
            axisIntegerUnit = Boolean.valueOf(axisIntegerUnitProperty);
        }
    }

    if (axis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) axis;
        int axisRange = (int) numberAxis.getRange().getLength();

        if (axisIntegerUnit) {
            ChartUtil chartUtil = ChartUtil.getInstance(chartContext.getJasperReportsContext());
            numberAxis.setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale()));
            chartUtil.setAutoTickUnit(numberAxis);
        } else if (axisRange > 0) {
            if (tickInterval != null) {
                if (numberAxis.getNumberFormatOverride() != null) {
                    numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(),
                            numberAxis.getNumberFormatOverride()));
                } else {
                    numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(),
                            NumberFormat.getNumberInstance(getLocale())));
                }
            } else if (tickCount != null) {
                if (numberAxis.getNumberFormatOverride() != null) {
                    numberAxis.setTickUnit(
                            new NumberTickUnit(axisRange / tickCount, numberAxis.getNumberFormatOverride()));
                } else {
                    numberAxis.setTickUnit(new NumberTickUnit(axisRange / tickCount,
                            NumberFormat.getNumberInstance(getLocale())));
                }
            } else {
                ChartUtil chartUtil = ChartUtil.getInstance(chartContext.getJasperReportsContext());
                numberAxis.setStandardTickUnits(chartUtil.createStandardTickUnits(getLocale()));
                chartUtil.setAutoTickUnit(numberAxis);
            }
        }
    }
    //      else if (axis instanceof DateAxis)
    //      {
    //         DateAxis dateAxis = (DateAxis)axis;
    //         int axisRange = (int)dateAxis.getRange().getLength();
    //         if (dateAxis.getDateFormatOverride() != null)
    //         {
    //            dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount, dateAxis.getDateFormatOverride()));
    //         }
    //         else
    //         {
    //            dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount));
    //         }
    //      }
}

From source file:de.innovationgate.wga.server.api.WGA.java

/**
 * Returns an OpenWGA number format//from   w ww  . j  a  v  a 2 s  .c  o m
 * @param pattern The number format pattern
 * @param locale A locale to use for locale-dependent number parts. Specify null to let the current WebTML context choose the locale.
 * @throws WGException
 */
public NumberFormat getNumberFormat(String pattern, Locale locale) throws WGException {

    // Select language for language dependent number formats
    if (locale == null) {
        locale = chooseLocale(locale);
    }

    if (WGUtils.isEmpty(pattern)) {
        NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
        numberFormat.setMaximumFractionDigits(Integer.MAX_VALUE);
        numberFormat.setMaximumIntegerDigits(Integer.MAX_VALUE);
        return numberFormat;
    }

    // For default pattern
    if (pattern.toLowerCase().equals("decimal")) {
        return NumberFormat.getNumberInstance(locale);
    }

    // Custom pattern
    return new DecimalFormat(pattern, new DecimalFormatSymbols(locale));

}

From source file:com.MainFiles.Functions.java

public String genHashDelimiterString(Map<String, String> hashDelimiterdetails, String intid)
        throws IOException, SQLException {

    NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("en", "tz"));
    String hashDelimiterString = "";
    String agentTeller;//  w  w w. j av a  2 s  .c om
    String strMessage;
    String strMessage1;
    String strReasonDescription;
    String strAvailableBalance = "";
    String strActualBalance = "";
    String cardlesssmsmsg;
    String strCustomername = "";
    String[] strBalance = null;
    String[] dataArray;
    String strAccountNo = "";
    String strStatementPrinting = "";
    String Status = "";
    String Amount = "";
    String Currency = "";
    String CustomerName = "";
    String response = "";
    String invoiceNo = "";

    if (hashDelimiterdetails.get("39").equals("00")) {
        hashDelimiterString += CustomerCopy();
    } else {
        hashDelimiterString += AgentCopy();
    }

    hashDelimiterString += this.strResponseHeader(hashDelimiterdetails.get("68"));
    hashDelimiterString += "AGENT ID:  " + hashDelimiterdetails.get("104") + "#";

    //Get Processing Code
    switch (hashDelimiterdetails.get("3")) {

    case "010000":
        //Cash Withdrawal
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            if (hashDelimiterdetails.get("48").equals("SUCCESS")) {
                try {
                    strAccountNo = hashDelimiterdetails.get("102").toString();
                    String amountString = formatter.format(Double.valueOf(hashDelimiterdetails.get("4")))
                            .replace("TZS", "");

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "         CASH WITHDRAWAL        " + "#";
                    hashDelimiterString += "    CASH WITHDRAWAL SUCCESSFUL  " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "ACCOUNT NUM:  " + strAccountNo + "#";
                    hashDelimiterString += "AMOUNT:   TZS " + amountString + "#";
                    hashDelimiterString += "                                " + "#";

                } catch (Exception ex) {
                    this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                            + this.StackTraceWriter(ex), "ERROR");
                }

            } else {
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "         CASH WITHDRAWAL        " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "     CASH WITHDRAWAL FAILED    " + "#";
                hashDelimiterString += " "
                        + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
                hashDelimiterString += "                                " + "#";
            }
            break;
        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "         CASH WITHDRAWAL        " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "     CASH WITHDRAWAL FAILED    " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";
            break;
        }

        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        if (hashDelimiterdetails.get("39").equals("00")) {
            String strReplace = hashDelimiterString.replace("CUSTOMER COPY", "AGENT COPY");
            hashDelimiterString += strReplace;
        }
        this.SendPOSResponse(hashDelimiterString, intid);

        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "120000":
        //Merchant Payments

        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            if (hashDelimiterdetails.get("48").equals("SUCCESS")) {
                try {
                    strAccountNo = hashDelimiterdetails.get("102").toString();
                    String amountString = formatter.format(Double.valueOf(hashDelimiterdetails.get("4")))
                            .replace("TZS", "");

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "         MERCHANT PAYMENT        " + "#";
                    hashDelimiterString += "    MERCHANT PAYMENT SUCCESSFUL  " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "ACCOUNT NUM:  " + strAccountNo + "#";
                    hashDelimiterString += "AMOUNT:   TZS " + amountString + "#";
                    hashDelimiterString += "                                " + "#";

                } catch (Exception ex) {
                    this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                            + this.StackTraceWriter(ex), "ERROR");
                }

            } else {
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "        MERCHANT PAYMENT        " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "     MERCHANT PAYMENT FAILED    " + "#";
                hashDelimiterString += " "
                        + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
                hashDelimiterString += "                                " + "#";

            }
            break;
        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "        MERCHANT PAYMENT       " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "     MERCHANT PAYMENT FAILED    " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";

            break;
        }

        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        if (hashDelimiterdetails.get("39").equals("00")) {
            String strReplace = hashDelimiterString.replace("CUSTOMER COPY", "AGENT COPY");
            hashDelimiterString += strReplace;
        }
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "340000":
        // Card Activation
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "         CARD ACTIVATION        " + "#";
            hashDelimiterString += "   CARD ACTIVATION SUCCESSFUL   " + "#";
            hashDelimiterString += "                                " + "#";
            break;
        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "         CARD ACTIVATION        " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "      CARD ACTIVATION FAILED    " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";

            break;
        }
        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;
    case "320000":
        // Bill presentment
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("48"));
        switch (hashDelimiterdetails.get("39")) {
        case "00":
            switch (hashDelimiterdetails.get("100").toUpperCase()) {
            case "DSTV_INQ":
                response = getDSTVresponse(strReasonDescription);
                break;
            case "TRA_INQ":
                break;
            case "BRELA_INQ":
                dataArray = strReasonDescription.split("|");
                Status = dataArray[1];
                Amount = dataArray[3];
                Currency = dataArray[4];
                CustomerName = dataArray[5];
                response = "STATUS: " + Status + " AMOUNT: " + Currency + " " + Amount + " CUSTOMER NAME: "
                        + CustomerName;
                break;
            case "TPA_INQ":
                dataArray = strReasonDescription.split("~");
                Status = dataArray[1];
                Amount = dataArray[3];
                Currency = dataArray[4];
                CustomerName = dataArray[5];
                response = "STATUS: " + Status + " AMOUNT: " + Currency + " " + Amount + " CUSTOMER NAME: "
                        + CustomerName;
                break;
            }
            break;
        default:
            break;
        }
        this.SendPOSResponse(hashDelimiterString, intid);
        break;

    case "210000":
        // Cash Deposit

        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
        String amountString = formatter.format(Double.valueOf(hashDelimiterdetails.get("4"))).replace("TZS",
                "");

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            if (hashDelimiterdetails.get("48").toUpperCase().equals("SUCCESS")) {

                try {
                    String strAccountNumber = hashDelimiterdetails.get("103").toString();
                    String RecipientName = "";
                    if (hashDelimiterdetails.containsKey("89")) {
                        RecipientName = "ACC NAME:" + hashDelimiterdetails.get("89");
                    } else {
                        RecipientName = "ACC NAME:" + getCustomerDetails((hashDelimiterdetails.get("103")));
                    }

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          CASH DEPOSIT          " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "     CASH DEPOSIT SUCCESSFUL    " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "AMOUNT:      TZS " + amountString + "#";
                    hashDelimiterString += "TO ACCOUNT:      " + (hashDelimiterdetails.get("103")) + "#";
                    hashDelimiterString += stringBuilder(RecipientName) + "#";

                    hashDelimiterString += "                                " + "#";

                } catch (Exception ex) {
                    this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                            + this.StackTraceWriter(ex), "ERROR");
                }
            } else {
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "          CASH DEPOSIT          " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "        CASH DEPOSIT FAILED    " + "#";
                hashDelimiterString += " "
                        + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
                hashDelimiterString += "                                " + "#";

            }
            break;

        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "          CASH DEPOSIT          " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "        CASH DEPOSIT FAILED    " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";

            break;

        }
        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        if (hashDelimiterdetails.get("39").equals("00")) {
            String strReplace = hashDelimiterString.replace("CUSTOMER COPY", "AGENT COPY");
            hashDelimiterString += strReplace;
        }
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "310000":
        //Balance Inquiry
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
        switch (hashDelimiterdetails.get("39")) {
        case "00":

            try {
                String[] strBal = hashDelimiterdetails.get("54").split("\\|");
                String strAccountNumber = hashDelimiterdetails.get("102").toString();
                strAvailableBalance = formatter.format(Double.valueOf(strBal[0])).replace("TZS", "");
                strActualBalance = formatter.format(Double.valueOf(strBal[1])).replace("TZS", "");

                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "        BALANCE ENQUIRY         " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "ACCOUNT NUM:       " + (hashDelimiterdetails.get("102")) + "#";
                hashDelimiterString += "AVAIL BALANCE: TZS " + strAvailableBalance + "#";
                hashDelimiterString += "ACTUAL BALANCE:TZS " + strActualBalance + "#";
                hashDelimiterString += "                                " + "#";

            } catch (Exception ex) {
                this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                        + this.StackTraceWriter(ex), "ERROR");
            }
            break;
        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "        BALANCE ENQUIRY         " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "       BALANCE ENQUIRY FAILED   " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";

            break;

        }
        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "300000":
        // Agent balances
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
        switch (hashDelimiterdetails.get("39")) {
        case "00":
            try {
                String[] strBal = hashDelimiterdetails.get("54").split("\\|");
                String strAccountNumber = hashDelimiterdetails.get("102").toString();
                strAvailableBalance = formatter.format(Double.valueOf(strBal[0])).replace("TZS", "");
                strActualBalance = formatter.format(Double.valueOf(strBal[1])).replace("TZS", "");

                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "     AGENT BALANCE ENQUIRY      " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "ACCOUNT NUM:       " + hashDelimiterdetails.get("102").toString() + "#";
                hashDelimiterString += "AVAIL BALANCE:  TZS" + strAvailableBalance + "#";
                hashDelimiterString += "ACTUAL BALANCE: TZS" + strActualBalance + "#";
                hashDelimiterString += "                                " + "#";

            } catch (Exception ex) {
                this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                        + this.StackTraceWriter(ex), "ERROR");
            }
            break;
        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "     AGENT BALANCE ENQUIRY      " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "     AGENT BALANCE FAILED      " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";
            break;
        }
        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "380000":
        // Mini Statement
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        try {
            if (hashDelimiterdetails.get("48").contains("~")) {
                String[] strStatementData = hashDelimiterdetails.get("48").split("~");

                for (int i = 0; i < strStatementData.length; i++) {
                    strStatementPrinting += strStatementData[i] + "#";
                }
            }

            switch (hashDelimiterdetails.get("39")) {
            case "00":
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "      MINISTATEMENT ENQUIRY     " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "ACCOUNT NUM:       " + (hashDelimiterdetails.get("102")) + "#";
                hashDelimiterString += strStatementPrinting + "#";
                hashDelimiterString += "                                " + "#";
                break;

            default:
                strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "      MINISTATEMENT ENQUIRY     " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "   MINISTATEMENT ENQUIRY FAILED " + "#";
                hashDelimiterString += " "
                        + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
                hashDelimiterString += "                                " + "#";
                break;
            }
            hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
            this.SendPOSResponse(hashDelimiterString, intid);
            updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
            break;

        } catch (Exception ex) {
            this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                    + this.StackTraceWriter(ex), "ERROR");
        }

        break;
    case "400000":
        // FUNDS TRANSFER

        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
        String StramountString = formatter.format(Double.valueOf(hashDelimiterdetails.get("4"))).replace("TZS",
                "");

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            if (hashDelimiterdetails.get("48").toUpperCase().equals("SUCCESS")) {

                try {
                    String strAccountNumber = hashDelimiterdetails.get("103").toString();
                    String SendersName = "ACC NAME:" + getCustomerDetails((hashDelimiterdetails.get("102")));
                    String RecipientsName = "ACC NAME:" + getCustomerDetails((hashDelimiterdetails.get("103")));

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          FUNDS TRANSFER          " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "     FUNDS TRANSFER SUCCESSFUL    " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "AMOUNT:       TZS " + StramountString + "#";
                    hashDelimiterString += "FROM ACCOUNT:     " + (hashDelimiterdetails.get("102")) + "#";
                    hashDelimiterString += stringBuilder(SendersName) + "#";
                    hashDelimiterString += "TO ACCOUNT:       " + (hashDelimiterdetails.get("103")) + "#";
                    hashDelimiterString += stringBuilder(RecipientsName) + "#";

                    hashDelimiterString += "                                " + "#";

                } catch (Exception ex) {
                    this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                            + this.StackTraceWriter(ex), "ERROR");
                }
            } else {
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "          FUNDS TRANSFER          " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "       FUNDS TRANSFER FAILED    " + "#";
                hashDelimiterString += " "
                        + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
                hashDelimiterString += "                                " + "#";
            }
            break;

        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "          FUNDS TRANSFER          " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "       FUNDS TRANSFER FAILED    " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";
            break;

        }
        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        if (hashDelimiterdetails.get("39").equals("00")) {
            String strReplace = hashDelimiterString.replace("CUSTOMER COPY", "AGENT COPY");
            hashDelimiterString += strReplace;
        }
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "420000":
        // Airtime Topup
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            try {
                String strAccountNumber = hashDelimiterdetails.get("102").toString();
                String strAmount = formatter.format(Double.valueOf(hashDelimiterdetails.get("4")))
                        .replace("TZS", "");

                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "         AIRTIME TOPUP          " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "    AIRTIME TOPUP SUCCESSFUL    " + "#";
                hashDelimiterString += "ACCOUNT NUM:     " + strAccountNumber + "#";
                hashDelimiterString += "AMOUNT:      TZS " + strAmount + "#";
                hashDelimiterString += "                                " + "#";

            } catch (Exception ex) {
                this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                        + this.StackTraceWriter(ex), "ERROR");
            }
            break;
        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "         AIRTIME TOPUP          " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "      AIRTIME TOPUP FAILED      " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";
            break;
        }

        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));

        if (hashDelimiterdetails.get("39").equals("00")) {
            String strReplace = hashDelimiterString.replace("CUSTOMER COPY", "AGENT COPY");
            hashDelimiterString += strReplace;
        }
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "500000":
        //Bills Payments
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            if (hashDelimiterdetails.get("48").toString().trim().equalsIgnoreCase("NOPURCHASE")) {
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "          BILL PAYMENT          " + "#";
                hashDelimiterString += stringBuilder(hashDelimiterdetails.get("48")) + "#";
                hashDelimiterString += "                                " + "#";
            } else {
                // LUKU PREPAID
                String strAmount = formatter.format(Double.valueOf(hashDelimiterdetails.get("4")))
                        .replace("TZS", "");
                String strToken = "";
                if (hashDelimiterdetails.get("100").equals("LUKUPREPAID")) {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          BILL PAYMENT          " + "#";
                    hashDelimiterString += "     LUKU PAYMENT SUCCESSFUL    " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += " METER NUM: " + hashDelimiterdetails.get("65") + "#";
                    hashDelimiterString += " TOKEN NUM: " + stringBuilder(hashDelimiterdetails.get("48")) + "#";
                    hashDelimiterString += " AMOUNT PAID:TZS " + strAmount + "#";
                    hashDelimiterString += "                                " + "#";
                }

                //AZAMTV
                if (hashDelimiterdetails.get("100").equals("AZAMTV")) {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          BILL PAYMENT          " + "#";
                    hashDelimiterString += "   AZAM TV PAYMENT SUCCESSFUL   " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += " METER NUM: " + hashDelimiterdetails.get("65") + "#";
                    hashDelimiterString += getAZAMTVResponse(hashDelimiterdetails.get("48"));
                    hashDelimiterString += "                                " + "#";

                }

                //STARTIMES TV
                if (hashDelimiterdetails.get("100").equals("STARTIMESTV")) {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          BILL PAYMENT          " + "#";
                    hashDelimiterString += " STARTIMES TV PAYMENT SUCCESSFUL" + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += " METER NUM:      " + hashDelimiterdetails.get("65") + "#";
                    hashDelimiterString += getStartimesResponse(hashDelimiterdetails.get("48"));
                    hashDelimiterString += "                                " + "#";
                }

                //DAWASCO PAYMENT  
                if (hashDelimiterdetails.get("100").equals("DAWASCO")) {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          BILL PAYMENT          " + "#";
                    hashDelimiterString += "   DAWASCO PAYMENT SUCCESSFUL   " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += " METER NUM:      " + hashDelimiterdetails.get("65") + "#";
                    hashDelimiterString += " TOKEN NUM:      " + stringBuilder(hashDelimiterdetails.get("48"))
                            + "#";
                    hashDelimiterString += " AMOUNT PAID:    " + strAmount + "#";
                    hashDelimiterString += "                                " + "#";
                }

                //ZUKU PAYMENT
                if (hashDelimiterdetails.get("100").equals("ZUKU")) {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          BILL PAYMENT          " + "#";
                    hashDelimiterString += "   ZUKU PAYMENT SUCCESSFUL   " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += " METER NUM:      " + hashDelimiterdetails.get("65") + "#";
                    hashDelimiterString += getZukuresponse(hashDelimiterdetails.get("48"));
                    hashDelimiterString += "                                " + "#";
                }

                //NHC PAYMENT
                if (hashDelimiterdetails.get("100").equals("NHC")) {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          BILL PAYMENT          " + "#";
                    hashDelimiterString += "    NHC PAYMENT SUCCESSFUL   " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += " METER NUM:      " + hashDelimiterdetails.get("65") + "#";
                    hashDelimiterString += " TOKEN NUM:      " + stringBuilder(hashDelimiterdetails.get("48"));
                    hashDelimiterString += " AMOUNT PAID:    " + strAmount + "#";
                    hashDelimiterString += "                                " + "#";
                }

                //PRECISIONAIR PAYMENT
                if (hashDelimiterdetails.get("100").equals("PRECISIONAIR")) {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "          BILL PAYMENT          " + "#";
                    hashDelimiterString += "PRECISION AIR PAYMENT SUCCESSFUL" + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += " METER NUM:      " + hashDelimiterdetails.get("65") + "#";
                    hashDelimiterString += " TICKET NUM:     " + stringBuilder(hashDelimiterdetails.get("48"))
                            + "#";
                    hashDelimiterString += " AMOUNT PAID:    " + strAmount + "#";
                    hashDelimiterString += "                                " + "#";
                }
            }
            break;
        default:
            hashDelimiterString += "         BILL PAYMENT           " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "      BILL PAYMENT FAILED   " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";
            break;

        }

        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        if (hashDelimiterdetails.get("39").equals("00")) {
            String strReplace = hashDelimiterString.replace("CUSTOMER COPY", "AGENT COPY");
            hashDelimiterString += strReplace;
        }
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;
    case "620000":
        //Cardless Origination
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
        switch (hashDelimiterdetails.get("39")) {
        case "00":
            String[] strBal = hashDelimiterdetails.get("54").split("|");
            try {
                strAvailableBalance = strBal[0];
            } catch (Exception ex) {
                this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                        + this.StackTraceWriter(ex), "ERROR");
            }
            try {
                strActualBalance = strBal[1];
            } catch (Exception ex) {
                this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                        + this.StackTraceWriter(ex), "ERROR");
            }

            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "      CARDLESS ORIGINATION      " + "#";
            hashDelimiterString += "  CARDLESS TRANSFER SUCCESSFUL  " + "#";
            hashDelimiterString += "                                " + "#";

            if (hashDelimiterdetails.get("80").isEmpty()) {
            } else {
                hashDelimiterString += "    Your 4 digit code is "
                        + hashDelimiterdetails.get("80").substring(0, 4) + "#";
            }

            hashDelimiterString += "Please send it to the Receipient" + "#";
            hashDelimiterString += "--------------------------------" + "#";
            hashDelimiterString += "Amount .      " + NumberFormat.getNumberInstance(Locale.US)
                    .format(Double.parseDouble(hashDelimiterdetails.get("4"))) + "#";
            hashDelimiterString += "--------------------------------" + "#";
            hashDelimiterString += "Avail.      "
                    + NumberFormat.getNumberInstance(Locale.US).format(Double.parseDouble(strAvailableBalance))
                    + "#";
            hashDelimiterString += "Actual.     "
                    + NumberFormat.getNumberInstance(Locale.US).format(Double.parseDouble(strActualBalance))
                    + "#";

            cardlesssmsmsg = "Dear Customer, Your 4 digit code is "
                    + hashDelimiterdetails.get("80").substring(0, 4) + ", kindly send this to the recipient";
            break;
        default:

            strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "      CARDLESS ORIGINATION      " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "  CARDLESS ORIGINATION FAILED   " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";
            break;
        }

        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    case "630000":
        //Cardless Fullfillment
        try {
            hashDelimiterString += "Ref No:      " + hashDelimiterdetails.get("37") + "#";
            strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
            switch (hashDelimiterdetails.get("39")) {
            case "00":
                String strAmount = formatter.format(Double.valueOf(hashDelimiterdetails.get("4")))
                        .replace("TZS", "");
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "      CARDLESS FULLFILMENT      " + "#";
                hashDelimiterString += "CARDLESS FULLFILLMENT SUCCESSFUL" + "#";
                hashDelimiterString += "AMOUNT:      " + strAmount + "#";
                hashDelimiterString += "                                " + "#";
                break;
            default:
                strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "      CARDLESS FULLFILMENT      " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "   CARDLESS FULLFILMENT FAILED  " + "#";
                hashDelimiterString += " "
                        + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
                hashDelimiterString += "                                " + "#";
                break;
            }

            hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
            this.SendPOSResponse(hashDelimiterString, intid);
            updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        } catch (Exception ex) {
            this.log("\nINFO genHashDelimeterString() :: " + ex.getMessage() + "\n" + StackTraceWriter(ex),
                    "ERROR");
        }
        break;

    case "720000":
        //Reversal Request
        hashDelimiterString += "TRAN NUM:  " + hashDelimiterdetails.get("37") + "#";
        hashDelimiterString += "--------------------------------" + "#";
        hashDelimiterString += "                                " + "#";
        strReasonDescription = this.getResponseCode(hashDelimiterdetails.get("39"));

        switch (hashDelimiterdetails.get("39")) {
        case "00":
            if (hashDelimiterdetails.get("48").equals("SUCCESS")) {
                try {

                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "        REVERSAL REQUEST        " + "#";
                    hashDelimiterString += "    REVERSAL REQUEST SUCCESSFUL " + "#";
                    hashDelimiterString += "                                " + "#";
                    hashDelimiterString += "                                " + "#";

                } catch (Exception ex) {
                    this.log("INFO : Function genHashDelimiterString   " + ex.getMessage() + "\n"
                            + this.StackTraceWriter(ex), "ERROR");
                }

            } else {
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "        REVERSAL REQUEST        " + "#";
                hashDelimiterString += "                                " + "#";
                hashDelimiterString += "    REVERSAL REQUEST FAILED     " + "#";
                hashDelimiterString += " "
                        + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
                hashDelimiterString += "                                " + "#";

            }
            break;
        default:
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "         REVERSAL REQUEST        " + "#";
            hashDelimiterString += "                                " + "#";
            hashDelimiterString += "     REVERSAL REQUEST FAILED    " + "#";
            hashDelimiterString += " "
                    + stringBuilder(InterpretResponse(hashDelimiterdetails.get("48").toString())) + "#";
            hashDelimiterString += "                                " + "#";

            break;
        }

        hashDelimiterString += this.strResponseFooter(hashDelimiterdetails.get("104"));
        if (hashDelimiterdetails.get("39").equals("00")) {
            String strReplace = hashDelimiterString.replace("CUSTOMER COPY", "AGENT COPY");
            hashDelimiterString += strReplace;
        }
        this.SendPOSResponse(hashDelimiterString, intid);

        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;

    default:
        hashDelimiterString = "TRANSACTION CODE NOT DEFINED#--------------------------------#";
        hashDelimiterString += "";
        this.SendPOSResponse(hashDelimiterString, intid);
        updateTransactionResponse(hashDelimiterdetails, intid, hashDelimiterString);
        break;
    }

    return hashDelimiterString;
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

/**
 * For a given axis, adjust the tick unit size, in order to 
 * have a customizable number of ticks on that axis
 *//*from w w  w  . ja v  a2s.  c o m*/
protected void calculateTickUnits(Axis axis, AxisSettings axisSettings, DateTickUnitType timePeriodUnitx) {
    Integer tickCount = null;
    Number tickInterval = null;
    boolean axisIntegerUnit = false;

    if (getChart().hasProperties()) {
        String tickCountProperty = null;
        String tickIntervalProperty = null;
        String axisIntegerUnitProperty = null;

        if (axisSettings == getChartThemeSettings().getRangeAxisSettings()) {
            tickCountProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT);
            tickIntervalProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL);
            axisIntegerUnitProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_INTEGER_UNIT);
        } else {
            tickCountProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT);
            tickIntervalProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL);
            axisIntegerUnitProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_INTEGER_UNIT);
        }
        if (tickCountProperty != null && tickCountProperty.trim().length() > 0) {
            tickCount = Integer.valueOf(tickCountProperty);
        }
        if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) {
            tickInterval = Double.valueOf(tickIntervalProperty);
        }
        if (axisIntegerUnitProperty != null && axisIntegerUnitProperty.trim().length() > 0) {
            axisIntegerUnit = Boolean.valueOf(axisIntegerUnitProperty);
        }
    } else {
        tickCount = axisSettings.getTickCount();
        tickInterval = axisSettings.getTickInterval();
        if (axisSettings.getAxisIntegerUnit() != null) {
            axisIntegerUnit = axisSettings.getAxisIntegerUnit();
        }
    }

    if (axis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) axis;
        int axisRange = (int) numberAxis.getRange().getLength();
        if (axisIntegerUnit) {
            ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext());
            numberAxis.setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale()));
            chartUtil.setAutoTickUnit(numberAxis);
        } else if (axisRange > 0) {
            if (tickInterval != null) {
                if (numberAxis.getNumberFormatOverride() != null) {
                    numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(),
                            numberAxis.getNumberFormatOverride()));
                } else {
                    numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(),
                            NumberFormat.getNumberInstance(getLocale())));
                }
            } else if (tickCount != null) {
                if (numberAxis.getNumberFormatOverride() != null) {
                    numberAxis.setTickUnit(
                            new NumberTickUnit(axisRange / tickCount, numberAxis.getNumberFormatOverride()));
                } else {
                    numberAxis.setTickUnit(new NumberTickUnit(axisRange / tickCount,
                            NumberFormat.getNumberInstance(getLocale())));
                }
            } else {
                ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext());
                numberAxis.setStandardTickUnits(chartUtil.createStandardTickUnits(getLocale()));
                chartUtil.setAutoTickUnit(numberAxis);
            }
        }
    }
    //      else if (axis instanceof DateAxis)
    //      {
    //         DateAxis dateAxis = (DateAxis)axis;
    //         int axisRange = (int)dateAxis.getRange().getLength();
    //         if (dateAxis.getDateFormatOverride() != null)
    //         {
    //            dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount, dateAxis.getDateFormatOverride()));
    //         }
    //         else
    //         {
    //            dateAxis.setTickUnit(new DateTickUnit(timePeriodUnit, axisRange/tickCount));
    //         }
    //      }
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

/**
 * For a given axis, adjust the tick unit size, in order to 
 * have a customizable number of ticks on that axis
 *///from  w w  w  .  j a  v a  2 s . c o m
protected void calculateTickUnits(Axis axis, boolean isRangeAxis, String timePeriodUnit) {
    Integer tickCount = null;
    Number tickInterval = null;
    boolean axisIntegerUnit = false;

    if (getChart().hasProperties()) {
        String tickCountProperty = null;
        String tickIntervalProperty = null;
        String axisIntegerUnitProperty = null;

        if (isRangeAxis) {
            tickCountProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_COUNT);
            tickIntervalProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_TICK_INTERVAL);
            axisIntegerUnitProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_RANGE_AXIS_INTEGER_UNIT);
        } else {
            tickCountProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_COUNT);
            tickIntervalProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_TICK_INTERVAL);
            axisIntegerUnitProperty = getChart().getPropertiesMap()
                    .getProperty(DefaultChartTheme.PROPERTY_DOMAIN_AXIS_INTEGER_UNIT);
        }
        if (tickCountProperty != null && tickCountProperty.trim().length() > 0) {
            tickCount = Integer.valueOf(tickCountProperty);
        }
        if (tickIntervalProperty != null && tickIntervalProperty.trim().length() > 0) {
            tickInterval = Double.valueOf(tickIntervalProperty);
        }
        if (axisIntegerUnitProperty != null && axisIntegerUnitProperty.trim().length() > 0) {
            axisIntegerUnit = Boolean.valueOf(axisIntegerUnitProperty);
        }
    } else {
        if (isRangeAxis) {
            tickCount = (Integer) getDefaultValue(defaultAxisPropertiesMap,
                    ChartThemesConstants.RANGE_AXIS_TICK_COUNT);
            tickInterval = (Number) getDefaultValue(defaultAxisPropertiesMap,
                    ChartThemesConstants.RANGE_AXIS_TICK_INTERVAL);
            if (getDefaultValue(defaultAxisPropertiesMap,
                    ChartThemesConstants.RANGE_AXIS_INTEGER_UNIT) != null) {
                axisIntegerUnit = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
                        ChartThemesConstants.RANGE_AXIS_INTEGER_UNIT);
            }
        } else {
            tickCount = (Integer) getDefaultValue(defaultAxisPropertiesMap,
                    ChartThemesConstants.DOMAIN_AXIS_TICK_COUNT);
            tickInterval = (Number) getDefaultValue(defaultAxisPropertiesMap,
                    ChartThemesConstants.DOMAIN_AXIS_TICK_INTERVAL);
            if (getDefaultValue(defaultAxisPropertiesMap,
                    ChartThemesConstants.DOMAIN_AXIS_INTEGER_UNIT) != null) {
                axisIntegerUnit = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
                        ChartThemesConstants.DOMAIN_AXIS_INTEGER_UNIT);
            }
        }
    }

    //      if (axis instanceof NumberAxis)
    //      {
    //         NumberAxis numberAxis = (NumberAxis)axis;
    //         int axisRange = (int)numberAxis.getRange().getLength();
    //         if (numberAxis.getNumberFormatOverride() != null)
    //         {
    //            if (tickInterval != null && tickInterval.length() > 0)
    //               numberAxis.setTickUnit(new NumberTickUnit(Double.valueOf(tickInterval), numberAxis.getNumberFormatOverride()));
    //            else
    //               numberAxis.setTickUnit(new NumberTickUnit( axisRange/tickCount, numberAxis.getNumberFormatOverride()));
    //         }
    //         else
    //         {
    //            if (tickInterval != null && tickInterval.length() > 0)
    //               numberAxis.setTickUnit(new NumberTickUnit(Double.valueOf(tickInterval)));
    //            else
    //               numberAxis.setTickUnit(new NumberTickUnit(axisRange/tickCount));
    //         }
    //      }
    if (axis instanceof NumberAxis) {
        NumberAxis numberAxis = (NumberAxis) axis;
        int axisRange = (int) numberAxis.getRange().getLength();

        if (axisIntegerUnit) {
            ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext());
            numberAxis.setStandardTickUnits(chartUtil.createIntegerTickUnits(getLocale()));
            chartUtil.setAutoTickUnit(numberAxis);
        } else if (axisRange > 0) {
            if (tickInterval != null) {
                if (numberAxis.getNumberFormatOverride() != null) {
                    numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(),
                            numberAxis.getNumberFormatOverride()));
                } else {
                    numberAxis.setTickUnit(new NumberTickUnit(tickInterval.doubleValue(),
                            NumberFormat.getNumberInstance(getLocale())));
                }
            } else if (tickCount != null) {
                int newTickUnitSize = axisRange / tickCount;
                if (newTickUnitSize > numberAxis.getTickUnit().getSize()) {
                    int tickUnitSize = newTickUnitSize;

                    //preferably multiple of 5 values should be used as tick units lengths:
                    int i = 1;
                    while (tickUnitSize > 9) {
                        tickUnitSize /= 10;
                        i *= 10;
                    }
                    tickUnitSize *= i;
                    newTickUnitSize = tickUnitSize + i / 2;

                    if (newTickUnitSize > 0 && axisRange / newTickUnitSize > tickCount) {
                        newTickUnitSize += i / 2;
                    }
                    if (numberAxis.getNumberFormatOverride() != null) {
                        numberAxis.setTickUnit(
                                new NumberTickUnit(newTickUnitSize, numberAxis.getNumberFormatOverride()));
                    } else {
                        numberAxis.setTickUnit(new NumberTickUnit(newTickUnitSize,
                                NumberFormat.getNumberInstance(getLocale())));
                    }
                }
            } else {
                ChartUtil chartUtil = ChartUtil.getInstance(getChartContext().getJasperReportsContext());
                numberAxis.setStandardTickUnits(chartUtil.createStandardTickUnits(getLocale()));
                chartUtil.setAutoTickUnit(numberAxis);
            }
        }
    }
    //      else if (axis instanceof DateAxis)
    //      {
    //         DateAxis dateAxis = (DateAxis)axis;
    //         int axisRange = (int)dateAxis.getRange().getLength();
    //         int timeUnit = getTimePeriodUnit(timePeriodUnit);
    //         
    //         if (dateAxis.getDateFormatOverride() != null)
    //         {
    //            if (tickInterval != null && tickInterval.length() > 0)
    //               dateAxis.setTickUnit(new DateTickUnit(timeUnit, Integer.valueOf(tickInterval), dateAxis.getDateFormatOverride()));
    //            else
    //               dateAxis.setTickUnit(new DateTickUnit(timeUnit, axisRange/tickCount, dateAxis.getDateFormatOverride()));
    //         }
    //         else
    //         {
    //            if (tickInterval != null && tickInterval.length() > 0)
    //               dateAxis.setTickUnit(new DateTickUnit(timeUnit, Integer.valueOf(tickInterval)));
    //            else
    //               dateAxis.setTickUnit(new DateTickUnit(timeUnit, axisRange/tickCount));
    //         }
    //      }
}

From source file:com.osparking.osparking.Settings_System.java

private void addPopSizeOptions() {
    PopSizeCBox.removeAllItems();//from w  w  w  .j a v  a2s.  c o m

    for (int option : statCountArr) {
        PopSizeCBox.addItem(new ConvComboBoxItem(new Integer(option),
                NumberFormat.getNumberInstance(Locale.US).format(option)));
    }
}