日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BPP 相关——01

發布時間:2024/7/23 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BPP 相关——01 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、InputPageUtil

2、EditPageUtil



----------------------------------------------------------------------------------------------------------

1、InputPageUtil

功能簡述:在輸入畫面中,總是顯示最后一頁,本頁輸入滿了則自動跳到下一頁(如果還有)。

參數:

int ?recordsOfPage —— 每頁顯示的記錄條數(不能小于1,默認10)
int ?inputtedCount —— 已經輸入產品的個數(不能小于 0)
int ?totalCount —— 訂單關聯的產品總個數(不能小于 1)

各方法描述:

a、計算總頁數

int totalPageCount(){if( totalCount % recordsOfPage == 0 ){return totalCount / recordsOfPage;}return totalCount / recordsOfPage + 1;}

b、計算當前頁數

注意:如果 inputtedCount 剛好滿頁。則要繼續判斷 --->?

b-1、如果全部輸入完了,那么當前頁就是本頁

b-2、如果沒有全部輸入完,那么當前頁就為 (本頁+1)

特殊值,inputtedCount 為 0 。計算結果為1,也正確。

int currentPageCount(){ if( inputtedCount % recordsOfPage == 0 ){if( inputtedCount == totalCount ){return inputtedCount / recordsOfPage;}else{return inputtedCount / recordsOfPage + 1;}}return inputtedCount / recordsOfPage + 1;}c、計算最后頁的第一行對應已經輸入的 products (List)的索引(用來將最后部分數據 Copy 出來)

顯然這個起始索引只能是,0、10、20、30....

int startIndexForLastPage( int currentPageCount ){return ( currentPageCount - 1 ) * recordsOfPage;}d、最后頁的 Number 數(轉換成List,方便strut2 的循環標簽使用)


