com.g2forge.alexandria.java.associative.MapAssociation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
package com.g2forge.alexandria.java.associative;
import java.util.Map;
import java.util.Optional;
import lombok.Data;
@Data
public class MapAssociation implements IAssociation {
protected final Map map;
@Override
public Optional get(K key, boolean remove) {
if (!map.containsKey(key)) return Optional.empty();
return Optional.of(map.get(key));
}
@Override
public void put(K key, V value) {
map.put(key, value);
}
@Override
public void remove(K key) {
map.remove(key);
}
@Override
public Optional set(K key, V value) {
final boolean contained = map.containsKey(key);
final V retVal = map.put(key, value);
return contained ? Optional.empty() : Optional.of(retVal);
}
}