Skip to content

Commit

Permalink
[#816] Nameable is now Comparable. Code refactored.
Browse files Browse the repository at this point in the history
  • Loading branch information
DjThunder committed Jul 23, 2024
1 parent 73b61b1 commit fe8ce78
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @param <T> The object type handled by the list.
*/
// CHECKSTYLE IGNORE LINE: DataAbstractionCoupling
public abstract class ObjectListAbstract<T extends Nameable>
public abstract class ObjectListAbstract<T extends Nameable<T>>
{
/** Icon add. */
public static final Image ICON_ADD = UtilIcon.get("add.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @param <T> The object type handled by the list.
*/
public interface ObjectListListener<T extends Nameable>
public interface ObjectListListener<T extends Nameable<T>>
{
/**
* Notify when object has been selected from list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @param <T> The object type handled by the properties.
*/
public abstract class ObjectPropertiesAbstract<T extends Nameable>
public abstract class ObjectPropertiesAbstract<T extends Nameable<T>>
{
/**
* Create a text and its label.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @param repeat The repeat flag.
*/
public record Animation(String name, int firstFrame, int lastFrame, double speed, boolean reverse, boolean repeat)
implements Nameable
implements Nameable<Animation>
{

/** Animation default name. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Represents an input device, such as mouse, keyboard, joypad...
*/
public interface InputDevice extends Updatable, Nameable, Listenable<InputDeviceListener>
public interface InputDevice extends Updatable, Nameable<InputDevice>, Listenable<InputDeviceListener>
{
/**
* Set visibility.
Expand Down
17 changes: 8 additions & 9 deletions lionengine-core/src/main/java/com/b3dgs/lionengine/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@
* Represents a path to a resource located outside. This abstraction allows to load a resource from any kind of
* location, such as external storage, <code>JAR</code>... Can point to a file or a directory.
*/
public interface Media extends Nameable
public interface Media
{
/**
* Get the media name (excluding its path).
*
* @return The media name without its path.
*/
String getName();

/**
* Get the relative media path.
*
Expand Down Expand Up @@ -94,12 +101,4 @@ public interface Media extends Nameable
* @return <code>true</code> if in jar, <code>false</code> else.
*/
boolean isJar();

/**
* Get the media name (excluding its path).
*
* @return The media name without its path.
*/
@Override
String getName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@

/**
* Represents something that can be designated by a unique name.
*
* @param <T> The nameable type.
*/
public interface Nameable
public interface Nameable<T extends Nameable<T>> extends Comparable<T>
{
/**
* Get the name.
*
* @return The name value.
*/
String getName();

@Override
default int compareTo(T nameable)
{
return getName().compareTo(nameable.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @see ComponentCollision
*/
public record Collision(String name, int offsetX, int offsetY, int width, int height, boolean mirror)
implements Nameable
implements Nameable<Collision>
{

/** Compute automatically collision by using the owner size. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* @see com.b3dgs.lionengine.game.feature.tile.TileGroupsConfig
*/
public record TileGroup(String name, TileGroupType type, Set<Integer> tiles) implements Nameable
public record TileGroup(String name, TileGroupType type, Set<Integer> tiles) implements Nameable<TileGroup>
{
/**
* Create group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* @see CollisionFormula
*/
public record CollisionCategory(String name, Axis axis, int x, int y, boolean glue, List<CollisionGroup> groups)
implements Nameable
implements Nameable<CollisionCategory>
{
/**
* Create category.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public record CollisionFormula(String name,
CollisionRange range,
CollisionFunction function,
CollisionConstraint constraint)
implements Nameable
implements Nameable<CollisionFormula>
{
/**
* Create formula.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @see CollisionGroupConfig
* @see CollisionFormula
*/
public record CollisionGroup(String name, Collection<CollisionFormula> formulas) implements Nameable
public record CollisionGroup(String name, Collection<CollisionFormula> formulas) implements Nameable<CollisionGroup>
{
/**
* Check if tiles groups are same.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* Represents the possible movement from a tile.
*/
public enum MovementTile implements Nameable
public enum MovementTile implements Nameable<MovementTile>
{
/** Up movement. */
UP(0, 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @param name The category name.
* @param groups The associated groups.
*/
public record PathCategory(String name, Collection<String> groups) implements Nameable
public record PathCategory(String name, Collection<String> groups) implements Nameable<PathCategory>
{
/**
* Create category.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @param movements The allowed movements.
*/
public record PathData(String category, double cost, boolean blocking, Collection<MovementTile> movements)
implements Nameable
implements Nameable<PathData>
{
/**
* Create a path data.
Expand Down

0 comments on commit fe8ce78

Please sign in to comment.