Added extra methods to Items

This commit is contained in:
Auxilor
2022-02-03 17:17:01 +00:00
parent fbf56037d4
commit e65cf9be2c

View File

@@ -20,6 +20,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -344,6 +345,35 @@ public final class Items {
}
}
/**
* Convert an array of materials to an array of testable items.
*
* @param materials The materials.
* @return An array of functionally identical testable items.
*/
@NotNull
public static TestableItem[] fromMaterials(@NotNull final Material... materials) {
return Arrays.stream(materials)
.map(MaterialTestableItem::new)
.toArray(MaterialTestableItem[]::new);
}
/**
* Convert a collection of materials into a collection of testable items.
*
* @param materials The materials.
* @return A collection of functionally identical testable items.
*/
@NotNull
public static Collection<TestableItem> fromMaterials(@NotNull final Iterable<Material> materials) {
List<TestableItem> items = new ArrayList<>();
for (Material material : materials) {
items.add(new MaterialTestableItem(material));
}
return items;
}
private Items() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}