Skip to content

Commit

Permalink
Improve JavaDocs in Resources package
Browse files Browse the repository at this point in the history
  • Loading branch information
nightm4re94 committed Dec 14, 2024
1 parent 1d298f7 commit f25cd96
Show file tree
Hide file tree
Showing 20 changed files with 1,028 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,35 @@
import de.gurkenlabs.litiengine.util.io.FileUtilities;
import de.gurkenlabs.litiengine.util.io.XmlUtilities;

/**
* A class that manages the loading and handling of Blueprint resources.
*/
public class Blueprints extends ResourcesContainer<Blueprint> {

/**
* Constructs a new Blueprints container.
*/
Blueprints() {}

/**
* Checks if the given file name is supported by this container.
*
* @param fileName The name of the file to check.
* @return true if the file is supported, false otherwise.
*/
public static boolean isSupported(String fileName) {
String extension = FileUtilities.getExtension(fileName);
return extension != null && !extension.isEmpty()
&& (extension.equalsIgnoreCase(Blueprint.BLUEPRINT_FILE_EXTENSION) || extension.equalsIgnoreCase(Blueprint.TEMPLATE_FILE_EXTENSION));
return !extension.isEmpty() && (extension.equalsIgnoreCase(Blueprint.BLUEPRINT_FILE_EXTENSION) || extension.equalsIgnoreCase(
Blueprint.TEMPLATE_FILE_EXTENSION));
}

/**
* Loads a Blueprint resource from the specified URL.
*
* @param resourceName The URL of the resource to load.
* @return The loaded Blueprint resource.
* @throws Exception if an error occurs while loading the resource.
*/
@Override
protected Blueprint load(URL resourceName) throws Exception {
Blueprint blueprint;
Expand All @@ -31,6 +50,13 @@ protected Blueprint load(URL resourceName) throws Exception {
return blueprint;
}

/**
* Gets the alias for the specified resource.
*
* @param resourceName The name of the resource.
* @param resource The resource to get the alias for.
* @return The alias of the resource, or null if no alias is available.
*/
@Override
protected String getAlias(String resourceName, Blueprint resource) {
if (resource == null || resource.getName() == null || resource.getName().isEmpty() || resource.getName().equalsIgnoreCase(resourceName)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package de.gurkenlabs.litiengine.resources;

import java.util.ArrayList;

import de.gurkenlabs.litiengine.util.io.FileUtilities;
import java.util.ArrayList;

/**
* Some common implementations that are used by different kinds of file classes (e.g. {@code SoundFormat},
* {@code ImageFormat}.
* Some common implementations that are used by different kinds of file classes (e.g. {@code SoundFormat}, {@code ImageFormat}.
*/
final class DataFormat {
private DataFormat() {}
private DataFormat() {
}

protected static <T extends Enum<T>> T get(String format, T[] values, T defaultValue) {
/**
* Retrieves the enum value corresponding to the given format string.
*
* @param <T> The type of the enum.
* @param format The format string to match.
* @param values The array of enum values to search.
* @param defaultValue The default value to return if no match is found.
* @return The matching enum value, or the default value if no match is found.
*/
static <T extends Enum<T>> T get(String format, T[] values, T defaultValue) {
if (format == null || format.isEmpty()) {
return defaultValue;
}
Expand All @@ -30,9 +38,18 @@ protected static <T extends Enum<T>> T get(String format, T[] values, T defaultV
return defaultValue;
}

protected static <T extends Enum<T>> boolean isSupported(String fileName, T[] values, T defaultValue) {
/**
* Checks if the given file name is supported by the specified enum values.
*
* @param <T> The type of the enum.
* @param fileName The name of the file to check.
* @param values The array of enum values to search.
* @param defaultValue The default value to use for comparison.
* @return true if the file is supported, false otherwise.
*/
static <T extends Enum<T>> boolean isSupported(String fileName, T[] values, T defaultValue) {
String extension = FileUtilities.getExtension(fileName);
if (extension == null || extension.isEmpty()) {
if (extension.isEmpty()) {
return false;
}

Expand All @@ -45,14 +62,22 @@ protected static <T extends Enum<T>> boolean isSupported(String fileName, T[] va
return false;
}

protected static <T extends Enum<T>> String[] getAllExtensions(T[] values, T defaultValue) {
/**
* Retrieves all extensions for the specified enum values.
*
* @param <T> The type of the enum.
* @param values The array of enum values to search.
* @param defaultValue The default value to exclude from the result.
* @return An array of strings representing all extensions.
*/
static <T extends Enum<T>> String[] getAllExtensions(T[] values, T defaultValue) {
ArrayList<String> arrList = new ArrayList<>();
for (T format : values) {
if (format != defaultValue) {
arrList.add(format.toString());
}
}

return arrList.toArray(new String[arrList.size()]);
return arrList.toArray(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* A container class for managing font resources. This class extends the ResourcesContainer class, specifically for Font objects.
*/
public final class Fonts extends ResourcesContainer<Font> {
private static final Logger log = Logger.getLogger(Fonts.class.getName());

Fonts() {}
Fonts() {
}

/**
* Retrieves a font with the specified name and size.
*
* @param name The name of the font.
* @param size The size of the font.
* @return The derived font with the specified size, or null if the font is not found.
*/
public Font get(String name, float size) {
Font font = this.get(name);
if (font == null) {
Expand All @@ -22,6 +33,13 @@ public Font get(String name, float size) {
return font.deriveFont(size);
}

/**
* Retrieves a font with the specified name and style.
*
* @param name The name of the font.
* @param style The style of the font (e.g., Font.PLAIN, Font.BOLD).
* @return The derived font with the specified style, or null if the font is not found.
*/
public Font get(String name, int style) {
Font font = this.get(name);
if (font == null) {
Expand All @@ -31,6 +49,14 @@ public Font get(String name, int style) {
return font.deriveFont(style);
}

/**
* Retrieves a font with the specified name, style, and size.
*
* @param name The name of the font.
* @param style The style of the font (e.g., Font.PLAIN, Font.BOLD).
* @param size The size of the font.
* @return The derived font with the specified style and size, or null if the font is not found.
*/
public Font get(String name, int style, float size) {
Font font = this.get(name);
if (font == null) {
Expand All @@ -47,7 +73,7 @@ public Font get(String name, int style, float size) {
* @param resourceName
* The name of the font
* @return The loaded font.
*
*
* @see Font#createFont(int, java.io.File)
* @see Font#getFont(String)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package de.gurkenlabs.litiengine.resources;

import de.gurkenlabs.litiengine.entities.Rotation;
import de.gurkenlabs.litiengine.util.Imaging;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

import de.gurkenlabs.litiengine.entities.Rotation;
import de.gurkenlabs.litiengine.util.Imaging;

/**
* A container class for managing image resources. This class extends the ResourcesContainer class, specifically for BufferedImage objects.
*/
public final class Images extends ResourcesContainer<BufferedImage> {
Images() {}
Images() {
}

/**
* Loads all images from the specified texture atlas.
*
* @param textureAtlas
* The texture atlas that contains all the images.
*
* @param textureAtlas The texture atlas that contains all the images.
*/
public void load(TextureAtlas textureAtlas) {
BufferedImage atlasImage = Resources.images().get(textureAtlas.getAbsoluteImagePath());
Expand All @@ -35,12 +36,9 @@ public void load(TextureAtlas textureAtlas) {
}

/**
* Loads the image by the specified resourceName. This method supports both loading images from a folder and loading
* them from the resources.
* Loads the image by the specified resourceName. This method supports both loading images from a folder and loading them from the resources.
*
* @param resourceName
* The path to the image.
*
* @param resourceName The path to the image.
* @return the image
*/
@Override
Expand Down
Loading

0 comments on commit f25cd96

Please sign in to comment.