SDN Controller Programming Guide

178
if (device.getId() == null) {
Id<Switch, Long> id = Id.valueOf(idCount.getAndIncrement());
deviceToAdd = new Switch(id, device.getMacAddress());
deviceToAdd.setActiveState(device.getActiveState());
deviceToAdd.setFriendlyName(device.getFriendlyName());
deviceToAdd.setIpAddress(device.getIpAddress());
}
devices.put(deviceToAdd.getId(), deviceToAdd);
return deviceToAdd;
}
@Override
public void update(Switch device) {
if (device == null) {
throw new NullPointerException("device cannot be null");
}
if (device.getId() == null) {
throw new IllegalArgumentException(
"a device must be added before updating it");
}
devices.put(device.getId(), device);
}
@Override
public Switch get(Id<Switch, Long> id) {
if (id == null) {
throw new NullPointerException("id cannot be null");
}
return devices.get(id);
}
@Override
public List<Switch> find(SwitchFilter filter,
SortSpecification<SwitchSortKey> sortSpecification) {
// In a real application a database may be used: filter would be
// mapped to predicates and sortSpecification to sorting clauses
return new ArrayList<Switch>(devices.values());
}
@Override
public void delete(Id<Switch, Long> id) {