Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/shared/model/ToLoad.java @ 831:9101b4d64666
Datacage: Re-written ToLoad to feature the new filter models.
flys-client/trunk@2539 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 23 Aug 2011 16:58:07 +0000 |
parents | 2f65c742803f |
children | 77469d7f3c93 |
comparison
equal
deleted
inserted
replaced
830:3dde14f0bd98 | 831:9101b4d64666 |
---|---|
1 package de.intevation.flys.client.shared.model; | 1 package de.intevation.flys.client.shared.model; |
2 | 2 |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 import java.util.Map; | 3 import java.util.Map; |
6 import java.util.HashMap; | 4 import java.util.HashMap; |
7 import java.util.Iterator; | |
8 | 5 |
9 import java.io.Serializable; | 6 import java.io.Serializable; |
10 | 7 |
11 public class ToLoad implements Serializable | 8 public class ToLoad implements Serializable |
12 { | 9 { |
13 public static class Tuple { | 10 protected Map<String, Map<String, ArtifactFilter>> artifacts; |
14 | 11 |
15 protected String ids; | 12 public ToLoad() { |
16 protected String num; | 13 artifacts = new HashMap<String, Map<String, ArtifactFilter>>(); |
14 } | |
17 | 15 |
18 public Tuple() { | 16 public void add( |
17 String artifactName, | |
18 String factory, | |
19 String out, | |
20 String name, | |
21 String num | |
22 ) { | |
23 if (artifactName == null) artifactName = ""; | |
24 if (out == null) out = ""; | |
25 | |
26 Map<String, ArtifactFilter> artifact = artifacts.get(artifactName); | |
27 | |
28 if (artifact == null) { | |
29 artifact = new HashMap<String, ArtifactFilter>(); | |
30 artifacts.put(artifactName, artifact); | |
19 } | 31 } |
20 | 32 |
21 public Tuple(String ids, String num) { | 33 ArtifactFilter filter = artifact.get(factory); |
22 this.ids = ids; | 34 if (filter == null) { |
23 this.num = num; | 35 filter = new ArtifactFilter(factory); |
36 artifact.put(factory, filter); | |
24 } | 37 } |
25 | 38 |
26 @Override | 39 filter.add(out, name, num); |
27 public boolean equals(Object other) { | |
28 if (!(other instanceof Tuple)) { | |
29 return false; | |
30 } | |
31 Tuple o = (Tuple)other; | |
32 return ToLoad.equals(o.ids, ids) && ToLoad.equals(o.num, num); | |
33 } | |
34 | |
35 public void toString(StringBuilder sb) { | |
36 sb.append("[ids='").append(ids) | |
37 .append("', num='").append(num).append("']"); | |
38 } | |
39 } | |
40 | |
41 public static class Factory { | |
42 | |
43 protected String name; | |
44 protected List<Tuple> tuples; | |
45 | |
46 public Factory() { | |
47 tuples = new ArrayList<Tuple>(); | |
48 } | |
49 | |
50 public Factory(String name) { | |
51 this(); | |
52 this.name = name; | |
53 } | |
54 | |
55 void add(String ids, String num) { | |
56 Tuple t = new Tuple(ids, num); | |
57 if (!tuples.contains(t)) { | |
58 tuples.add(t); | |
59 } | |
60 } | |
61 | |
62 public void toString(StringBuilder sb) { | |
63 for (Iterator<Tuple> iter = tuples.iterator(); iter.hasNext();) { | |
64 Tuple t = iter.next(); | |
65 t.toString(sb); | |
66 if (iter.hasNext()) { | |
67 sb.append(", "); | |
68 } | |
69 } | |
70 } | |
71 } | |
72 | |
73 protected String artifactId; | |
74 | |
75 protected Map<String, Factory> factories; | |
76 | |
77 public ToLoad() { | |
78 factories = new HashMap<String, Factory>(); | |
79 } | |
80 | |
81 public ToLoad(String artifactId) { | |
82 this.artifactId = artifactId; | |
83 } | |
84 | |
85 public String getArtifactId() { | |
86 return artifactId; | |
87 } | |
88 | |
89 public void setArtifactId(String artifactId) { | |
90 this.artifactId = artifactId; | |
91 } | |
92 | |
93 public void add(String factoryName, String ids, String num) { | |
94 Factory factory = factories.get(factoryName); | |
95 if (factory == null) { | |
96 factory = new Factory(factoryName); | |
97 } | |
98 factory.add(ids, num); | |
99 } | |
100 | |
101 protected static final boolean equals(String a, String b) { | |
102 if ((a == null && b != null) || (a != null && b == null)) { | |
103 return false; | |
104 } | |
105 return (a == null && b == null) || a.equals(b); | |
106 } | |
107 | |
108 @Override | |
109 public String toString() { | |
110 StringBuilder sb = new StringBuilder("[") | |
111 .append("artifactId='").append(artifactId).append("', factories=["); | |
112 | |
113 for (Iterator<Map.Entry<String, Factory>> | |
114 iter = factories.entrySet().iterator(); iter.hasNext();) { | |
115 Map.Entry<String, Factory> entry = iter.next(); | |
116 String name = entry.getKey(); | |
117 Factory factory = entry.getValue(); | |
118 | |
119 sb.append("[name='").append(name).append("', factory=["); | |
120 factory.toString(sb); | |
121 sb.append(']'); | |
122 if (iter.hasNext()) { | |
123 sb.append(", "); | |
124 } | |
125 } | |
126 return sb.append("]]").toString(); | |
127 } | 40 } |
128 | 41 |
129 public boolean isEmpty() { | 42 public boolean isEmpty() { |
130 return factories.isEmpty(); | 43 return artifacts.isEmpty(); |
131 } | 44 } |
132 } | 45 } |
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 46 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |