Source:
<code>public void update(Direction direction, Tuple update) { boolean propagate = false; if (this.deleteRederive) { if (direction == Direction.INSERT) { if (memory.get(update) > 0) { <START> memory.add(update); <END> } else { if (rederivableMemory.get(update) == 0) { reteContainer.registerRederivable(this, update); } rederivableMemory.add(update); } } else { if (memory.get(update) > 0) { if (rederivableMemory.get(update) != 0) { issueError("[INTERNAL ERROR] Re-derivation memory for " + update + " must be empty before the re-derivation phase in UniquenessEnforcer " + this + " for pattern(s) " + getTraceInfoPatternsEnumerated(), null); } int count = memory.get(update) - 1; if (count > 0) { reteContainer.registerRederivable(this, update); rederivableMemory.add(update, count); } memory.clear(update); propagate = true; } else { int count = rederivableMemory.get(update); if (count == 1) { reteContainer.unregisterRederivable(this, update); } try { rederivableMemory.remove(update); } catch (NullPointerException ex) { issueError("[INTERNAL ERROR] Duplicate deletion of " + update + " was detected in UniquenessEnforcer " + this + " for pattern(s) " + getTraceInfoPatternsEnumerated(), ex); } } } } else { if (direction == Direction.INSERT) { propagate = this.memory.add(update); } else { try { propagate = this.memory.remove(update); } catch (NullPointerException ex) { propagate = false; issueError( "[INTERNAL ERROR] Duplicate deletion of " + update + " was detected in UniquenessEnforcer " + this + " for pattern(s) " + getTraceInfoPatternsEnumerated(), ex); } } } if (propagate) { propagate(direction, update); } }</code><technical_language>complicated micro-optimization nitpick: is a separate get add call - 3 lookups. reduce this if introduce a boolean addOneIfAlreadyExists(Tuple) method TupleMask a variant of add() this in step. leave is :)</technical_language>

Target:
public void update(Direction direction, Tuple update) { boolean propagate = false; if (this.deleteRederive) { if (direction == Direction.INSERT) { boolean containedAlready = memory.demandAdd(update); if (!containedAlready) { if (rederivableMemory.add(update)) { reteContainer.registerRederivable(this); } } } else { int memoryCount = memory.get(update); int rederivableCount = rederivableMemory.get(update); if (memoryCount > 0) { if (rederivableCount != 0) { issueError("[INTERNAL ERROR] Re-derivation memory for " + update + " must be empty before the re-derivation phase in UniquenessEnforcer " + this + " for pattern(s) " + getTraceInfoPatternsEnumerated(), null); } int count = memoryCount - 1; if (count > 0) { reteContainer.registerRederivable(this); rederivableMemory.add(update, count); } memory.clear(update); propagate = true; } else { try { rederivableMemory.remove(update); } catch (NullPointerException ex) { issueError("[INTERNAL ERROR] Duplicate deletion of " + update + " was detected in UniquenessEnforcer " + this + " for pattern(s) " + getTraceInfoPatternsEnumerated(), ex); } if (rederivableMemory.size() == 0) { reteContainer.unregisterRederivable(this); } } } } else { if (direction == Direction.INSERT) { propagate = this.memory.add(update); } else { try { propagate = this.memory.remove(update); } catch (NullPointerException ex) { propagate = false; issueError( "[INTERNAL ERROR] Duplicate deletion of " + update + " was detected in UniquenessEnforcer " + this + " for pattern(s) " + getTraceInfoPatternsEnumerated(), ex); } } } if (propagate) { propagate(direction, update); } }