int lastPageNumberCount( int currentPageCount, int totalPageCount ){if( currentPageCount < totalPageCount ){return recordsOfPage;}else if( currentPageCount == totalPageCount ){if( totalCount % recordsOfPage == 0 ){return recordsOfPage;}return totalCount % recordsOfPage;}else{// this can't happenreturn -1;}}

d、判斷是否已經全部輸入

boolean isAllProductsInputted(){return inputtedCount == totalCount;}

完整代碼:

package jp.co.snjp.kddi.ht.util;public class InputPageUtil {private static final int DEFAULT_RECORDS_OF_PAGE = 10;private final int recordsOfPage;private final int inputtedCount;private final int totalCount;private InputPageUtil( int inputtedCount, int totalCount ){this( inputtedCount, totalCount, DEFAULT_RECORDS_OF_PAGE );}private InputPageUtil( int inputtedCount, int totalCount, int recordsOfPage ){if( isInvalidParams( inputtedCount, totalCount, recordsOfPage ) ){throw new IllegalStateException("Parameters state error.");}this.inputtedCount = inputtedCount;this.totalCount = totalCount;this.recordsOfPage = recordsOfPage;}private boolean isInvalidParams( int inputtedCount, int totalCount, int recordsOfPage ){if( inputtedCount < 0 || totalCount < 1 || recordsOfPage < 1){return true;}if( totalCount < inputtedCount){return true;}return false;}public int getRecordsOfPage(){return recordsOfPage;}public int getInputtedCount() {return inputtedCount;}public int getTotalCount() {return totalCount;}public static InputPageUtil newInstanceDefaultRecordsOfPage( int inputtedCount, int totalCount ){return new InputPageUtil( inputtedCount, totalCount );}public static InputPageUtil newInstanceSetRecordsOfPage( int inputtedCount, int totalCount, int recordsOfPage ){return new InputPageUtil( inputtedCount, totalCount, recordsOfPage );}boolean isAllProductsInputted(){return inputtedCount == totalCount;}int totalPageCount(){if( totalCount % recordsOfPage == 0 ){return totalCount / recordsOfPage;}return totalCount / recordsOfPage + 1;}int currentPageCount(){ if( inputtedCount % recordsOfPage == 0 ){if( inputtedCount == totalCount ){return inputtedCount / recordsOfPage;}else{return inputtedCount / recordsOfPage + 1;}}return inputtedCount / recordsOfPage + 1;}int startIndexForLastPage( int currentPageCount ){return ( currentPageCount - 1 ) * recordsOfPage;}int lastPageNumberCount( int currentPageCount, int totalPageCount ){if( currentPageCount < totalPageCount ){return recordsOfPage;}else if( currentPageCount == totalPageCount ){if( totalCount % recordsOfPage == 0 ){return recordsOfPage;}return totalCount % recordsOfPage;}else{// this can't happenreturn -1;}}public Status computeAllStatus(){int totalPageCount = totalPageCount();int currentPageCount = currentPageCount();int startIndexForLastPage = startIndexForLastPage( currentPageCount );int lastPageNumberCount = lastPageNumberCount( currentPageCount, totalPageCount );boolean allProductsInputted = isAllProductsInputted();return new Status( currentPageCount, totalPageCount, startIndexForLastPage, lastPageNumberCount, allProductsInputted );}public static class Status{private final int totalPageCount;private final int currentPageCount;private final int startIndexForLastPage;private final int lastPageNumberCount;private final boolean allProductsInputted;private Status( int currentPageCount, int totalPageCount, int startIndexForLastPage, int lastPageNumberCount, boolean allProductsInputted ){this.currentPageCount = currentPageCount;this.totalPageCount = totalPageCount;this.startIndexForLastPage =startIndexForLastPage;this.lastPageNumberCount = lastPageNumberCount;this.allProductsInputted = allProductsInputted;}public int getCurrentPageCount() {return currentPageCount;}public int getLastPageNumberCount() {return lastPageNumberCount;}public int getStartIndexForLastPage() {return startIndexForLastPage;}public int getTotalPageCount() {return totalPageCount;}public boolean isAllProductsInputted() {return allProductsInputted;}}}

使用示例:

void initContinueManualInputParam( T03SlipWk orderForm, List<T04CaseDtlWk> products ){assert orderForm != null;assert products != null;assert products.size() != 0;productName = orderForm.getProdNm1();productCount = orderForm.getShpVol1().intValue();InputPageUtil.Status inputPageStatus = InputPageUtil.newInstanceDefaultRecordsOfPage( products.size(), productCount ).computeAllStatus();allProductsInput = inputPageStatus.isAllProductsInputted();totalPageCount = inputPageStatus.getTotalPageCount();currentPageCount = inputPageStatus.getCurrentPageCount();int startIndexForLastPage = inputPageStatus.getStartIndexForLastPage();int lastPageNumberCount = inputPageStatus.getLastPageNumberCount();lastPageProducts = lastPageProducts( startIndexForLastPage, products );lastPageRecords = lastPageRecords( lastPageNumberCount );}// 相關的兩個方法List<String> lastPageProducts( int startIndexForLastPage, List<T04CaseDtlWk> products ){List<String> result = new ArrayList<String>();while( startIndexForLastPage < products.size() ){T04CaseDtlWk product = (T04CaseDtlWk)products.get( startIndexForLastPage );result.add( formatNumber( product.getShpWt2() ) );startIndexForLastPage++;}return result;}List<Integer> lastPageRecords( int lastPageNumberCount ){List<Integer> result = new ArrayList<Integer>();for( int i = 0 ; i < lastPageNumberCount ; i++ ){result.add( i );}return result;}
2、EditPageUtil

功能簡述:

進入編輯頁面,根據 page_line 參數來確定顯示的“當前頁”和 選中狀態的“當前行”,如果 page_line 為 null (從輸入頁面進入編輯頁面),則默認顯示第一頁,選中第一行。

參數:

int recordsOfPage —— 頁面記錄條數(不能小于1,默認為10)
int inputtedCount —— 已經輸入產品個數(不能小于1,這里如果一個都沒有輸入會構造一個 BlankProduct,這樣進入編輯頁就可以直接輸入)
int totalCount ——?訂單關聯的產品總個數(不能小于 1)
String page_line —— JSP 頁面傳遞的參數,用來確定頁和行

各方法描述:

a、計算總頁數

int totalPageCount(){if( totalCount % recordsOfPage == 0 ){return totalCount / recordsOfPage;}return totalCount / recordsOfPage + 1;}b、計算當前頁

// 1. 第一次從輸入頁面->編輯頁面 ( page_line為null, 默認第一頁面)// 2. 編輯修改保存后->再次進入 (根據 page_line 參數解析)int currentPageCount(){// 1if( page_line == null ){return 1;}// 2int page = parsePage();if( page < 1){return 1;}else if( maxEditablePageCount() < page ){return maxEditablePageCount();}else{return page;}}c、計算當前行

int currentLine( int currentPageCount ){// 1if( page_line == null ){return 1;}// 2int line = parseLine();if( line < 1 ){return 1;}else if( maxEditableLine( currentPageCount ) < line ){return maxEditableLine( currentPageCount );}else{return line;}}d、計算當前頁的記錄條數(也就是 JSP 頁面,HT 的 Select控件 option 的個數)
// select 控件要用int productRecordCountOfCurrentPage( int currentPageCount ){if( inputtedCount < ( currentPageCount * recordsOfPage ) ){return inputtedCount - ( currentPageCount - 1 ) * recordsOfPage;}return recordsOfPage;}e、計算當前頁的第一行對應已經輸入的 products (List)的索引(用來將最后部分數據 Copy 出來)

顯然這個起始索引只能是,0、10、20、30....

int startIndexForCopy( int currentPageCount ){return ( currentPageCount - 1 ) * recordsOfPage;}f、判斷是否有上一頁 和是否有下一頁

boolean hasPrePage( int currentPageCount ){return 1 < currentPageCount ? true : false;}boolean hasNextPage( int currentPageCount ){return currentPageCount < maxEditablePageCount() ? true : false;}g、構造 page_line 參數

String pageLine( int currentPageCount, int currentLine ){return currentPageCount + "_" + currentLine;}


完整代碼:

package jp.co.snjp.kddi.ht.util;import java.util.regex.Matcher; import java.util.regex.Pattern;public class EditPageUtil {private static final int DEFAULT_RECORDS_OF_PAGE = 10;private final int recordsOfPage;private final int inputtedCount;private final int totalCount;private final String page_line;public int getInputtedCount() {return inputtedCount;}public int getRecordsOfPage() {return recordsOfPage;}public int getTotalCount() {return totalCount;}private EditPageUtil( int inputtedCount, int totalCount, String page_line ){this( inputtedCount, totalCount, page_line, DEFAULT_RECORDS_OF_PAGE );}private EditPageUtil( int inputtedCount, int totalCount, String page_line, int recordsOfPage ){if( isInvalidParams( inputtedCount, totalCount, page_line, recordsOfPage ) ){throw new IllegalStateException("Parameters state error.");}this.inputtedCount = inputtedCount;this.totalCount = totalCount;this.page_line = page_line;this.recordsOfPage = recordsOfPage;}private boolean isInvalidParams( int inputtedCount, int totalCount, String page_line, int recordsOfPage ){// 這里 inputtedCount 至少會有一個 BlankProduct, 用于在編輯模式下輸入if( inputtedCount < 1 || totalCount < 1 || recordsOfPage < 1){return true;}if( totalCount < inputtedCount){return true;}if( page_line != null && !page_line.trim().equals("") ){return notMatcher( page_line, "\\d+_\\d+" );}return false;}private boolean notMatcher( String sequence, String regex ){Pattern p = Pattern.compile(regex);Matcher m = p.matcher( sequence.trim() );return !m.matches();}public static EditPageUtil newInstanceDefaultRecordsOfPage( int inputtedCount, int totalCount, String page_line ){return new EditPageUtil( inputtedCount, totalCount, page_line );}public static EditPageUtil newInstanceSetRecordsOfPage( int inputtedCount, int totalCount, String page_line, int recordsOfPage ){return new EditPageUtil( inputtedCount, totalCount,page_line, recordsOfPage );}int totalPageCount(){if( totalCount % recordsOfPage == 0 ){return totalCount / recordsOfPage;}return totalCount / recordsOfPage + 1;}// 1. 第一次從輸入頁面->編輯頁面 ( page_line為null, 默認第一頁面)// 2. 編輯修改保存后->再次進入 (根據 page_line 參數解析)int currentPageCount(){// 1if( page_line == null ){return 1;}// 2int page = parsePage();if( page < 1){return 1;}else if( maxEditablePageCount() < page ){return maxEditablePageCount();}else{return page;}}int currentLine( int currentPageCount ){// 1if( page_line == null ){return 1;}// 2int line = parseLine();if( line < 1 ){return 1;}else if( maxEditableLine( currentPageCount ) < line ){return maxEditableLine( currentPageCount );}else{return line;}}private int maxEditableLine( int currentPageCount ){return productRecordCountOfCurrentPage( currentPageCount );}// select 控件要用int productRecordCountOfCurrentPage( int currentPageCount ){if( inputtedCount < ( currentPageCount * recordsOfPage ) ){return inputtedCount - ( currentPageCount - 1 ) * recordsOfPage;}return recordsOfPage;}int startIndexForCopy( int currentPageCount ){return ( currentPageCount - 1 ) * recordsOfPage;}boolean hasPrePage( int currentPageCount ){return 1 < currentPageCount ? true : false;}boolean hasNextPage( int currentPageCount ){return currentPageCount < maxEditablePageCount() ? true : false;}String pageLine( int currentPageCount, int currentLine ){return currentPageCount + "_" + currentLine;}// 可以"翻頁"的最大頁數private int maxEditablePageCount(){if( inputtedCount % recordsOfPage == 0 ){return inputtedCount / recordsOfPage;}return inputtedCount / recordsOfPage + 1;}private int parsePage(){String[] params = page_line.split( "_" );String page = params[0].trim();return Integer.valueOf( page ).intValue();}private int parseLine(){String[] params = page_line.split( "_" );String line = params[1].trim();return Integer.valueOf( line ).intValue();}public Status computeAllStatus(){int totalPageCount = totalPageCount();int currentPageCount = currentPageCount();int currentLine = currentLine( currentPageCount );int productRecordCountOfCurrentPage = productRecordCountOfCurrentPage( currentPageCount );int startIndexForCopy = startIndexForCopy( currentPageCount );String pageLine = pageLine( currentPageCount, currentLine );boolean hasPrePage = hasPrePage( currentPageCount );boolean hasNextPage = hasNextPage( currentPageCount );return new Status( totalPageCount, currentPageCount, currentLine,productRecordCountOfCurrentPage, startIndexForCopy,pageLine, hasPrePage, hasNextPage);}public static class Status{private final int totalPageCount;private final int currentPageCount;private final int currentLine;private final int productRecordCountOfCurrentPage;private final int startIndexForCopy;private final String pageLine;private final boolean hasPrePage;private final boolean hasNextPage;private Status( int totalPageCount, int currentPageCount, int currentLine, int productRecordCountOfCurrentPage, int startIndexForCopy, String pageLine, boolean hasPrePage, boolean hasNextPage) {this.totalPageCount = totalPageCount;this.currentPageCount = currentPageCount;this.currentLine = currentLine;this.productRecordCountOfCurrentPage = productRecordCountOfCurrentPage;this.startIndexForCopy = startIndexForCopy;this.pageLine = pageLine;this.hasPrePage = hasPrePage;this.hasNextPage = hasNextPage;}public int getCurrentLine() {return currentLine;}public int getCurrentPageCount() {return currentPageCount;}public boolean getHasNextPage() {return hasNextPage;}public boolean getHasPrePage() {return hasPrePage;}public String getPageLine() {return pageLine;}public int getProductRecordCountOfCurrentPage() {return productRecordCountOfCurrentPage;}public int getStartIndexForCopy() {return startIndexForCopy;}public int getTotalPageCount() {return totalPageCount;}} }
使用示例:

void initEditJspParam( ){T03SlipWk orderForm = (T03SlipWk) session.get( "SLIP_WK" );List<T04CaseDtlWk> products = getEditableProducts( orderForm );LOG.info( "products.size()=" + products.size() );productName = orderForm.getProdNm1();productCount = orderForm.getShpVol1().intValue();String page_line = request.getParameter( "page_line" );EditPageUtil.Status editPageStatus = EditPageUtil.newInstanceDefaultRecordsOfPage( products.size(), productCount, page_line).computeAllStatus();totalPageCount = editPageStatus.getTotalPageCount();currentPageCount = editPageStatus.getCurrentPageCount();currentLine = editPageStatus.getCurrentLine();currentPageProductRecords = editPageStatus.getProductRecordCountOfCurrentPage();currentPageProducts = currentPageProducts( products, editPageStatus );hasPrePage = editPageStatus.getHasPrePage();hasNextPage = editPageStatus.getHasNextPage();pageLine = editPageStatus.getPageLine();LOG.info( "currentPageCount=" + currentPageCount );LOG.info( "currentLine=" + currentLine );LOG.info( "currentPageProductRecords=" + currentPageProductRecords );LOG.info( "hasPrePage=" + hasPrePage );LOG.info( "hasNextPage=" + hasNextPage );}// 計算顯示在當前頁面的商品List<String> currentPageProducts( List<T04CaseDtlWk> products, EditPageUtil.Status status ){List<String> results = new ArrayList<String>();int currentPageProductRecords = status.getProductRecordCountOfCurrentPage();int startIndexForCopy = status.getStartIndexForCopy();int copyedCount = 0;final String BLANK = " ";while( copyedCount < currentPageProductRecords ){T04CaseDtlWk product = products.get( startIndexForCopy );BigDecimal wt2 = product.getShpWt2();if( wt2 == null ){results.add( BLANK );}else{results.add( manualInputAction.formatNumber( wt2 ) );}startIndexForCopy++;copyedCount++;}return results;} // 獲取可編輯 的商品************************************ 注意這個方法對BlankProduct 的操作List<T04CaseDtlWk> getEditableProducts( T03SlipWk orderForm ){List<T04CaseDtlWk> products = manualInputAction.getProductsFromDB( orderForm );// 商品沒有完全輸入, 在最后加入一個 BlankProduct, 用于輸入if( products.size() < orderForm.getShpVol1().intValue() ){String slipId = orderForm.getSlipId();products.add( constructBlankProduct( slipId ) );}return products;}T04CaseDtlWk constructBlankProduct( String slipId ){T04CaseDtlWk product = new T04CaseDtlWk();product.setSlipId( slipId );// 要保證通過 page_line 計算出來的 caseId 找不到這個BlankProductproduct.setCaseId( -1 );product.setShpWt2( null );return product;}









































總結

以上是生活随笔為你收集整理的BPP 相关——01的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。