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
|
/*
Copyright (c) 2011 James Ahlborn
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.healthmarketscience.jackcess.impl;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import com.healthmarketscience.jackcess.DataType;
import com.healthmarketscience.jackcess.PropertyMap;
/**
* Map of properties for a database object.
*
* @author James Ahlborn
*/
public class PropertyMapImpl implements PropertyMap
{
private final String _mapName;
private final short _mapType;
private final Map<String,Property> _props =
new LinkedHashMap<String,Property>();
public PropertyMapImpl(String name, short type) {
_mapName = name;
_mapType = type;
}
public String getName() {
return _mapName;
}
public short getType() {
return _mapType;
}
public int getSize() {
return _props.size();
}
public boolean isEmpty() {
return _props.isEmpty();
}
public Property get(String name) {
return _props.get(DatabaseImpl.toLookupName(name));
}
public Object getValue(String name) {
return getValue(name, null);
}
public Object getValue(String name, Object defaultValue) {
Property prop = get(name);
Object value = defaultValue;
if((prop != null) && (prop.getValue() != null)) {
value = prop.getValue();
}
return value;
}
/**
* Puts a property into this map with the given information.
*/
public void put(String name, DataType type, byte flag, Object value) {
_props.put(DatabaseImpl.toLookupName(name),
new PropertyImpl(name, type, flag, value));
}
public Iterator<Property> iterator() {
return _props.values().iterator();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(PropertyMaps.DEFAULT_NAME.equals(getName()) ?
"<DEFAULT>" : getName())
.append(" {");
for(Iterator<Property> iter = iterator(); iter.hasNext(); ) {
sb.append(iter.next());
if(iter.hasNext()) {
sb.append(",");
}
}
sb.append("}");
return sb.toString();
}
/**
* Info about a property defined in a PropertyMap.
*/
private static final class PropertyImpl implements PropertyMap.Property
{
private final String _name;
private final DataType _type;
private final byte _flag;
private final Object _value;
private PropertyImpl(String name, DataType type, byte flag, Object value) {
_name = name;
_type = type;
_flag = flag;
_value = value;
}
public String getName() {
return _name;
}
public DataType getType() {
return _type;
}
public Object getValue() {
return _value;
}
@Override
public String toString() {
Object val = getValue();
if(val instanceof byte[]) {
val = ByteUtil.toHexString((byte[])val);
}
return getName() + "[" + getType() + ":" + _flag + "]=" + val;
}
}
}
|