public Tuple get(RowKey key) { AssociationOperation result = currentState.get(key); if (result == null) { return cleared ? null : snapshot.get(key); } else if (result.getType() == PUT_NULL || result.getType() == REMOVE) { return null; } return result.getValue(); }
public int size() { int size = cleared ? 0 : snapshot.size(); for (Map.Entry<RowKey, AssociationOperation> op : currentState.entrySet()) { switch (op.getValue().getType()) { case PUT: case PUT_NULL: if (cleared || !snapshot.containsKey(op.getKey())) { size++; } break; case REMOVE: if (!cleared && snapshot.containsKey(op.getKey())) { size--; } break; } } return size; }
public boolean isEmpty() { int snapshotSize = cleared ? 0 : snapshot.size(); // nothing in both if (snapshotSize == 0 && currentState.isEmpty()) { return true; } // snapshot bigger than changeset if (snapshotSize > currentState.size()) { return false; } return size() == 0; }
public Set<RowKey> getKeys() { Set<RowKey> keys = new HashSet<RowKey>(); if (!cleared) { keys.addAll(snapshot.getRowKeys()); } for (Map.Entry<RowKey, AssociationOperation> op : currentState.entrySet()) { switch (op.getValue().getType()) { case PUT: case PUT_NULL: keys.add(op.getKey()); break; case REMOVE: keys.remove(op.getKey()); break; } } return keys; }