Example usage for java.math BigDecimal min

List of usage examples for java.math BigDecimal min

Introduction

In this page you can find the example usage for java.math BigDecimal min.

Prototype

public BigDecimal min(BigDecimal val) 

Source Link

Document

Returns the minimum of this BigDecimal and val .

Usage

From source file:org.kalypso.wspwin.core.WspWinZustand.java

void updateSegmentInfo() {
    m_segmentBeans.clear();/*from  w  ww  . ja  v a  2  s .  c om*/

    BigDecimal minStation = new BigDecimal(Double.MAX_VALUE);
    BigDecimal maxStation = new BigDecimal(-Double.MAX_VALUE);
    for (int i = 0; i < m_profileBeans.size() - 1; i++) {
        final ProfileBean fromProfile = m_profileBeans.get(i);
        final ProfileBean toProfile = m_profileBeans.get(i + 1);

        final BigDecimal stationFrom = fromProfile.getStation();
        final BigDecimal stationTo = toProfile.getStation();

        /* calculate global min/max station */
        minStation = minStation.min(stationFrom);
        minStation = minStation.min(stationTo);
        maxStation = maxStation.max(stationFrom);
        maxStation = maxStation.max(stationTo);

        /* recalculate distance to next profile */
        // REMARK: special handling for the distance of Profiles with 'Mehrfeld-Code': here the distance must be
        // the distance to the next real profile (i.e. the next profile without Mehfeld-Code and with a different station)
        final ProfileBean nextRealProfile = findNextRealProfile(fromProfile, i + 1);

        final double distance;
        if (nextRealProfile == null) {
            // should never happen
            distance = Math.abs(stationTo.doubleValue() - stationFrom.doubleValue());
            System.out.println("Error in zustand"); //$NON-NLS-1$
        } else {
            final BigDecimal nextStation = nextRealProfile.getStation();
            distance = Math.abs(nextStation.doubleValue() - stationFrom.doubleValue());
        }

        final String fileNameFrom = fromProfile.getFileName();
        final String fileNameTo = toProfile.getFileName();

        final ZustandSegmentBean segment = new ZustandSegmentBean(stationFrom, stationTo, fileNameFrom,
                fileNameTo, distance, distance, distance);
        m_segmentBeans.add(segment);
    }

    m_bean.setStartStation(minStation);
    m_bean.setEndStation(maxStation);
}

From source file:org.openbravo.erpCommon.ad_forms.AcctServer.java

/**
 * Matching//from  w  w  w .  jav  a 2s . c  om
 * 
 * <pre>
 *  Derive Invoice-Receipt Match from PO-Invoice and PO-Receipt
 *  Purchase Order (20)
 *  - Invoice1 (10)
 *  - Invoice2 (10)
 *  - Receipt1 (5)
 *  - Receipt2 (15)
 *  (a) Creates Directs
 *      - Invoice1 - Receipt1 (5)
 *      - Invoice2 - Receipt2 (10)
 *  (b) Creates Indirects
 *      - Invoice1 - Receipt2 (5)
 *  (Not imlemented)
 * 
 * 
 * </pre>
 * 
 * @return number of records created
 */
public int match(VariablesSecureApp vars, ConnectionProvider conn, Connection con) {
    // if (log4j.isDebugEnabled())
    // log4j.debug("AcctServer - Match--Starting");
    int counter = 0;
    // (a) Direct Matches
    AcctServerData[] data = null;
    try {
        data = AcctServerData.selectMatch(conn, AD_Client_ID);
        for (int i = 0; i < data.length; i++) {
            BigDecimal qty1 = new BigDecimal(data[i].qty1);
            BigDecimal qty2 = new BigDecimal(data[i].qty2);
            BigDecimal Qty = qty1.min(qty2);
            if (Qty.toString().equals("0"))
                continue;
            // if (log4j.isDebugEnabled())
            // log4j.debug("AcctServer - Match--dateTrx1 :->" + data[i].datetrx1
            // + "Match--dateTrx2: ->" + data[i].datetrx2);
            String dateTrx1 = data[i].datetrx1;
            String dateTrx2 = data[i].datetrx2;
            String compare = "";
            try {
                compare = DateTimeData.compare(conn, dateTrx1, dateTrx2);
            } catch (ServletException e) {
                log4j.warn(e);
                e.printStackTrace();
            }
            String DateTrx = dateTrx1;
            if (compare.equals("-1"))
                DateTrx = dateTrx2;
            //
            String strQty = Qty.toString();
            String strDateTrx = DateTrx;
            String AD_Client_ID = data[i].adClientId;
            String AD_Org_ID = data[i].adOrgId;
            String C_InvoiceLine_ID = data[i].cInvoicelineId;
            String M_InOutLine_ID = data[i].mInoutlineId;
            String M_Product_ID = data[i].mProductId;
            //
            if (createMatchInv(AD_Client_ID, AD_Org_ID, M_InOutLine_ID, C_InvoiceLine_ID, M_Product_ID,
                    strDateTrx, strQty, vars, conn, con) == 1)
                counter++;
        }
    } catch (ServletException e) {
        log4j.warn(e);
        e.printStackTrace();
    }
    // if (log4j.isDebugEnabled())
    // log4j.debug("AcctServer - Matcher.match - Client_ID=" + AD_Client_ID
    // + ", Records created=" + counter);
    return counter;
}

