+
+ /**
+ * Clones the given project and returns the clone. The clone will be
+ * identical in all user-exposed fields, except for the project’s
+ * {@link Project#getId ID}.
+ *
+ * @param project
+ * The project to clone
+ * @return The cloned project
+ */
+ public Project cloneProject(Project project) {
+ Project projectClone = new Project(project);
+ projects.add(projectClone);
+ projectClone.setId(generateId());
+ projectClone.addPropertyChangeListener(this);
+ try {
+ save();
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ return projectClone;
+ }
+
+ /**
+ * Removes the given project.
+ *
+ * @param project
+ * The project to remove
+ */
+ public void removeProject(Project project) {
+ projects.remove(project);
+ try {
+ save();
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Generates a new random ID, consisting of 16 random bytes converted to a
+ * hexadecimal number.
+ *
+ * @return The new ID
+ */
+ private static String generateId() {
+ byte[] idBytes = new byte[16];
+ random.nextBytes(idBytes);
+ return Hex.toHex(idBytes);
+ }
+
+ //
+ // INTERFACE PropertyChangeListener
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
+ try {
+ save();
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ }
+