view flys-client/src/main/java/de/intevation/flys/client/shared/model/DefaultCollection.java @ 67:74257b95567b

Added CollectionItems and Facets and replaced Artifact references in Collection with CollectionItems. flys-client/trunk@1567 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 25 Mar 2011 09:19:29 +0000
parents 6cb8aff3cd6b
children e2abb6b9dc7e
line wrap: on
line source
package de.intevation.flys.client.shared.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * The default implementation of a {@link Collection}.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class DefaultCollection implements Collection {

    /** The uuid of the collection. */
    protected String uuid;

    /** The list of artifacts that are managed by this Collection.*/
    protected List<CollectionItem> items;


    /**
     * Constructor without arguments is necessary for GWT.
     */
    public DefaultCollection() {
    }


    /**
     * Creates a new DefaultCollection with a UUID.
     *
     * @param uuid The UUID.
     */
    public DefaultCollection(String uuid) {
        this.uuid  = uuid;
        this.items = new ArrayList<CollectionItem>();
    }


    public String identifier() {
        return uuid;
    }


    public Date getLastAccess() {
        return new Date();
    }


    public String getName() {
        return uuid;
    }


    public void addItem(CollectionItem item) {
        if (item != null) {
            items.add(item);
        }
    }


    public int getItemLength() {
        return items.size();
    }


    public CollectionItem getItem(int idx) {
        if (idx >= getItemLength()) {
            return null;
        }

        return items.get(idx);
    }


    public Map<String, OutputMode> getOutputModes() {
        Map<String, OutputMode> modes = new HashMap<String, OutputMode>();

        for (CollectionItem item: items) {
            List<OutputMode> itemModes = item.getOutputModes();

            if (itemModes != null) {
                for (OutputMode itemMode: itemModes) {
                    String name = itemMode.getName();
                    if (!modes.containsKey(name)) {
                        // we dont want duplicated OutputModes in our result.
                        modes.put(name, itemMode);
                    }
                }
            }
        }

        return modes;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org