1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.esigate.impl;
16
17 import java.util.LinkedHashMap;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.SortedSet;
21 import java.util.TreeSet;
22
23 import org.esigate.Driver;
24
25
26
27
28
29
30
31
32
33 public class IndexedInstances {
34 private final Map<String, Driver> instances;
35 private final Map<UriMapping, String> uriMappings;
36
37 public IndexedInstances(Map<String, Driver> instances) {
38 this.instances = instances;
39 this.uriMappings = buildUriMappings();
40 }
41
42 private Map<UriMapping, String> buildUriMappings() {
43 Map<UriMapping, String> result = new LinkedHashMap<>();
44
45 Map<UriMapping, String> unsortedResult = new LinkedHashMap<>();
46
47 if (this.instances != null) {
48 for (String instanceId : this.instances.keySet()) {
49 List<UriMapping> driverMappings = this.instances.get(instanceId).getConfiguration().getUriMappings();
50
51 for (UriMapping mapping : driverMappings) {
52 unsortedResult.put(mapping, instanceId);
53 }
54 }
55 }
56
57
58 SortedSet<UriMapping> keys = new TreeSet<>(new UriMappingComparator());
59 keys.addAll(unsortedResult.keySet());
60 for (UriMapping key : keys) {
61 result.put(key, unsortedResult.get(key));
62 }
63
64 return result;
65 }
66
67
68
69
70
71
72 public Map<String, Driver> getInstances() {
73 return this.instances;
74 }
75
76
77
78
79
80
81 public Map<UriMapping, String> getUrimappings() {
82 return this.uriMappings;
83 }
84
85 }