Hi,
I am working on a mechanism to enable the concurrent devicemap data
initialization for DeviceMap Java client. In createIndex() method, what is
the purpose of the *i == (pattern.getPatternParts().size() - 1)* check?
That is,
private void createIndex() {
patterns = new HashMap<String, List<DeviceType>>(8000);
for (DeviceType device : devices.values()) {
for (Pattern pattern : device.getPatternSet().getPatterns()) {
for (int i = 0; i < pattern.getPatternParts().size(); i++) {
String part = pattern.getPatternParts().get(i);
//duplicate
if (patterns.get(part) != null) {
if (i == (pattern.getPatternParts().size() - 1) &&
!patterns.get(part).contains(device)) {
patterns.get(part).add(device);
}
} else {
List<DeviceType> single = new ArrayList<DeviceType>();
single.add(device);
patterns.put(part, single);
}
}
}
}
}
Can't we just go with a *!patterns.get(part).contains(device)* check?
Additionally, wouldn't it be better to rather use a Set instead of a List?
Best.