diff options
author | Matt Windsor <mbw500@student.cs.york.ac.uk> | 2011-03-07 13:50:24 +0000 |
---|---|---|
committer | Matt Windsor <mbw500@student.cs.york.ac.uk> | 2011-03-07 13:50:24 +0000 |
commit | 9b4647f1ae8c3f41163d0d4053504dab861d0c94 (patch) | |
tree | b621e8c0b75a5cadd69f938116b1637f7ad0c94d /src/uk/org/ury/database/DatabaseItem.java | |
parent | c33f098de8a43a2df778d4d694e0c07bbde59828 (diff) |
Emergency impending hard drive failure dump - lots of changes on the frontend, but they're all potentially controversial so I'm not pushing to master yet. Beginnings of show viewer. Application now run through demo menu, which allows for the links between modules to be tested.
Diffstat (limited to 'src/uk/org/ury/database/DatabaseItem.java')
-rw-r--r-- | src/uk/org/ury/database/DatabaseItem.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/uk/org/ury/database/DatabaseItem.java b/src/uk/org/ury/database/DatabaseItem.java new file mode 100644 index 0000000..4f6d34d --- /dev/null +++ b/src/uk/org/ury/database/DatabaseItem.java @@ -0,0 +1,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 ()); + } +} |