List of usage examples for java.math BigDecimal max
public BigDecimal max(BigDecimal val)
From source file:org.kalypso.wspwin.core.WspWinZustand.java
void updateSegmentInfo() { m_segmentBeans.clear();/*from w w w .ja v a 2 s . c o m*/ 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.kuali.ole.module.purap.document.web.struts.OlePurchaseOrderAction.java
/** * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#insertSourceLine(org.apache.struts.action.ActionMapping, * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//*from ww w . j a va2s . com*/ @Override public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // It would be preferable to find a way to genericize the KualiAccountingDocument methods but this will work for now PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form; // index of item selected int itemIndex = getSelectedLine(request); PurApItem item = null; // if custom processing of an accounting line is not done then insert a line generically. if (processCustomInsertAccountingLine(purapForm, request) == false) { String errorPrefix = null; PurApAccountingLine line = null; boolean rulePassed = false; if (itemIndex >= 0) { item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex)); //Calculating the dollar amount for the accounting Line. PurApAccountingLine lineItem = item.getNewSourceLine(); if (lineItem.getAccountLinePercent() != null) { BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100)); lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent)))); } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent() == null) { KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100)); BigDecimal dollarToPercent = dollar.bigDecimalValue() .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR); lineItem.setAccountLinePercent(dollarToPercent); } line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem); //end //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line); errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME; rulePassed = SpringContext.getBean(KualiRuleService.class) .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line)); } else if (itemIndex == -2) { //corrected: itemIndex == -2 is the only case for distribute account //This is the case when we're inserting an accounting line for distribute account. line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine(); //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line); errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE; rulePassed = SpringContext.getBean(KualiRuleService.class) .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line)); } AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine(); if (accountingLineBase != null) { String accountNumber = accountingLineBase.getAccountNumber(); String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode(); Map<String, String> criteria = new HashMap<String, String>(); criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber); criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode); Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, criteria); rulePassed = checkForValidAccount(account); } if (rulePassed) { // add accountingLine SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line); PurApAccountingLine newSourceLine = item.getNewSourceLine(); List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines(); BigDecimal initialValue = new BigDecimal(0); for (PurApAccountingLine accountLine : existingSourceLine) { initialValue = initialValue.add(accountLine.getAccountLinePercent()); } if (itemIndex >= 0) { if ((newSourceLine.getAccountLinePercent() .intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT .subtract(initialValue).intValue()) && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) { if (OleSelectConstant.MAX_PERCENT.subtract(initialValue) .intValue() != OleSelectConstant.ZERO) { insertAccountingLine(purapForm, item, line); } } else { checkAccountingLinePercent(newSourceLine); } for (PurApAccountingLine oldSourceAccountingLine : item.getSourceAccountingLines()) { if (oldSourceAccountingLine instanceof OlePurchaseOrderAccount) { ((OlePurchaseOrderAccount) oldSourceAccountingLine) .setExistingAmount(oldSourceAccountingLine.getAmount()); } } List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines(); BigDecimal totalPercent = new BigDecimal(100); BigDecimal initialPercent = new BigDecimal(0); for (PurApAccountingLine purApAccountingLine : existingAccountingLine) { initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent()); } initialPercent = totalPercent.subtract(initialPercent); BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT); if (maxPercent.intValue() == OleSelectConstant.ZERO) { item.resetAccount(OleSelectConstant.ZERO_PERCENT); } else { item.resetAccount(initialPercent); } } else if (itemIndex == -2) { //this is the case for distribute account ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line); } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:org.kuali.ole.module.purap.document.web.struts.OleRequisitionAction.java
/** * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#insertSourceLine(org.apache.struts.action.ActionMapping, * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//* w ww. ja v a 2 s . c o m*/ @Override public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // It would be preferable to find a way to genericize the KualiAccountingDocument methods but this will work for now PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form; // index of item selected int itemIndex = getSelectedLine(request); PurApItem item = null; // if custom processing of an accounting line is not done then insert a line generically. if (processCustomInsertAccountingLine(purapForm, request) == false) { String errorPrefix = null; PurApAccountingLine line = null; boolean rulePassed = false; if (itemIndex >= 0) { item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex)); // calculating the dollar amount for the accounting Line. PurApAccountingLine lineItem = item.getNewSourceLine(); if (item.getTotalAmount() != null && !item.getTotalAmount().equals(KualiDecimal.ZERO)) { if (lineItem.getAccountLinePercent() != null && (lineItem.getAmount() == null || lineItem.getAmount().equals(KualiDecimal.ZERO))) { BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100)); lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent)))); } else if (lineItem.getAmount() != null && lineItem.getAmount().isNonZero() && lineItem.getAccountLinePercent() == null) { KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100)); BigDecimal dollarToPercent = dollar.bigDecimalValue() .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR); lineItem.setAccountLinePercent(dollarToPercent); } else if (lineItem.getAmount() != null && lineItem.getAmount().isZero() && lineItem.getAccountLinePercent() == null) { lineItem.setAccountLinePercent(new BigDecimal(0)); } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent().intValue() == 100) { KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100)); BigDecimal dollarToPercent = dollar.bigDecimalValue() .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR); lineItem.setAccountLinePercent(dollarToPercent); } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent() != null) { BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100)); lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent)))); } } else { lineItem.setAmount(new KualiDecimal(0)); } line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem); //end //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line); errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME; rulePassed = SpringContext.getBean(KualiRuleService.class) .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line)); } else if (itemIndex == -2) { //corrected: itemIndex == -2 is the only case for distribute account //This is the case when we're inserting an accounting line for distribute account. line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine(); //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line); errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE; rulePassed = SpringContext.getBean(KualiRuleService.class) .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line)); } if (rulePassed) { AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine(); if (accountingLineBase != null) { String accountNumber = accountingLineBase.getAccountNumber(); String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode(); Map<String, String> criteria = new HashMap<String, String>(); criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber); criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode); Account account = SpringContext.getBean(BusinessObjectService.class) .findByPrimaryKey(Account.class, criteria); rulePassed = checkForValidAccount(account); } } if (rulePassed) { // add accountingLine SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line); PurApAccountingLine newSourceLine = item.getNewSourceLine(); List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines(); BigDecimal initialValue = OleSelectConstant.ZERO_PERCENT; for (PurApAccountingLine accountLine : existingSourceLine) { initialValue = initialValue.add(accountLine.getAccountLinePercent()); } if (itemIndex >= 0) { if ((newSourceLine.getAccountLinePercent() .intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT .subtract(initialValue).intValue()) && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) { if (OleSelectConstant.MAX_PERCENT.subtract(initialValue) .intValue() != OleSelectConstant.ZERO) { insertAccountingLine(purapForm, item, line); } } else { checkAccountingLinePercent(newSourceLine); } for (PurApAccountingLine oldSourceAccountingLine : item.getSourceAccountingLines()) { if (oldSourceAccountingLine instanceof OleRequisitionAccount) { ((OleRequisitionAccount) oldSourceAccountingLine) .setExistingAmount(oldSourceAccountingLine.getAmount()); } } List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines(); BigDecimal totalPercent = new BigDecimal(100); BigDecimal initialPercent = new BigDecimal(0); for (PurApAccountingLine purApAccountingLine : existingAccountingLine) { initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent()); } initialPercent = totalPercent.subtract(initialPercent); BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT); if (maxPercent.intValue() == OleSelectConstant.ZERO) { item.resetAccount(OleSelectConstant.ZERO_PERCENT); } else { item.resetAccount(initialPercent); } } else if (itemIndex == -2) { //this is the case for distribute account ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line); } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:org.kuali.ole.select.document.web.struts.OlePaymentRequestAction.java
/** * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#insertSourceLine(org.apache.struts.action.ActionMapping, * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///w w w.jav a2s. c o m @Override public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // It would be preferable to find a way to genericize the KualiAccountingDocument methods but this will work for now PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form; // index of item selected int itemIndex = getSelectedLine(request); PurApItem item = null; // if custom processing of an accounting line is not done then insert a line generically. if (processCustomInsertAccountingLine(purapForm, request) == false) { String errorPrefix = null; PurApAccountingLine line = null; boolean rulePassed = false; if (itemIndex >= 0) { item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex)); //Calculating the dollar amount for the accounting Line. PurApAccountingLine lineItem = item.getNewSourceLine(); if (lineItem.getAccountLinePercent() != null) { BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100)); lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent)))); } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent() == null) { KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100)); BigDecimal dollarToPercent = dollar.bigDecimalValue() .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR); lineItem.setAccountLinePercent(dollarToPercent); } line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem); //end //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line); errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME; rulePassed = SpringContext.getBean(KualiRuleService.class) .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line)); } else if (itemIndex == -2) { //corrected: itemIndex == -2 is the only case for distribute account //This is the case when we're inserting an accounting line for distribute account. line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine(); //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line); errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE; rulePassed = SpringContext.getBean(KualiRuleService.class) .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line)); } AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine(); if (accountingLineBase != null) { String accountNumber = accountingLineBase.getAccountNumber(); String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode(); Map<String, String> criteria = new HashMap<String, String>(); criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber); criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode); Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, criteria); rulePassed = checkForValidAccount(account); } /* if (rulePassed) { // add accountingLine SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line); if (itemIndex >=0) { insertAccountingLine(purapForm, item, line); // clear the temp account item.resetAccount(); } else if (itemIndex == -2) { //this is the case for distribute account ((PurchasingFormBase)purapForm).addAccountDistributionsourceAccountingLine(line); } }*/ if (rulePassed) { // add accountingLine SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line); PurApAccountingLine newSourceLine = item.getNewSourceLine(); List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines(); BigDecimal initialValue = new BigDecimal(0); for (PurApAccountingLine accountLine : existingSourceLine) { initialValue = initialValue.add(accountLine.getAccountLinePercent()); } if (itemIndex >= 0) { if ((newSourceLine.getAccountLinePercent() .intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT .subtract(initialValue).intValue()) && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) { if (OleSelectConstant.MAX_PERCENT.subtract(initialValue) .intValue() != OleSelectConstant.ZERO) { insertAccountingLine(purapForm, item, line); } } else { checkAccountingLinePercent(newSourceLine); } for (PurApAccountingLine oldSourceAccountingLine : item.getSourceAccountingLines()) { if (oldSourceAccountingLine instanceof PaymentRequestAccount) { ((PaymentRequestAccount) oldSourceAccountingLine) .setExistingAmount(oldSourceAccountingLine.getAmount()); } } List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines(); BigDecimal totalPercent = new BigDecimal(100); BigDecimal initialPercent = new BigDecimal(0); for (PurApAccountingLine purApAccountingLine : existingAccountingLine) { initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent()); } initialPercent = totalPercent.subtract(initialPercent); BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT); if (maxPercent.intValue() == OleSelectConstant.ZERO) { item.resetAccount(OleSelectConstant.ZERO_PERCENT); } else { item.resetAccount(initialPercent); } } else if (itemIndex == -2) { //this is the case for distribute account ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line); } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
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 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 = 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;/*from w ww .j a va 2 s.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; }