ingo@3: package de.intevation.flys.client.shared.model; ingo@3: ingo@17: import java.util.ArrayList; ingo@3: import java.util.Date; ingo@67: import java.util.HashMap; ingo@17: import java.util.List; ingo@67: import java.util.Map; ingo@3: ingo@3: ingo@3: /** ingo@3: * The default implementation of a {@link Collection}. ingo@3: * ingo@3: * @author Ingo Weinzierl ingo@3: */ ingo@3: public class DefaultCollection implements Collection { ingo@3: ingo@3: /** The uuid of the collection. */ ingo@3: protected String uuid; ingo@3: ingo@95: /** The name of the collection.*/ ingo@95: protected String name; ingo@95: ingo@95: /** The creation time of this collection.*/ ingo@95: protected Date creation; ingo@95: ingo@17: /** The list of artifacts that are managed by this Collection.*/ ingo@67: protected List items; ingo@67: ingo@67: ingo@67: /** ingo@67: * Constructor without arguments is necessary for GWT. ingo@67: */ ingo@67: public DefaultCollection() { ingo@67: } ingo@17: ingo@3: ingo@3: /** ingo@3: * Creates a new DefaultCollection with a UUID. ingo@3: * ingo@3: * @param uuid The UUID. ingo@3: */ ingo@3: public DefaultCollection(String uuid) { ingo@67: this.uuid = uuid; ingo@67: this.items = new ArrayList(); ingo@3: } ingo@3: ingo@3: ingo@95: /** ingo@95: * Creates a new DefaultCollection with uuid and name. ingo@95: * ingo@95: * @param uuid The identifier of this collection. ingo@95: * @param name The name of this collection. ingo@95: */ ingo@95: public DefaultCollection(String uuid, String name) { ingo@95: this(uuid); ingo@95: ingo@95: this.name = name; ingo@95: } ingo@95: ingo@95: ingo@95: /** ingo@95: * Creates a new DefaultCollection with uuid and name. ingo@95: * ingo@95: * @param uuid The identifier of this collection. ingo@95: * @param name The name of this collection. ingo@95: * @param creation The creation time. ingo@95: */ ingo@95: public DefaultCollection(String uuid, String name, Date creation) { ingo@95: this(uuid, name); ingo@95: ingo@95: this.creation = creation; ingo@95: } ingo@95: ingo@95: ingo@5: public String identifier() { ingo@5: return uuid; ingo@5: } ingo@5: ingo@5: ingo@95: public Date getCreationTime() { ingo@95: return creation; ingo@95: } ingo@95: ingo@95: ingo@3: public Date getLastAccess() { ingo@3: return new Date(); ingo@3: } ingo@3: ingo@3: ingo@3: public String getName() { ingo@95: return name; ingo@3: } ingo@17: ingo@17: ingo@67: public void addItem(CollectionItem item) { ingo@67: if (item != null) { ingo@67: items.add(item); ingo@17: } ingo@17: } ingo@17: ingo@17: ingo@67: public int getItemLength() { ingo@67: return items.size(); ingo@17: } ingo@17: ingo@17: ingo@67: public CollectionItem getItem(int idx) { ingo@67: if (idx >= getItemLength()) { ingo@67: return null; ingo@67: } ingo@67: ingo@67: return items.get(idx); ingo@67: } ingo@67: ingo@67: ingo@67: public Map getOutputModes() { ingo@67: Map modes = new HashMap(); ingo@67: ingo@67: for (CollectionItem item: items) { ingo@67: List itemModes = item.getOutputModes(); ingo@67: ingo@67: if (itemModes != null) { ingo@67: for (OutputMode itemMode: itemModes) { ingo@67: String name = itemMode.getName(); ingo@67: if (!modes.containsKey(name)) { ingo@67: // we dont want duplicated OutputModes in our result. ingo@67: modes.put(name, itemMode); ingo@67: } ingo@67: } ingo@67: } ingo@67: } ingo@67: ingo@67: return modes; ingo@17: } ingo@3: } ingo@3: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :