Package net.mtrop.doom.texture
Class CommonTextureList<T extends CommonTexture<?>>
java.lang.Object
net.mtrop.doom.texture.CommonTextureList<T>
- Type Parameters:
T
- the contained CommonTexture type.
- All Implemented Interfaces:
Iterable<T>
,BinaryObject
,Sizable
- Direct Known Subclasses:
DoomTextureList
,StrifeTextureList
public abstract class CommonTextureList<T extends CommonTexture<?>>
extends Object
implements BinaryObject, Iterable<T>, Sizable
This is the lump that contains a collection of textures.
All textures are stored in here, usually named TEXTURE1 or TEXTURE2 in a WAD.
Most creation methods in this object are factory-style, due to the diversity of implemented texture formats.
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.mtrop.doom.object.BinaryObject
BinaryObject.InlineScanner<BO extends BinaryObject>, BinaryObject.Reflect, BinaryObject.Scanner<BO extends BinaryObject>, BinaryObject.Shared, BinaryObject.Transformer<BO extends BinaryObject>
-
Constructor Summary
ConstructorDescriptionCreates a new TextureList with a default starting capacity.CommonTextureList
(int capacity) Creates a new TextureList with a specific starting capacity. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCreatedTexture
(T texture) Adds a created texture to this texture list.void
clear()
Clears this list of textures.abstract T
createTexture
(String name) Creates a new texture in this list with no patches, at the end of the list.getTextureByIndex
(int index) Gets a texture entry in this list by its index.getTextureByName
(String name) Gets a texture in this list by its name.int
Gets the index of a texture in this list by its name.boolean
isEmpty()
Returns if this object contains no objects.iterator()
Attempts to remove a texture entry by its name.removeIndex
(int index) Removes a texture entry at an index.int
size()
void
sort()
Sorts the textures in this texture list using natural ordering.void
sort
(Comparator<? super T> comp) Sorts the textures in this texture list using the provided comparator.void
writeBytes
(OutputStream out) Writes this object to anOutputStream
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.mtrop.doom.object.BinaryObject
fromBytes, readBytes, readFile, toBytes, writeFile, writeFile
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
CommonTextureList
public CommonTextureList()Creates a new TextureList with a default starting capacity. -
CommonTextureList
public CommonTextureList(int capacity) Creates a new TextureList with a specific starting capacity.- Parameters:
capacity
- the starting capacity.
-
-
Method Details
-
addCreatedTexture
Adds a created texture to this texture list. Must be called fromcreateTexture(String)
.- Parameters:
texture
- the texture to add.
-
clear
public void clear()Clears this list of textures. -
indexOf
Gets the index of a texture in this list by its name.- Parameters:
name
- the name of the texture.- Returns:
- a valid index if found, or -1 if not.
-
getTextureByIndex
Gets a texture entry in this list by its index.- Parameters:
index
- the index to use.- Returns:
- a valid texture if found, or
null
if no texture at that index.
-
getTextureByName
Gets a texture in this list by its name.- Parameters:
name
- the name of the texture.- Returns:
- a valid index if found, or -1 if not.
-
remove
Attempts to remove a texture entry by its name. Note that this will shift the indices of the other entries.- Parameters:
name
- the name of the entry.- Returns:
- true if removed, false if not.
-
removeIndex
Removes a texture entry at an index. Note that this will shift the indices of the other entries.- Parameters:
index
- the index to use.- Returns:
- the entry removed, or
null
if no entry at that index.
-
sort
public void sort()Sorts the textures in this texture list using natural ordering. -
sort
Sorts the textures in this texture list using the provided comparator.- Parameters:
comp
- the comparator to use.
-
createTexture
Creates a new texture in this list with no patches, at the end of the list.- Parameters:
name
- the name of the texture.- Returns:
- a new, empty texture object added to this list.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name for a texture.- See Also:
-
writeBytes
Description copied from interface:BinaryObject
Writes this object to anOutputStream
.- Specified by:
writeBytes
in interfaceBinaryObject
- Parameters:
out
- theOutputStream
to write to.- Throws:
IOException
- if a write error occurs.
-
iterator
- Specified by:
iterator
in interfaceIterable<T extends CommonTexture<?>>
-
size
public int size() -
isEmpty
public boolean isEmpty()Description copied from interface:Sizable
Returns if this object contains no objects. The general policy of this method is that this returns true if and only ifSizable.size()
returns 0.
-