IT-KIMI_SHI\SINOIT.KIMI
2018-06-01 64c40fb427bff513f575f11e4c1e7bd9a1bfe3e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package frame.data;
 
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import frame.expression.IVariantRequestListener;
import frame.expression.VariantRequestParams;
 
public class Page implements IVariantRequestListener, IDataProvider {  
    
    private static Set<String> parameterNames;
    private int pageSize;  
    private int recordCount;  
    private int pageNo;
  
    static {
        parameterNames = new HashSet<String>();
        parameterNames.add("pagesize");
        parameterNames.add("recordcount");
        parameterNames.add("pageno");
        parameterNames.add("beginno");        
    }
    
    public Page(int recordCount) { 
        this.pageSize = 20;
        this.pageNo = 1;
        this.recordCount = recordCount;
    }  
    
    public Page(int totalCount, DataPool dataPool) {
        this.pageSize = dataPool.getInt("pagesize", 20);
        this.pageNo = dataPool.getInt("pageno", 1);
        this.recordCount = totalCount;
    }
 
    public int getBeginRecordNo() { 
        int recordNo = pageSize * (pageNo - 1) + 1; 
        return recordNo;  
    }  
    
    public int getBeginRecordNo_1() { 
        int recordNo = getBeginRecordNo();
        return recordNo - 1;  
    } 
    
    public int getEndRecordNo() {  
        int recordNo = pageSize * pageNo;
        return Math.min(recordNo, recordCount);  
    }  
    
    public int getPageSize() {  
        return pageSize;  
    }  
  
    public int getPageNo() {  
        return pageNo;
    }  
  
    public int getRecordCount() {  
        return recordCount;  
    }  
  
    public int getPageCount() {  
        return (int)Math.ceil(recordCount * 1.0d / pageSize);
    }  
  
    public void setRecordCount(int count) {
        this.recordCount = count;
    }
  
    public void setPageSize(int value) { 
        if (value <= 0) {
            return;
        }
        
           pageSize = value;  
    }  
    
    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }
 
    public void set(String name, String value) {
        name = name.toLowerCase();
        
        if ("pageno".equals(name)) {
            setPageNo(Integer.parseInt(value));
        }
        else if ("pagesize".equals(name)) {
            setPageSize(Integer.parseInt(value));            
        }
    }
 
     public String toString() {
        StringBuilder result = new StringBuilder();
        
        result.append("size=").append(pageSize).append(",");
        result.append("recordCount=").append(recordCount).append(",");
        result.append("pageNo=").append(pageNo);
        
        return result.toString();
    }
 
    @Override
    public String getStringValue(String name, VariantRequestParams params) {
        if ("pageSize".equalsIgnoreCase(name)) {
            return String.valueOf(pageSize);
        }
        else if ("recordCount".equalsIgnoreCase(name)) {
            return String.valueOf(recordCount);
        }
        else if ("pageNo".equalsIgnoreCase(name)) {
            return String.valueOf(pageNo);
        }
        else if ("beginNo".equalsIgnoreCase(name)) {
            int beginNo = getBeginRecordNo_1();
            return String.valueOf(beginNo);
        }
        else if ("endNo".equalsIgnoreCase(name)) {
            int endNo = getEndRecordNo();
            return String.valueOf(endNo);
        }
        
        return null;
    }
 
    @Override
    public List<String> getVariantNames() {
        return new ArrayList<String>(parameterNames);
    }
 
    public static Set<String> getVarinatNameSet() {
        return parameterNames;
    }
 
    @Override
    public List<String> getDataNameList() {
        // TODO Auto-generated method stub
        return null;
    }
 
    @Override
    public boolean containsData(String name) {
        // TODO Auto-generated method stub
        return false;
    }
 
    @Override
    public Object getDataValue(String name) {
        // TODO Auto-generated method stub
        return null;
    }
    
}