private int silentAdd(R record) { if (record == null) { throw new NullPointerException("Record is null passed into add() to store"); } Long id = record.getRecordId(); if (id == null) { id = ID_GENERATOR.next(); try { record.setRecordId(id); } catch (Exception e) { // this can't happen if we have exclusive access to the object (2 threads?) } } R existing = data.get(id); if (existing != null) { throw new RuntimeException("The store already contains this"); } // add it to our internal memory int index = data.add(id, record); // listen for change events. (null safe version) record.onChange().addObserver(this.onValueChanged); return index; }
private void remove(R record) { if (record == null) { return; } Long id = record.getRecordId(); if (!contains(id)) { return; } // need to know where it is so we can update the GUI efficiently int index = indexOf(id); // kill from our data backing. // NOTE: this MUST pierce the veil of filtering data.remove(id); // stop listening for changes. record.onChange().removeObserver(this.onValueChanged); if (this.onRemove != null) { this.onRemove.notifyObservers(this, getEventObject(record, index)); } }
private OrderedDataEventObject<R> getEventObject(R record) { return new OrderedDataEventObject<R>(this, record, indexOf(record.getRecordId())); }