monniasza.collects.indexar.OneToManyIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package monniasza.collects.indexar;
import java.util.function.Function;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
import mmb.NN;
/**
* An index, where property is a single value and may repeat between objects
* @param type of indexed objects
* @param type of indexed properties
* @author oskar
*/
public class OneToManyIndex implements Index> {
/** Function which defines a property of an object */
@NN public final Function fn;
@NN private final SetMultimap multimap = HashMultimap.create();
@NN private final SetMultimap pmultimap = Multimaps.unmodifiableSetMultimap(multimap);
public OneToManyIndex(Function fn) {
this.fn = fn;
}
@Override
public boolean add(T value) {
U key = fn.apply(value);
return multimap.put(key, value);
}
@Override
public boolean remove(T value) {
U key = fn.apply(value);
return multimap.remove(key, value);
}
@Override
public boolean test(T value) {
return true;
}
@Override
public SetMultimap multimap() {
return pmultimap;
}
@Override
public void clear() {
multimap.clear();
}
}