|
1 | | -// Copyright 2021 The Terasology Foundation |
| 1 | +// Copyright 2022 The Terasology Foundation |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 | package org.terasology.engine.entitySystem.entity; |
4 | 4 |
|
@@ -130,10 +130,32 @@ public interface EntityPool { |
130 | 130 | Iterable<EntityRef> getAllEntities(); |
131 | 131 |
|
132 | 132 | /** |
| 133 | + * All entities containing every one of the given components. |
| 134 | + * <p> |
| 135 | + * Implementation note: |
| 136 | + * <a href="http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#Topic5" |
| 137 | + * title="Designing Generic Methods">Java generic types are a mess</a>, especially where |
| 138 | + * varargs are involved. We can't use {@link SafeVarargs @SafeVarargs} on any interface methods |
| 139 | + * because there is no way to know the <em>implementations</em> of the interface are safe. |
| 140 | + * <p> |
| 141 | + * In this case, in practice, there are few (if any) callers that pass more than two values. |
| 142 | + * By adding methods that explicitly take one and two values, we can present an interface the |
| 143 | + * compiler doesn't need to complain about at every call site. |
| 144 | + * |
133 | 145 | * @return An iterable over all entities with the provided component types. |
134 | 146 | */ |
135 | 147 | Iterable<EntityRef> getEntitiesWith(Class<? extends Component>... componentClasses); |
136 | 148 |
|
| 149 | + @SuppressWarnings("unchecked") |
| 150 | + default Iterable<EntityRef> getEntitiesWith(Class<? extends Component> componentClass) { |
| 151 | + return getEntitiesWith(new Class[] {componentClass}); |
| 152 | + } |
| 153 | + |
| 154 | + @SuppressWarnings("unchecked") |
| 155 | + default Iterable<EntityRef> getEntitiesWith(Class<? extends Component> componentClass, Class<? extends Component> componentClass2) { |
| 156 | + return getEntitiesWith(new Class[] {componentClass, componentClass2}); |
| 157 | + } |
| 158 | + |
137 | 159 | /** |
138 | 160 | * @return A count of entities with the provided component types |
139 | 161 | */ |
|
0 commit comments