Simplify and slightly optimize EntityClassDescriptor
Could probably also be a record, though I'll look into that at another time
This commit is contained in:
2 files changed
+13
-23
No files matched your search
@@ -283,29 +283,15 @@ public class EntityValue extends Value
|
||||
|
||||
public static class EntityClassDescriptor
|
||||
{
|
||||
public EntityTypeTest<Entity, ? extends Entity> directType; // interface of EntityType
|
||||
public Predicate<? super Entity> filteringPredicate;
|
||||
public List<EntityType<? extends Entity>> typeList;
|
||||
public Value listValue;
|
||||
EntityClassDescriptor(EntityType<?> type, Predicate<? super Entity> predicate, List<EntityType<?>> types)
|
||||
{
|
||||
directType = type;
|
||||
filteringPredicate = predicate;
|
||||
typeList = types;
|
||||
listValue = (types==null)?Value.NULL:ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getKey(et)))).collect(Collectors.toList()));
|
||||
}
|
||||
public final EntityTypeTest<Entity, ? extends Entity> directType; // interface of EntityType
|
||||
public final Predicate<? super Entity> filteringPredicate;
|
||||
public final List<EntityType<? extends Entity>> types;
|
||||
|
||||
EntityClassDescriptor( EntityTypeTest<Entity, ?> type, Predicate<? super Entity> predicate, List<EntityType<?>> types)
|
||||
EntityClassDescriptor(EntityTypeTest<Entity, ?> type, Predicate<? super Entity> predicate, List<EntityType<?>> types)
|
||||
{
|
||||
directType = type;
|
||||
filteringPredicate = predicate;
|
||||
typeList = types;
|
||||
listValue = (types==null)?Value.NULL:ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getKey(et)))).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
EntityClassDescriptor(EntityType<?> type, Predicate<? super Entity> predicate, Stream<EntityType<?>> types)
|
||||
{
|
||||
this(type, predicate, types.toList());
|
||||
this.directType = type;
|
||||
this.filteringPredicate = predicate;
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
EntityClassDescriptor(EntityTypeTest<Entity, ?> type, Predicate<? super Entity> predicate, Stream<EntityType<?>> types)
|
||||
@@ -313,6 +299,10 @@ public class EntityValue extends Value
|
||||
this(type, predicate, types.toList());
|
||||
}
|
||||
|
||||
public Value listValue() {
|
||||
return ListValue.wrap(types.stream().map(et -> StringValue.of(nameFromRegistryId(Registry.ENTITY_TYPE.getKey(et)))));
|
||||
}
|
||||
|
||||
public final static Map<String, EntityClassDescriptor> byName = new HashMap<>() {{
|
||||
List<EntityType<?>> allTypes = Registry.ENTITY_TYPE.stream().toList();
|
||||
// nonliving types
|
||||
|
||||
Reference in new issue
Block a user