jalse.entities.methods.KillEntitiesMethod Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JALSE Show documentation
Show all versions of JALSE Show documentation
Java Artificial Life Simulation Engine
package jalse.entities.methods;
import jalse.entities.Entity;
import jalse.entities.EntityContainer;
import jalse.entities.annotations.KillEntities;
import jalse.entities.functions.KillEntitiesFunction;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;
/**
* This is used for mapping calls to {@link EntityContainer#killEntities()}.
*
* @author Elliot Ford
*
* @see KillEntities
* @see KillEntitiesFunction
*
*/
public class KillEntitiesMethod implements EntityMethod {
private final Set> idSuppliers;
/**
* Creates a kill entities method.
*
* @param idSuppliers
* Entity ID suppliers for filtering.
*/
public KillEntitiesMethod(final Set> idSuppliers) {
this.idSuppliers = Objects.requireNonNull(idSuppliers);
}
/**
* Gets entity ID suppliers.
*
* @return ID suppliers.
*/
public Set> getIDSuppliers() {
return idSuppliers;
}
@Override
public Object invoke(final Object proxy, final Entity entity, final Object[] args) throws Throwable {
// Kill all
if (idSuppliers.isEmpty()) {
entity.killEntities();
}
// Kill selected
else {
idSuppliers.stream().map(Supplier::get).forEach(entity::killEntity);
}
// void return
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy