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
package edu.caltech.nanodb.commands;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
import edu.caltech.nanodb.expressions.TypeConverter;
/**
* This class holds properties that might contain additional details for a
* command. For example, the <tt>CREATE TABLE</tt> DDL command takes
* properties to specify non-default storage engine types, the page size to
* use for the table file, and so forth.
*/
public class CommandProperties {
/** A map of name-value pairs that represent the actual properties. */
private HashMap<String, Object> values = new HashMap<>();
public void set(String name, Object value) {
if (name == null)
throw new IllegalArgumentException("name cannot be null");
if (value == null)
throw new IllegalArgumentException("value cannot be null");
values.put(name, value);
}
public Object get(String name, Object defaultValue) {
Object value = values.get(name);
if (value == null)
value = defaultValue;
return value;
}
public Object get(String name) {
return get(name, null);
}
public int getInt(String name, int defaultValue) {
Object obj = get(name);
if (obj == null)
return defaultValue;
Integer intObj = TypeConverter.getIntegerValue(obj);
return intObj.intValue();
}
public String getString(String name, String defaultValue) {
Object obj = get(name);
if (obj == null)
return defaultValue;
return obj.toString();
}
public Set<String> getNames() {
return Collections.unmodifiableSet(values.keySet());
}
@Override
public String toString() {
return "CommandProperties[" + values.toString() + "]";
}
}