view flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java @ 828:910b03de6857

Added a service to get some basic spatial information used for map creation. flys-client/trunk@2529 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 23 Aug 2011 09:43:12 +0000
parents 2f65c742803f
children 9101b4d64666
line wrap: on
line source
package de.intevation.flys.client.shared.model;

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

import java.io.Serializable;

public class ToLoad implements Serializable
{
    public static class Tuple {

        protected String ids;
        protected String num;

        public Tuple() {
        }

        public Tuple(String ids, String num) {
            this.ids = ids;
            this.num = num;
        }

        @Override
        public boolean equals(Object other) {
            if (!(other instanceof Tuple)) {
                return false;
            }
            Tuple o = (Tuple)other;
            return ToLoad.equals(o.ids, ids) && ToLoad.equals(o.num, num);
        }

        public void toString(StringBuilder sb) {
            sb.append("[ids='").append(ids)
              .append("', num='").append(num).append("']");
        }
    }

    public static class Factory {

        protected String      name;
        protected List<Tuple> tuples;

        public Factory() {
            tuples = new ArrayList<Tuple>();
        }

        public Factory(String name) {
            this();
            this.name = name;
        }

        void add(String ids, String num) {
            Tuple t = new Tuple(ids, num);
            if (!tuples.contains(t)) {
                tuples.add(t);
            }
        }

        public void toString(StringBuilder sb) {
            for (Iterator<Tuple> iter = tuples.iterator(); iter.hasNext();) {
                Tuple t = iter.next();
                t.toString(sb);
                if (iter.hasNext()) {
                    sb.append(", ");
                }
            }
        }
    }

    protected String artifactId;

    protected Map<String, Factory> factories;

    public ToLoad() {
        factories = new HashMap<String, Factory>();
    }

    public ToLoad(String artifactId) {
        this.artifactId = artifactId;
    }

    public String getArtifactId() {
        return artifactId;
    }

    public void setArtifactId(String artifactId) {
        this.artifactId = artifactId;
    }

    public void add(String factoryName, String ids, String num) {
        Factory factory = factories.get(factoryName);
        if (factory == null) {
            factory = new Factory(factoryName);
        }
        factory.add(ids, num);
    }

    protected static final boolean equals(String a, String b) {
        if ((a == null && b != null) || (a != null && b == null)) {
            return false;
        }
        return (a == null && b == null) || a.equals(b);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("[")
          .append("artifactId='").append(artifactId).append("', factories=[");

        for (Iterator<Map.Entry<String, Factory>> 
            iter = factories.entrySet().iterator(); iter.hasNext();) {
            Map.Entry<String, Factory> entry = iter.next();
            String  name    = entry.getKey();
            Factory factory = entry.getValue();

            sb.append("[name='").append(name).append("', factory=[");
            factory.toString(sb);
            sb.append(']');
            if (iter.hasNext()) {
                sb.append(", ");
            }
        }
        return sb.append("]]").toString();
    }

    public boolean isEmpty() {
        return factories.isEmpty();
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org