blob: 4f6d34dd84e0ff2d99b3763448b76a264d12de7b (
plain)
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
|
package uk.org.ury.database;
import java.util.Map;
import uk.org.ury.database.exceptions.MissingPropertyException;
/**
* An abstract class presenting a template for objects serving as
* a data structure for collections of properties retrieved from
* a SQL database.
*
* @param E The enumeration type used as the property list.
*
* @param T The type of datum stored for each property.
*
* @author Matt Windsor
*/
public abstract class DatabaseItem<E, T>
{
private Map<E, T> properties;
/**
* Construct a new item from an existing list of properties.
*
* @param properties The map of properties that the new item will
* inherit.
*/
public
DatabaseItem (Map<E, T> properties)
{
this.properties = properties;
}
/**
* Check whether a property has been set in the item.
*
* @return true if the property has been set; false otherwise.
*/
public boolean
has (E property)
{
return properties.containsKey (property);
}
/**
* Query this item for a property.
*
* @param property The property to query.
*
* @return The property, if it exists.
*
* @throws MissingPropertyException if the property does
* not exist.
*/
public T
get (E property) throws MissingPropertyException
{
if (properties.containsKey (property))
return properties.get (property);
else
throw new MissingPropertyException (property.toString ());
}
}
|