Some useful predictates
This commit is contained in:
parent
dd4fd924f1
commit
8d1ec9f51d
49
src/com/massivecraft/mcore/PredictateAnd.java
Normal file
49
src/com/massivecraft/mcore/PredictateAnd.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
24
src/com/massivecraft/mcore/PredictateIsntDefaultEntity.java
Normal file
24
src/com/massivecraft/mcore/PredictateIsntDefaultEntity.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user