Helius
2020-12-15 2914588a65371a3ce43f678cde0a26cd8da26611
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
package com.matrix.core.pojo;
 
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * simple mvc 支持的数据传输对象
 * 
 * @author jiangyouyao
 *
 */
@SuppressWarnings("rawtypes")
public class PageData extends HashMap implements Map {
 
    private static final long serialVersionUID = 1L;
 
    Map map = null;
    HttpServletRequest request;
 
    @SuppressWarnings("unchecked")
    public PageData(HttpServletRequest request) {
        this.request = request;
        Map properties = request.getParameterMap();
        Map returnMap = new HashMap();
        Iterator entries = properties.entrySet().iterator();
        Entry entry;
        String name = "";
        String value = "";
        
        while (entries.hasNext()) {
            entry = (Entry) entries.next();
            name = (String) entry.getKey();
            Object valueObj = entry.getValue();
            if (name.equals("offset") || name.equals("limit")) {
                if (valueObj instanceof String[]){
                    String[] values = (String[]) valueObj;
                    returnMap.put(name, Integer.parseInt(values[0].toString()));
                }else{
                    returnMap.put(name, Integer.parseInt(valueObj.toString()));
                }
                continue;
            }
        
            if (null == valueObj) {
                value = "";
            } else if (valueObj instanceof String[]) {
                String[] values = (String[]) valueObj;
                for (int i = 0; i < values.length; i++) {
                    value = values[i] + ",";
                }
                value = value.substring(0, value.length() - 1);
            } else {
                value = valueObj.toString();
            }
            returnMap.put(name, value);
        }
        map = returnMap;
    }
 
    public PageData() {
        map = new HashMap();
    }
 
    @Override
    public Object get(Object key) {
        Object obj = null;
        if (map.get(key) instanceof Object[]) {
            Object[] arr = (Object[]) map.get(key);
            obj = request == null ? arr : (request.getParameter((String) key) == null ? arr : arr[0]);
        } else {
            obj = map.get(key);
        }
        return obj;
    }
 
    public String getString(Object key) {
        return (String) get(key);
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public Object put(Object key, Object value) {
        return map.put(key, value);
    }
 
    @Override
    public Object remove(Object key) {
        return map.remove(key);
    }
 
    public void clear() {
        map.clear();
    }
 
    public boolean containsKey(Object key) {
        return map.containsKey(key);
    }
 
    public boolean containsValue(Object value) {
        return map.containsValue(value);
    }
 
    public Set entrySet() {
        return map.entrySet();
    }
 
    public boolean isEmpty() {
        
        return map.isEmpty();
    }
 
    public Set keySet() {
        
        return map.keySet();
    }
 
    @SuppressWarnings("unchecked")
    public void putAll(Map t) {
        
        map.putAll(t);
    }
 
    public int size() {
        
        return map.size();
    }
 
    public Collection values() {
        
        return map.values();
    }
 
}