Skip to content
This repository was archived by the owner on Jan 8, 2023. It is now read-only.

Commit e2d2ae8

Browse files
committed
Reverts singleton enforcing
1 parent d51721e commit e2d2ae8

File tree

6 files changed

+21
-50
lines changed

6 files changed

+21
-50
lines changed

src/main/java/io/github/spair/byond/dmi/Dmi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public DmiState getState(final String stateName) {
6767
}
6868

6969
/**
70-
* Returns first sprite of state with provided name or null if wasn't found.
70+
* Returns the first sprite of state with provided name or null if wasn't found.
7171
*
7272
* @param stateName state name to search
7373
* @return {@link DmiSprite} instance or null if wasn't found
@@ -77,7 +77,7 @@ public DmiSprite getStateSprite(final String stateName) {
7777
}
7878

7979
/**
80-
* Returns first sprite of state with provided name and dir or null if wasn't found.
80+
* Returns the first sprite of state with provided name and dir or null if wasn't found.
8181
*
8282
* @param stateName state name to search
8383
* @return {@link DmiSprite} instance or null if wasn't found

src/main/java/io/github/spair/byond/dmi/DmiComparator.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.stream.Collectors;
1313

1414
/**
15-
* Singleton class to compare two {@link io.github.spair.byond.dmi.Dmi} objects and get result of comparison
15+
* Class to compare two {@link io.github.spair.byond.dmi.Dmi} objects and get result of comparison
1616
* as {@link io.github.spair.byond.dmi.DmiDiff}.
1717
*/
1818
public final class DmiComparator {
@@ -136,19 +136,4 @@ private <V> V extractOrNull(final Dmi dmi, final Function<Dmi, V> function) {
136136
return null;
137137
}
138138
}
139-
140-
private DmiComparator() {
141-
}
142-
143-
/**
144-
* Method to get singleton instance of DmiComparator object.
145-
* @return DmiComparator object instance
146-
*/
147-
public static DmiComparator getInstance() {
148-
return SingletonHolder.HOLDER_INSTANCE;
149-
}
150-
151-
private static class SingletonHolder {
152-
private static final DmiComparator HOLDER_INSTANCE = new DmiComparator();
153-
}
154139
}

src/main/java/io/github/spair/byond/dmi/DmiSlurper.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.Map;
1515

1616
/**
17-
* Singleton class to extract {@link io.github.spair.byond.dmi.Dmi} object from file/base64 string/raw input stream.
17+
* Class to extract {@link io.github.spair.byond.dmi.Dmi} object from file/base64 string/raw input stream.
1818
*/
1919
public final class DmiSlurper {
2020

@@ -71,19 +71,4 @@ public Dmi slurpUp(final String dmiName, final InputStream input) {
7171
throw new IllegalArgumentException("Provided DMI can't be read");
7272
}
7373
}
74-
75-
private DmiSlurper() {
76-
}
77-
78-
/**
79-
* Method to get singleton instance of DmiSlurper object.
80-
* @return DmiSlurper object instance
81-
*/
82-
public static DmiSlurper getInstance() {
83-
return SingletonHolder.HOLDER_INSTANCE;
84-
}
85-
86-
private static class SingletonHolder {
87-
private static final DmiSlurper HOLDER_INSTANCE = new DmiSlurper();
88-
}
8974
}

src/main/java/io/github/spair/byond/dmi/DmiState.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public String getStateName() {
2323
}
2424

2525
/**
26-
* Returns first available sprite. That means, that sprite will be the first frame and {@link SpriteDir#SOUTH} dir.
26+
* Returns the first available sprite.
27+
* That means, that sprite will be the first frame and {@link SpriteDir#SOUTH} dir.
2728
* If sprite wasn't found result will be null.
2829
*
2930
* @return first available sprite
@@ -33,7 +34,7 @@ public DmiSprite getSprite() {
3334
}
3435

3536
/**
36-
* Returns first available sprite of specified dir.
37+
* Returns the first available sprite of specified dir.
3738
* That means, that sprite will be the first frame of provided dir. If sprite wasn't found result will be null.
3839
*
3940
* @param dir dir to search sprite
@@ -48,16 +49,6 @@ public DmiSprite getSprite(final SpriteDir dir) {
4849
}
4950
}
5051

51-
/**
52-
* Returns the list of sprites for specified dir.
53-
*
54-
* @param dir dir to search sprite
55-
* @return list of sprites for specified dir
56-
*/
57-
public List<DmiSprite> getSpriteList(final SpriteDir dir) {
58-
return sprites.get(dir);
59-
}
60-
6152
/**
6253
* Returns sprite with specified dir and frame. If sprite wasn't found result will be null.
6354
* Frame count goes <b>from</b> '1' number, so if method get something lesser then it than exception will be thrown.
@@ -72,10 +63,20 @@ public DmiSprite getSprite(final SpriteDir dir, final int frame) {
7263
}
7364

7465
List<DmiSprite> spriteList = sprites.get(dir);
75-
if (Objects.nonNull(spriteList) && !spriteList.isEmpty()) {
66+
if (Objects.nonNull(spriteList) && !spriteList.isEmpty() && spriteList.size() >= frame - 1) {
7667
return spriteList.get(frame - 1);
7768
} else {
7869
return null;
7970
}
8071
}
72+
73+
/**
74+
* Returns the list of sprites for specified dir.
75+
*
76+
* @param dir dir to search sprite
77+
* @return list of sprites for specified dir
78+
*/
79+
public List<DmiSprite> getSpriteList(final SpriteDir dir) {
80+
return sprites.get(dir);
81+
}
8182
}

src/test/java/io/github/spair/byond/dmi/DmiComparatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
public class DmiComparatorTest {
1414

15-
private final DmiSlurper dmiSlurper = DmiSlurper.getInstance();
16-
private final DmiComparator dmiComparator = DmiComparator.getInstance();
15+
private final DmiSlurper dmiSlurper = new DmiSlurper();
16+
private final DmiComparator dmiComparator = new DmiComparator();
1717

1818
private static final String ROLLERBED_ORIGINAL_PATH = "src/test/resources/rollerbed_original.dmi";
1919
private static final String ROLLERBED_DIFF_PATH = "src/test/resources/rollerbed_original_diff.dmi";

src/test/java/io/github/spair/byond/dmi/DmiSlurperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class DmiSlurperTest {
1616

17-
private final DmiSlurper dmiSlurper = DmiSlurper.getInstance();
17+
private final DmiSlurper dmiSlurper = new DmiSlurper();
1818

1919
@Test
2020
public void testSlurpUpFromFile() {

0 commit comments

Comments
 (0)