Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Classes that are intended to be instantiated as immutable objects (e.g. DefaultDevice) should have all class all variables declared final.
  • Collections (Sets, Maps, etc) returned by getters should be immutable, or a copy of the existing Collection.

    Code Block
    languagejava
    @Override
    public Iterable<Device> getDevices() {
        return Collections.unmodifiableCollection(devices.values());
    }
    
     
    // or, if copying
    @Override
    public Set<DeviceId> getDevices(NodeId nodeId) {
        Set<DeviceId> ids = new HashSet<>();
        for (Map.Entry<DeviceId, NodeId> d : masterMap.entrySet()) {
            if (d.getValue().equals(nodeId)) {
                ids.add(d.getKey());
            }
        }
        return ids;
    }

...