initial commit

This commit is contained in:
Sen 2025-03-11 00:23:54 +01:00 committed by Sen
parent 3c9ee26b06
commit 22186c33b9
1458 changed files with 282792 additions and 0 deletions

View file

@ -0,0 +1,17 @@
package game.properties;
import java.util.Collection;
public interface IProperty<T extends Comparable<T>>
{
String getName();
Collection<T> getAllowedValues();
Class<T> getValueClass();
/**
* Get the name for the given value.
*/
String getName(T value);
}

View file

@ -0,0 +1,6 @@
package game.properties;
public interface IStringSerializable
{
String getName();
}

View file

@ -0,0 +1,33 @@
package game.properties;
import java.util.Collection;
import game.collect.ImmutableSet;
public class PropertyBool extends PropertyHelper<Boolean>
{
private final ImmutableSet<Boolean> allowedValues = ImmutableSet.<Boolean>of(Boolean.valueOf(true), Boolean.valueOf(false));
protected PropertyBool(String name)
{
super(name, Boolean.class);
}
public Collection<Boolean> getAllowedValues()
{
return this.allowedValues;
}
public static PropertyBool create(String name)
{
return new PropertyBool(name);
}
/**
* Get the name for the given value.
*/
public String getName(Boolean value)
{
return value.toString();
}
}

View file

@ -0,0 +1,41 @@
package game.properties;
import java.util.Collection;
import java.util.function.Predicate;
import game.Predicates;
import game.collect.Filter;
import game.collect.Lists;
import game.world.Facing;
public class PropertyDirection extends PropertyEnum<Facing>
{
protected PropertyDirection(String name, Collection<Facing> values)
{
super(name, Facing.class, values);
}
/**
* Create a new PropertyDirection with the given name
*/
public static PropertyDirection create(String name)
{
return create(name, Predicates.<Facing>alwaysTrue());
}
/**
* Create a new PropertyDirection with all directions that match the given Predicate
*/
public static PropertyDirection create(String name, Predicate<Facing> filter)
{
return create(name, Filter.<Facing>filter(Lists.newArrayList(Facing.values()), filter));
}
/**
* Create a new PropertyDirection for the given direction values
*/
public static PropertyDirection create(String name, Collection<Facing> values)
{
return new PropertyDirection(name, values);
}
}

View file

@ -0,0 +1,68 @@
package game.properties;
import java.util.Collection;
import java.util.Map;
import java.util.function.Predicate;
import game.Predicates;
import game.collect.Filter;
import game.collect.ImmutableSet;
import game.collect.Lists;
import game.collect.Maps;
public class PropertyEnum<T extends Enum<T> & IStringSerializable> extends PropertyHelper<T>
{
private final ImmutableSet<T> allowedValues;
private final Map<String, T> nameToValue = Maps.<String, T>newHashMap();
protected PropertyEnum(String name, Class<T> valueClass, Collection<T> allowedValues)
{
super(name, valueClass);
this.allowedValues = ImmutableSet.copyOf(allowedValues);
for (T t : allowedValues)
{
String s = ((IStringSerializable)t).getName();
if (this.nameToValue.containsKey(s))
{
throw new IllegalArgumentException("Multiple values have the same name \'" + s + "\'");
}
this.nameToValue.put(s, t);
}
}
public Collection<T> getAllowedValues()
{
return this.allowedValues;
}
/**
* Get the name for the given value.
*/
public String getName(T value)
{
return ((IStringSerializable)value).getName();
}
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz)
{
return create(name, clazz, Predicates.<T>alwaysTrue());
}
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, Predicate<T> filter)
{
return create(name, clazz, Filter.<T>filter(Lists.newArrayList(clazz.getEnumConstants()), filter));
}
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, T... values)
{
return create(name, clazz, Lists.newArrayList(values));
}
public static <T extends Enum<T> & IStringSerializable> PropertyEnum<T> create(String name, Class<T> clazz, Collection<T> values)
{
return new PropertyEnum(name, clazz, values);
}
}

View file

@ -0,0 +1,50 @@
package game.properties;
public abstract class PropertyHelper<T extends Comparable<T>> implements IProperty<T>
{
private final Class<T> valueClass;
private final String name;
protected PropertyHelper(String name, Class<T> valueClass)
{
this.valueClass = valueClass;
this.name = name;
}
public String getName()
{
return this.name;
}
public Class<T> getValueClass()
{
return this.valueClass;
}
// public String toString()
// {
// return Objects.toStringHelper(this).add("name", this.name).add("clazz", this.valueClass).add("values", this.getAllowedValues()).toString();
// }
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (p_equals_1_ != null && this.getClass() == p_equals_1_.getClass())
{
PropertyHelper propertyhelper = (PropertyHelper)p_equals_1_;
return this.valueClass.equals(propertyhelper.valueClass) && this.name.equals(propertyhelper.name);
}
else
{
return false;
}
}
public int hashCode()
{
return 31 * this.valueClass.hashCode() + this.name.hashCode();
}
}

View file

@ -0,0 +1,86 @@
package game.properties;
import java.util.Collection;
import java.util.Set;
import game.collect.ImmutableSet;
import game.collect.Sets;
public class PropertyInteger extends PropertyHelper<Integer>
{
private final ImmutableSet<Integer> allowedValues;
protected PropertyInteger(String name, int min, int max)
{
super(name, Integer.class);
if (min < 0)
{
throw new IllegalArgumentException("Min value of " + name + " must be 0 or greater");
}
else if (max <= min)
{
throw new IllegalArgumentException("Max value of " + name + " must be greater than min (" + min + ")");
}
else
{
Set<Integer> set = Sets.<Integer>newHashSet();
for (int i = min; i <= max; ++i)
{
set.add(Integer.valueOf(i));
}
this.allowedValues = ImmutableSet.copyOf(set);
}
}
public Collection<Integer> getAllowedValues()
{
return this.allowedValues;
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (p_equals_1_ != null && this.getClass() == p_equals_1_.getClass())
{
if (!super.equals(p_equals_1_))
{
return false;
}
else
{
PropertyInteger propertyinteger = (PropertyInteger)p_equals_1_;
return this.allowedValues.equals(propertyinteger.allowedValues);
}
}
else
{
return false;
}
}
public int hashCode()
{
int i = super.hashCode();
i = 31 * i + this.allowedValues.hashCode();
return i;
}
public static PropertyInteger create(String name, int min, int max)
{
return new PropertyInteger(name, min, max);
}
/**
* Get the name for the given value.
*/
public String getName(Integer value)
{
return value.toString();
}
}