Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/shared/model/ToLoad.java @ 9227:84397da33d17
Allow to control specific behaviour in TwinDatacagePanel
Implemented client logic of 'intelligent datacage filtering' for SINFO
author | gernotbelger |
---|---|
date | Wed, 04 Jul 2018 18:28:08 +0200 |
parents | 5e38e2924c07 |
children |
comparison
equal
deleted
inserted
replaced
9226:83aee0942eae | 9227:84397da33d17 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.shared.model; | 9 package org.dive4elements.river.client.shared.model; |
10 | 10 |
11 import java.io.Serializable; | |
11 import java.util.ArrayList; | 12 import java.util.ArrayList; |
13 import java.util.HashMap; | |
12 import java.util.List; | 14 import java.util.List; |
13 import java.util.Map; | 15 import java.util.Map; |
14 import java.util.HashMap; | |
15 | |
16 import java.io.Serializable; | |
17 | 16 |
18 import com.google.gwt.core.client.GWT; | 17 import com.google.gwt.core.client.GWT; |
19 | 18 |
20 public class ToLoad implements Serializable | 19 public class ToLoad implements Serializable |
21 { | 20 { |
22 | 21 private static class StringTriple { |
23 /** Two strings. */ | |
24 public static class StringTriple { | |
25 public String first; | 22 public String first; |
26 public String second; | 23 public String second; |
27 public String third; | 24 public String third; |
28 public StringTriple(String first, String second, String third) { | 25 public StringTriple(final String first, final String second, final String third) { |
29 this.first = first; | 26 this.first = first; |
30 this.second = second; | 27 this.second = second; |
31 this.third = third; | 28 this.third = third; |
32 } | 29 } |
33 @Override | 30 @Override |
34 public int hashCode() { | 31 public int hashCode() { |
35 return first.hashCode() + second.hashCode() + third.hashCode(); | 32 return this.first.hashCode() + this.second.hashCode() + this.third.hashCode(); |
36 } | 33 } |
37 @Override | 34 @Override |
38 public boolean equals(Object o) { | 35 public boolean equals(final Object o) { |
39 if (!(o instanceof StringTriple)) { | 36 if (!(o instanceof StringTriple)) { |
40 return false; | 37 return false; |
41 } | 38 } |
42 StringTriple other = (StringTriple) o; | 39 final StringTriple other = (StringTriple) o; |
43 return second.equals(other.second) | 40 return this.second.equals(other.second) |
44 && first.equals(other.first) | 41 && this.first.equals(other.first) |
45 && third.equals(other.third); | 42 && this.third.equals(other.third); |
46 } | 43 } |
47 } | 44 } |
48 public static final String SYNTHETIC_KEY = "key-"; | |
49 | 45 |
50 protected Map<String, Map<StringTriple, ArtifactFilter>> artifacts; | 46 private static final String SYNTHETIC_KEY = "key-"; |
51 | 47 |
52 public ToLoad() { | 48 private final Map<String, Map<StringTriple, ArtifactFilter>> artifacts = new HashMap<String, Map<StringTriple, ArtifactFilter>>(); |
53 artifacts = new HashMap<String, Map<StringTriple, ArtifactFilter>>(); | |
54 } | |
55 | 49 |
56 public static final String uniqueKey(Map<?, ?> map) { | 50 public static final String uniqueKey(final Map<?, ?> map) { |
57 int idx = map.size(); | 51 int idx = map.size(); |
58 | 52 |
59 String key = SYNTHETIC_KEY + idx; | 53 String key = SYNTHETIC_KEY + idx; |
60 while (map.containsKey(key)) { | 54 while (map.containsKey(key)) { |
61 key = SYNTHETIC_KEY + ++idx; | 55 key = SYNTHETIC_KEY + ++idx; |
62 } | 56 } |
63 return key; | 57 return key; |
64 } | 58 } |
65 | 59 |
66 public void add( | 60 public void add( |
67 String artifactName, | 61 final String artifactName, |
68 String factory, | 62 final String factory, |
69 String out, | 63 final String out, |
70 String name, | 64 final String name, |
71 String ids, | 65 final String ids, |
72 String displayName | 66 final String displayName |
73 ) { | 67 ) { |
74 add(artifactName, factory, out, name, ids, displayName, null); | 68 add(artifactName, factory, out, name, ids, displayName, null); |
75 } | 69 } |
76 | 70 |
77 public void add( | 71 public void add( |
78 String artifactName, | 72 String artifactName, |
79 String factory, | 73 final String factory, |
80 String out, | 74 final String out, |
81 String name, | 75 final String name, |
82 String ids, | 76 final String ids, |
83 String displayName, | 77 final String displayName, |
84 String targetOut | 78 final String targetOut |
85 ) { | 79 ) { |
86 GWT.log("Adding artifact: " + artifactName + " Factory: " + factory + | 80 GWT.log("Adding artifact: " + artifactName + " Factory: " + factory + |
87 " Out: " + out + " Name: " + name + " Ids: " + ids + | 81 " Out: " + out + " Name: " + name + " Ids: " + ids + |
88 " Display Name: " + displayName + " Target Out: " + targetOut); | 82 " Display Name: " + displayName + " Target Out: " + targetOut); |
89 | 83 |
90 if (artifactName == null) { | 84 if (artifactName == null) { |
91 artifactName = uniqueKey(artifacts); | 85 artifactName = uniqueKey(this.artifacts); |
92 } | 86 } |
93 | 87 |
94 Map<StringTriple, ArtifactFilter> artifact = artifacts.get( | 88 Map<StringTriple, ArtifactFilter> artifact = this.artifacts.get( |
95 artifactName); | 89 artifactName); |
96 | 90 |
97 if (artifact == null) { | 91 if (artifact == null) { |
98 artifact = new HashMap<StringTriple, ArtifactFilter>(); | 92 artifact = new HashMap<StringTriple, ArtifactFilter>(); |
99 artifacts.put(artifactName, artifact); | 93 this.artifacts.put(artifactName, artifact); |
100 } | 94 } |
101 | 95 |
102 ArtifactFilter filter = artifact.get(factory); | 96 ArtifactFilter filter = artifact.get(factory); |
103 if (filter == null) { | 97 if (filter == null) { |
104 filter = new ArtifactFilter(factory); | 98 filter = new ArtifactFilter(factory); |
108 | 102 |
109 filter.add(out, name, ids); | 103 filter.add(out, name, ids); |
110 } | 104 } |
111 | 105 |
112 public boolean isEmpty() { | 106 public boolean isEmpty() { |
113 return artifacts.isEmpty(); | 107 return this.artifacts.isEmpty(); |
114 } | 108 } |
115 | 109 |
116 public List<Recommendation> toRecommendations() { | 110 public List<Recommendation> toRecommendations() { |
117 List<Recommendation> recommendations = new ArrayList<Recommendation>(); | 111 final List<Recommendation> recommendations = new ArrayList<Recommendation>(); |
118 | 112 |
119 for (Map.Entry<String, Map<StringTriple, ArtifactFilter>> all: | 113 for (final Map.Entry<String, Map<StringTriple, ArtifactFilter>> all: |
120 artifacts.entrySet() | 114 this.artifacts.entrySet() |
121 ) { | 115 ) { |
122 String masterArtifact = all.getKey(); | 116 String masterArtifact = all.getKey(); |
123 | 117 |
124 if (masterArtifact.startsWith(SYNTHETIC_KEY)) { // system data | 118 if (masterArtifact.startsWith(SYNTHETIC_KEY)) { // system data |
125 masterArtifact = null; | 119 masterArtifact = null; |
126 } | 120 } |
127 | 121 |
128 for (Map.Entry<StringTriple, ArtifactFilter> entry: | 122 for (final Map.Entry<StringTriple, ArtifactFilter> entry: |
129 all.getValue().entrySet() | 123 all.getValue().entrySet() |
130 ) { | 124 ) { |
131 StringTriple triple = entry.getKey(); | 125 final StringTriple triple = entry.getKey(); |
132 String factory = triple.first; | 126 final String factory = triple.first; |
133 String targetOut = triple.third; | 127 final String targetOut = triple.third; |
134 ArtifactFilter artifactFilter = entry.getValue(); | 128 final ArtifactFilter artifactFilter = entry.getValue(); |
135 | 129 |
136 String ids; | 130 String ids; |
137 Recommendation.Filter filter; | 131 Recommendation.Filter filter; |
138 | 132 |
139 if (masterArtifact == null) { // system data | 133 if (masterArtifact == null) { // system data |
143 else { // user specific | 137 else { // user specific |
144 ids = null; | 138 ids = null; |
145 filter = artifactFilter.toFilter(); | 139 filter = artifactFilter.toFilter(); |
146 } | 140 } |
147 | 141 |
148 Recommendation recommendation = new Recommendation( | 142 final Recommendation recommendation = new Recommendation( |
149 factory, ids, masterArtifact, filter, targetOut); | 143 factory, ids, masterArtifact, filter, targetOut); |
150 recommendation.setDisplayName(triple.second); | 144 recommendation.setDisplayName(triple.second); |
151 | 145 |
152 recommendations.add(recommendation); | 146 recommendations.add(recommendation); |
153 } | 147 } |
154 } | 148 } |