public void add(final OIdentifiable identifiable) { if (identifiable == null) throw new NullPointerException("Impossible to add a null identifiable in a ridbag"); if (identifiable.getIdentity().isValid()) { Change counter = changes.get(identifiable); if (counter == null) changes.put(identifiable, new DiffChange(1)); else { if (counter.isUndefined()) { counter = getAbsoluteValue(identifiable); changes.put(identifiable, counter); } counter.increment(); } } else { final OModifiableInteger counter = newEntries.get(identifiable); if (counter == null) newEntries.put(identifiable, new OModifiableInteger(1)); else counter.increment(); } if (size >= 0) size++; if (this.owner != null) ORecordInternal.track(this.owner, identifiable); if (updateOwner) fireCollectionChangedEvent( new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>( OMultiValueChangeEvent.OChangeType.ADD, identifiable, identifiable, null, false)); }
public void remove(OIdentifiable identifiable) { if (removeFromNewEntries(identifiable)) { if (size >= 0) size--; } else { final Change counter = changes.get(identifiable); if (counter == null) { // Not persistent keys can only be in changes or newEntries if (identifiable.getIdentity().isPersistent()) { changes.put(identifiable, new DiffChange(-1)); size = -1; } else // Return immediately to prevent firing of event return; } else { counter.decrement(); if (size >= 0) if (counter.isUndefined()) size = -1; else size--; } } if (this.owner != null) ORecordInternal.unTrack(this.owner, identifiable); if (updateOwner) fireCollectionChangedEvent( new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>( OMultiValueChangeEvent.OChangeType.REMOVE, identifiable, null, identifiable, false)); }
@Override public boolean convertRecords2Links() { final Map<OIdentifiable, Change> newChangedValues = new HashMap<OIdentifiable, Change>(); for (Map.Entry<OIdentifiable, Change> entry : changes.entrySet()) { OIdentifiable identifiable = entry.getKey(); if (identifiable instanceof ORecord) { ORID identity = identifiable.getIdentity(); ORecord record = (ORecord) identifiable; identity = record.getIdentity(); newChangedValues.put(identity, entry.getValue()); } else newChangedValues.put(entry.getKey().getIdentity(), entry.getValue()); } for (Map.Entry<OIdentifiable, Change> entry : newChangedValues.entrySet()) { if (entry.getKey() instanceof ORecord) { ORecord record = (ORecord) entry.getKey(); newChangedValues.put(record, entry.getValue()); } else return false; } newEntries.clear(); changes.clear(); changes.putAll(newChangedValues); return true; }