/*
* Copyright (C) 2015 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see
Example: Grow-only set values CRDT:
* class GrowOnlySetValuedMapEntryOperations<K, E>
* implements MapEntryOperations<K, Set<E>, Void> {
* @Override
* public Void remove(@NotNull MapEntry<K, Set<E>> entry) {
* throw new UnsupportedOperationException("Map with grow-only set values " +
* "doesn't support map value removals");
* }
* }
*
* class GrowOnlySetValuedMapRemoteOperations<K, E>
* implements MapRemoteOperations<K, Set<E>, Void> {
* @Override
* public void put(MapRemoteQueryContext<K, Set<E>, Void> q,
* Data<Set<E>, ?> newValue) {
* MapReplicableEntry<K, Set<E>> entry = q.entry();
* if (entry != null) {
* Set<E> merged = new HashSet<>(entry.value().get());
* merged.addAll(newValue.get());
* q.replaceValue(entry, q.wrapValueAsData(merged));
* } else {
* q.insert(q.absentEntry(), newValue);
* q.entry().updateOrigin(q.remoteIdentifier(), q.remoteTimestamp());
* }
* }
*
* @Override
* public void remove(MapRemoteQueryContext<K, Set<E>, Void> q) {
* throw new UnsupportedOperationException();
* }
* }
*
* @param {@code
* MapReplicableEntry entry = q.entry();
* if (entry != null) {
* if (DefaultEventualConsistencyStrategy.decideOnRemoteModification(entry, q) == ACCEPT) {
* q.remove(entry);
* ReplicableEntry replicableAbsentEntry = (ReplicableEntry) q.absentEntry();
* replicableAbsentEntry.updateOrigin(q.remoteIdentifier(), q.remoteTimestamp());
* replicableAbsentEntry.dropChanged();
* }
* } else {
* MapAbsentEntry absentEntry = q.absentEntry();
* ReplicableEntry replicableAbsentEntry;
* if (!(absentEntry instanceof ReplicableEntry)) {
* // Note in the two following lines dummy value is inserted and removed using direct
* // entry.doXxx calls, not q.xxx(entry). The intention is to avoid calling possibly
* // overridden MapEntryOperations, because this is technical procedure of making
* // "truly absent" entry "deleted", not actual insertion and removal.
* absentEntry.doInsert(q.dummyZeroValue());
* q.entry().doRemove();
* replicableAbsentEntry = (ReplicableEntry) q.absentEntry();
* } else {
* replicableAbsentEntry = (ReplicableEntry) absentEntry;
* if (DefaultEventualConsistencyStrategy.decideOnRemoteModification(
* replicableAbsentEntry, q) == DISCARD) {
* return;
* }
* }
* replicableAbsentEntry.updateOrigin(q.remoteIdentifier(), q.remoteTimestamp());
* replicableAbsentEntry.dropChanged();
* }}
*
* @param q the remote operation context
*/
default void remove(MapRemoteQueryContext{@code
* MapReplicableEntry entry = q.entry();
* if (entry != null) {
* if (DefaultEventualConsistencyStrategy.decideOnRemoteModification(entry, q) == ACCEPT) {
* q.replaceValue(entry, newValue);
* entry.updateOrigin(q.remoteIdentifier(), q.remoteTimestamp());
* entry.dropChanged();
* }
* } else {
* MapAbsentEntry absentEntry = q.absentEntry();
* if (!(absentEntry instanceof ReplicableEntry) ||
* DefaultEventualConsistencyStrategy.decideOnRemoteModification(
* (ReplicableEntry) absentEntry, q) == ACCEPT) {
* q.insert(absentEntry, newValue);
* entry = q.entry();
* entry.updateOrigin(q.remoteIdentifier(), q.remoteTimestamp());
* entry.dropChanged();
* }
* }}
*
* @param q the remote operation context
* @param newValue the new value to put
*/
default void put(MapRemoteQueryContext