-
Notifications
You must be signed in to change notification settings - Fork 3
/
SimpleContainer.cfc
57 lines (43 loc) · 1.34 KB
/
SimpleContainer.cfc
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
component implements = "IContainer" {
SimpleContainer function init() {
variables.store = {};
return this;
}
void function clear() {
if(structKeyExists(variables, "store")) {
structClear(variables.store);
}
}
boolean function containsKey(required string key) {
return structKeyExists(variables, "store") && structKeyExists(variables.store, arguments.key);
}
void function destroy() {
structDelete(variables, "store");
}
any function get(required string key) {
if(this.containsKey(arguments.key)) {
return variables.store[arguments.key];
}
}
boolean function isEmpty() {
return !structKeyExists(variables, "store") || structIsEmpty(variables.store);
}
string function keyList() {
return this.isEmpty() ? "" : listSort(structKeyList(variables.store), "textnocase");
}
void function put(required string key, required any value) {
variables.store[arguments.key] = arguments.value;
}
void function putAll(required struct values, boolean clear = false, boolean overwrite = false) {
if(arguments.clear) {
this.clear();
}
structAppend(variables.store, arguments.values, arguments.overwrite);
}
void function remove(required string key) {
structDelete(variables.store, arguments.key);
}
struct function values() {
return duplicate(variables.store);
}
}