-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectResult.java
More file actions
68 lines (57 loc) · 1.5 KB
/
Copy pathSelectResult.java
File metadata and controls
68 lines (57 loc) · 1.5 KB
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
package com.kmarinos.sqlutils.sql;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class SelectResult {
private final Map<Key<?>, Object> values = new HashMap<>();
private final Map<String, Key<?>> keys = new HashMap<>();
@SuppressWarnings("unused")
private <T> void put(Key<T> key, T value) {
values.put(key, value);
}
public <T> void put(String identifier, Class<T> type, Object value) {
Key<T> key = new SelectResult.Key<T>(identifier, type);
keys.put(identifier, key);
values.put(key, value);
}
private <T> T get(Key<T> key) {
if(key==null) {
return null;
}
return key.type.cast(values.get(key));
}
@SuppressWarnings("unchecked")
public <T> T get(String keyName) {
Key<?> key = keys.get(keyName);
if(key==null) {
}
return (T) get(key);
}
public <T> T get(String keyName,Class<T>type) {
return get(keyName);
}
public Map<String,?> getAll(){
if(keys==null) {
return new HashMap<>();
}
Map<String,?> map = new HashMap<>();
for(String strKey:keys.keySet()) {
map.put(strKey, get(strKey));
}
return map;
// return keys.keySet().stream().filter(x->x!=null).collect(Collectors.toMap(x->x, x->get(x)));
}
public Class<?> typeOf(String keyName){
return keys.get(keyName).type;
}
public class Key<T> {
final String identifier;
final Class<T> type;
public Key(String identifier, Class<T> type) {
this.identifier = identifier;
this.type = type;
}
}
}