devicemap-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Volkan YAZICI <volkan.yaz...@gmail.com>
Subject Comments needed for DeviceMapClient.createIndex()
Date Mon, 29 Dec 2014 12:53:16 GMT
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.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message