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

org.aksw.commons.collections.reversible.ReversibleSetMultimapImpl Maven / Gradle / Ivy

There is a newer version: 0.9.9
Show newest version
package org.aksw.commons.collections.reversible;

import java.util.LinkedHashSet;
import java.util.Map.Entry;
import java.util.Set;

import com.google.common.collect.SetMultimap;

/**
 * This implementation acts as a slave to the ReversibleMap:
 * Insert methods are delegated to ReversibleMap.
 *
 */
public class ReversibleSetMultimapImpl
	extends AbstractSetMultimap
	implements ReversibleSetMultimap
{
	protected ReversibleMap reverse;

	protected SetMultimap forward;


	public ReversibleSetMultimapImpl(ReversibleMap reverse, SetMultimap forward) {
		this.reverse = reverse;
		this.forward = forward;
	}


	@Override
	public ReversibleMap reverse() {
		return reverse;
	}

	@Override
	public boolean put(K key, V value) {
		K tmp = reverse.put(value, key);
		boolean change = tmp == key;
		return change;
	}

	@Override
	public Set> entries() {
		return forward.entries();
	}

	@Override
	public Set get(K key) {
		Set result = forward.get(key);
		return result;
	}

	@Override
	public boolean remove(Object key, Object value) {
		boolean result = forward.containsEntry(key, value);
		if(result) {
			reverse.remove(value);
		}
		return result;
	}

	@Override
	public Set removeAll(Object key) {
		Set result = new LinkedHashSet<>(forward.get((K)key));
		result.forEach(reverse::remove);
		return result;
	}

	@Override
	public void clear() {
		reverse.clear();
	}

	@Override
	public int hashCode() {
		return forward.hashCode();
	}

	@Override
	public boolean equals(Object arg) {
		return forward.equals(arg);
	}
//
//	@Override
//	protected Multimap delegate() {
//		return forward;
//	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy