All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jhotdraw8.icollection.impl.champmap.EditableMapEntry Maven / Gradle / Ivy

The newest version!
/*
 * @(#)EditableMapEntry.java
 * Copyright © 2022 The authors and contributors of JHotDraw. MIT License.
 */

package org.jhotdraw8.icollection.impl.champmap;

import org.jspecify.annotations.Nullable;

import java.io.Serial;
import java.util.AbstractMap;
import java.util.function.BiConsumer;

/**
 * A map entry that supports a put operation.
 *
 * @param  the key type
 * @param  the value type
 */
public class EditableMapEntry extends AbstractMap.SimpleEntry {
    @Serial
    private static final long serialVersionUID = 0L;
    private final int sequenceNumber;
    @SuppressWarnings({"serial", "RedundantSuppression"})
    private @Nullable BiConsumer putIfPresentFunction;// This map entry is actually not serializable

    public EditableMapEntry(K key, V value, int sequenceNumber) {
        super(key, value);
        this.sequenceNumber = sequenceNumber;
    }

    public int getSequenceNumber() {
        return sequenceNumber;
    }

    void setPutIfPresentFunction(@Nullable BiConsumer putIfPresentFunction) {
        this.putIfPresentFunction = putIfPresentFunction;
    }

    @Override
    public V setValue(V value) {
        if (putIfPresentFunction == null) {
            throw new UnsupportedOperationException();
        }
        putIfPresentFunction.accept(getKey(), value);
        return super.setValue(value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy