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

com.g2forge.alexandria.java.associative.MapAssociation Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy