Some useful predictates

This commit is contained in:
Olof Larsson 2013-12-17 02:59:57 +01:00
parent dd4fd924f1
commit 8d1ec9f51d
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package com.massivecraft.mcore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class PredictateAnd<T> implements Predictate<T>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
@SafeVarargs
public static <T> PredictateAnd<T> get(Predictate<T>... predictates) { return new PredictateAnd<T>(predictates); }
@SafeVarargs
public PredictateAnd(Predictate<T>... predictates)
{
this(Arrays.asList(predictates));
}
public static <T> PredictateAnd<T> get(Collection<Predictate<T>> predictates) { return new PredictateAnd<T>(predictates); }
public PredictateAnd(Collection<Predictate<T>> predictates)
{
this.predictates = Collections.unmodifiableList(new ArrayList<Predictate<T>>(predictates));
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final List<Predictate<T>> predictates;
public List<Predictate<T>> getPredictates() { return this.predictates; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean apply(T type)
{
for (Predictate<T> predictate : this.getPredictates())
{
if (!predictate.apply(type)) return false;
}
return true;
}
}

View File

@ -0,0 +1,24 @@
package com.massivecraft.mcore;
import com.massivecraft.mcore.store.Entity;
public class PredictateIsntDefaultEntity implements Predictate<Entity<?>>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PredictateIsntDefaultEntity i = new PredictateIsntDefaultEntity();
public static PredictateIsntDefaultEntity get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public boolean apply(Entity<?> entity)
{
return !entity.isDefault();
}
}