From source file:uk.ac.leeds.ccg.andyt.projects.fluvialglacial.SlopeAreaAnalysis.java

protected TreeMap<Integer, Object[]> readSwissData(File fileIn) {
    TreeMap<Integer, Object[]> result;
    result = new TreeMap<Integer, Object[]>();
    BufferedReader br;/*from  w  w  w.j  a v a  2  s.c om*/
    br = Generic_StaticIO.getBufferedReader(fileIn);
    StreamTokenizer st;
    st = new StreamTokenizer(br);
    Generic_StaticIO.setStreamTokenizerSyntax5(st);
    st.wordChars('(', '(');
    st.wordChars(')', ')');
    st.wordChars('%', '%');
    Generic_StaticIO.skipline(st);
    int token;
    String line = "";
    String[] fields;
    try {
        token = st.nextToken();
        int ID;
        //int pointID;
        while (token != StreamTokenizer.TT_EOF) {
            switch (token) {
            case StreamTokenizer.TT_EOL:
                //flowacc,area (km2),slope_25_(%),proglac_ID,COUNT
                //12.11111069,0.00756944,32.33880000000,0,250631
                fields = line.split(sComma);
                ID = Integer.valueOf(fields[3]);
                if (ID > 0) {
                    //BigDecimal flowacc;
                    BigDecimal area;
                    BigDecimal slope;
                    Object[] data;
                    BigDecimal maxx;
                    BigDecimal maxy;
                    BigDecimal minx;
                    BigDecimal miny;
                    data = result.get(ID);
                    ArrayList<Generic_XYNumericalData> theGeneric_XYNumericalData;
                    if (data == null) {
                        data = new Object[5];
                        theGeneric_XYNumericalData = new ArrayList<Generic_XYNumericalData>();
                        maxx = BigDecimal.ZERO;
                        maxy = BigDecimal.ZERO;
                        minx = BigDecimal.valueOf(Double.MAX_VALUE);
                        miny = BigDecimal.valueOf(Double.MAX_VALUE);
                        data[0] = theGeneric_XYNumericalData;
                        data[1] = maxx;
                        data[2] = minx;
                        data[3] = maxy;
                        data[4] = miny;
                        result.put(ID, data);
                    } else {
                        theGeneric_XYNumericalData = (ArrayList<Generic_XYNumericalData>) data[0];
                        maxx = (BigDecimal) data[1];
                        minx = (BigDecimal) data[2];
                        maxy = (BigDecimal) data[3];
                        miny = (BigDecimal) data[4];
                    }
                    //pointID = Integer.valueOf(fields[4]);
                    //flowacc = new BigDecimal(fields[0]);
                    area = new BigDecimal(fields[1]);
                    if (area.compareTo(BigDecimal.ZERO) == 1) {
                        area = Generic_BigDecimal.log(10, area, 10, RoundingMode.HALF_UP);
                    } else {
                        area = BigDecimal.ZERO;
                    }
                    slope = new BigDecimal(fields[2]);
                    if (slope.compareTo(BigDecimal.ZERO) == 1) {
                        slope = Generic_BigDecimal.log(10, slope, 10, RoundingMode.HALF_UP);
                    } else {
                        slope = BigDecimal.ZERO;
                    }
                    Generic_XYNumericalData point;
                    point = new Generic_XYNumericalData(slope, area);
                    theGeneric_XYNumericalData.add(point);
                    data[0] = theGeneric_XYNumericalData;
                    data[1] = maxx.max(slope);
                    data[2] = minx.min(slope);
                    data[3] = maxy.max(area);
                    data[4] = miny.min(area);
                }
                break;
            case StreamTokenizer.TT_WORD:
                line = st.sval;
                break;
            }
            token = st.nextToken();
        }
    } catch (IOException ex) {
        Logger.getLogger(SlopeAreaAnalysis.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
}

From source file:uk.ac.leeds.ccg.andyt.projects.fluvialglacial.SlopeAreaAnalysis.java

protected TreeMap<Integer, Object[]> readAustriaData(File fileIn) {
    TreeMap<Integer, Object[]> result;
    result = new TreeMap<Integer, Object[]>();
    BufferedReader br;/*  w  ww . ja v a  2s  . c  o  m*/
    br = Generic_StaticIO.getBufferedReader(fileIn);
    StreamTokenizer st;
    st = new StreamTokenizer(br);
    Generic_StaticIO.setStreamTokenizerSyntax5(st);
    st.wordChars('(', '(');
    st.wordChars(')', ')');
    st.wordChars('%', '%');
    Generic_StaticIO.skipline(st);
    int token;
    String line = "";
    String[] fields;
    try {
        token = st.nextToken();
        int ID;
        //int pointID;
        while (token != StreamTokenizer.TT_EOF) {
            switch (token) {
            case StreamTokenizer.TT_EOL:
                //flowacc,area (km2),slope_25_(%),proglac_ID,COUNT
                //12.11111069,0.00756944,32.33880000000,0,250631
                fields = line.split(sComma);
                ID = Double.valueOf(fields[1]).intValue();
                if (ID > 0) {
                    //BigDecimal flowacc;
                    BigDecimal area;
                    BigDecimal slope;
                    Object[] data;
                    BigDecimal maxx;
                    BigDecimal maxy;
                    BigDecimal minx;
                    BigDecimal miny;
                    data = result.get(ID);
                    ArrayList<Generic_XYNumericalData> theGeneric_XYNumericalData;
                    if (data == null) {
                        data = new Object[5];
                        theGeneric_XYNumericalData = new ArrayList<Generic_XYNumericalData>();
                        maxx = BigDecimal.ZERO;
                        maxy = BigDecimal.ZERO;
                        minx = BigDecimal.valueOf(Double.MAX_VALUE);
                        miny = BigDecimal.valueOf(Double.MAX_VALUE);
                        data[0] = theGeneric_XYNumericalData;
                        data[1] = maxx;
                        data[2] = minx;
                        data[3] = maxy;
                        data[4] = miny;
                        result.put(ID, data);
                    } else {
                        theGeneric_XYNumericalData = (ArrayList<Generic_XYNumericalData>) data[0];
                        maxx = (BigDecimal) data[1];
                        minx = (BigDecimal) data[2];
                        maxy = (BigDecimal) data[3];
                        miny = (BigDecimal) data[4];
                    }
                    //pointID = Integer.valueOf(fields[4]);
                    //flowacc = new BigDecimal(fields[0]);
                    area = new BigDecimal(fields[3]);
                    if (area.compareTo(BigDecimal.ZERO) == 1) {
                        area = Generic_BigDecimal.log(10, area, 10, RoundingMode.HALF_UP);
                    } else {
                        area = BigDecimal.ZERO;
                    }
                    slope = new BigDecimal(fields[2]);
                    if (slope.compareTo(BigDecimal.ZERO) == 1) {
                        slope = Generic_BigDecimal.log(10, slope, 10, RoundingMode.HALF_UP);
                    } else {
                        slope = BigDecimal.ZERO;
                    }
                    Generic_XYNumericalData point;
                    point = new Generic_XYNumericalData(slope, area);
                    theGeneric_XYNumericalData.add(point);
                    data[0] = theGeneric_XYNumericalData;
                    data[1] = maxx.max(slope);
                    data[2] = minx.min(slope);
                    data[3] = maxy.max(area);
                    data[4] = miny.min(area);
                }
                break;
            case StreamTokenizer.TT_WORD:
                line = st.sval;
                break;
            }
            token = st.nextToken();
        }
    } catch (IOException ex) {
        Logger.getLogger(SlopeAreaAnalysis.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
}