@Test public void testDeviceUniqueIndex() { DeviceUniqueIndex idx1 = new DeviceUniqueIndex( EnumSet.of(DeviceField.MAC, DeviceField.VLAN)); idx1.updateIndex(d1, d1.getDeviceKey()); idx1.updateIndex(e2, 2L); assertEquals(Long.valueOf(1L), idx1.findByEntity(e1a)); assertEquals(Long.valueOf(1L), idx1.findByEntity(e1b)); assertEquals(Long.valueOf(2L), idx1.findByEntity(e2)); assertEquals(Long.valueOf(2L), idx1.findByEntity(e2alt)); assertEquals(null, idx1.findByEntity(e3)); assertEquals(null, idx1.findByEntity(e4)); HashSet<Long> expectedKeys = new HashSet<Long>(); expectedKeys.add(1L); expectedKeys.add(2L); verifyIterator(expectedKeys, idx1.getAll()); verifyIterator(Collections.<Long>singleton(1L), idx1.queryByEntity(e1a)); verifyIterator(Collections.<Long>singleton(1L), idx1.queryByEntity(e1b)); verifyIterator(Collections.<Long>singleton(2L), idx1.queryByEntity(e2)); verifyIterator(Collections.<Long>singleton(2L), idx1.queryByEntity(e2alt)); assertEquals(false, idx1.queryByEntity(e3).hasNext()); assertEquals(false, idx1.queryByEntity(e3).hasNext()); idx1.removeEntity(e1a, 42L); assertEquals(Long.valueOf(1L), idx1.findByEntity(e1a)); idx1.removeEntity(e1a, 1L); assertEquals(null, idx1.findByEntity(e1a)); assertEquals(Long.valueOf(1L), idx1.findByEntity(e1b)); assertEquals(Long.valueOf(2L), idx1.findByEntity(e2)); idx1.removeEntity(e2); assertEquals(null, idx1.findByEntity(e2)); assertEquals(Long.valueOf(1L), idx1.findByEntity(e1b)); DeviceUniqueIndex idx2 = new DeviceUniqueIndex( EnumSet.of(DeviceField.IPV4, DeviceField.SWITCH)); idx2.updateIndex(e3, 3L); assertEquals(Long.valueOf(3L), idx2.findByEntity(e3)); e3.ipv4Address = 3; assertEquals(null, idx2.findByEntity(e3)); idx2.updateIndex(e4, 4L); assertEquals(null, idx2.findByEntity(e4)); Device d4 = new Device(null, 4L, null, null, null, Collections.<Entity>singleton(e4), null); idx2.updateIndex(d4, 4L); assertEquals(null, idx2.findByEntity(e4)); DeviceUniqueIndex idx3 = new DeviceUniqueIndex( EnumSet.of(DeviceField.MAC, DeviceField.VLAN)); idx3.updateIndex(e1a, 42L); assertEquals(false, idx3.updateIndex(d1, 1L)); idx3.updateIndex(e1a, 1L); assertEquals(true, idx3.updateIndex(d1, 1L)); }
public DeviceUniqueIndex(EnumSet<DeviceField> keyFields) { super(keyFields); index = new ConcurrentHashMap<IndexedEntity, Long>(); }
DeviceUniqueIndex extends DeviceIndex { public DeviceUniqueIndex(EnumSet<DeviceField> keyFields) { super(keyFields); index = new ConcurrentHashMap<IndexedEntity, Long>(); } }
DeviceUniqueIndex extends DeviceIndex { public DeviceUniqueIndex(EnumSet<DeviceField> keyFields) { super(keyFields); index = new ConcurrentHashMap<IndexedEntity, Long>(); } DeviceUniqueIndex(EnumSet<DeviceField> keyFields); }
DeviceUniqueIndex extends DeviceIndex { public DeviceUniqueIndex(EnumSet<DeviceField> keyFields) { super(keyFields); index = new ConcurrentHashMap<IndexedEntity, Long>(); } DeviceUniqueIndex(EnumSet<DeviceField> keyFields); @Override Iterator<Long> queryByEntity(Entity entity); @Override Iterator<Long> getAll(); @Override boolean updateIndex(Device device, Long deviceKey); @Override void updateIndex(Entity entity, Long deviceKey); @Override void removeEntity(Entity entity); @Override void removeEntity(Entity entity, Long deviceKey); Long findByEntity(Entity entity); }
DeviceUniqueIndex extends DeviceIndex { public DeviceUniqueIndex(EnumSet<DeviceField> keyFields) { super(keyFields); index = new ConcurrentHashMap<IndexedEntity, Long>(); } DeviceUniqueIndex(EnumSet<DeviceField> keyFields); @Override Iterator<Long> queryByEntity(Entity entity); @Override Iterator<Long> getAll(); @Override boolean updateIndex(Device device, Long deviceKey); @Override void updateIndex(Entity entity, Long deviceKey); @Override void removeEntity(Entity entity); @Override void removeEntity(Entity entity, Long deviceKey); Long findByEntity(Entity entity);  }