Skip to content

Commit e854bc0

Browse files
committed
Added @NotNull and @Nullable annotations.
1 parent 9e7f890 commit e854bc0

File tree

8 files changed

+144
-59
lines changed

8 files changed

+144
-59
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<version>5.8.2</version>
2222
<scope>test</scope>
2323
</dependency>
24+
<dependency>
25+
<groupId>org.jetbrains</groupId>
26+
<artifactId>annotations</artifactId>
27+
<version>23.0.0</version>
28+
<scope>compile</scope>
29+
</dependency>
2430
</dependencies>
2531

2632
<build>

src/main/java/cz/koca2000/nbs4j/CustomInstrument.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package cz.koca2000.nbs4j;
22

3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
36
public class CustomInstrument {
47

58
private String name = "";
@@ -16,7 +19,7 @@ public CustomInstrument(){}
1619
* Creates a copy of the custom instrument. Copy is not frozen and does not belong to any song.
1720
* @param customInstrument custom instrument to be copied
1821
*/
19-
public CustomInstrument(CustomInstrument customInstrument){
22+
public CustomInstrument(@NotNull CustomInstrument customInstrument){
2023
name = customInstrument.name;
2124
fileName = customInstrument.fileName;
2225
key = customInstrument.key;
@@ -26,7 +29,8 @@ public CustomInstrument(CustomInstrument customInstrument){
2629
song = null;
2730
}
2831

29-
CustomInstrument setSong(Song song){
32+
@NotNull
33+
CustomInstrument setSong(@NotNull Song song){
3034
if (this.song != null)
3135
throw new IllegalStateException("Custom instrument was already added to a song.");
3236

@@ -41,11 +45,10 @@ CustomInstrument setSong(Song song){
4145
* @throws IllegalArgumentException if the argument is null.
4246
* @throws IllegalStateException if the custom instrument is frozen and can not be modified
4347
*/
44-
public CustomInstrument setName(String name){
48+
@NotNull
49+
public CustomInstrument setName(@NotNull String name){
4550
throwIfFrozen();
4651

47-
if (name == null)
48-
throw new IllegalArgumentException("Name can not be null");
4952
this.name = name;
5053
return this;
5154
}
@@ -57,11 +60,10 @@ public CustomInstrument setName(String name){
5760
* @throws IllegalArgumentException if the argument is null.
5861
* @throws IllegalStateException if the custom instrument is frozen and can not be modified
5962
*/
60-
public CustomInstrument setFileName(String fileName){
63+
@NotNull
64+
public CustomInstrument setFileName(@NotNull String fileName){
6165
throwIfFrozen();
6266

63-
if (fileName == null)
64-
throw new IllegalArgumentException("File name can not be null");
6567
this.fileName = fileName;
6668
return this;
6769
}
@@ -73,6 +75,7 @@ public CustomInstrument setFileName(String fileName){
7375
* @throws IllegalArgumentException if the argument is not in range [0; 87] inclusive.
7476
* @throws IllegalStateException if the custom instrument is frozen and can not be modified
7577
*/
78+
@NotNull
7679
public CustomInstrument setKey(int key){
7780
throwIfFrozen();
7881

@@ -88,6 +91,7 @@ public CustomInstrument setKey(int key){
8891
* @return this instance of {@link CustomInstrument}
8992
* @throws IllegalStateException if the custom instrument is frozen and can not be modified
9093
*/
94+
@NotNull
9195
public CustomInstrument setShouldPressKey(boolean shouldPressKey) {
9296
throwIfFrozen();
9397

@@ -99,6 +103,7 @@ public CustomInstrument setShouldPressKey(boolean shouldPressKey) {
99103
* Returns the name of this custom instrument.
100104
* @return name of the instrument
101105
*/
106+
@NotNull
102107
public String getName() {
103108
return name;
104109
}
@@ -107,6 +112,7 @@ public String getName() {
107112
* Returns name of the file used in OpenNoteBlockStudio for this custom instrument.
108113
* @return file name
109114
*/
115+
@NotNull
110116
public String getFileName() {
111117
return fileName;
112118
}
@@ -119,6 +125,15 @@ public int getKey() {
119125
return key;
120126
}
121127

128+
/**
129+
* Returns the song this custom instrument belongs to.
130+
* @return {@link Song} if the custom instrument was added to a song; otherwise, null
131+
*/
132+
@Nullable
133+
public Song getSong() {
134+
return song;
135+
}
136+
122137
/**
123138
* Returns whether OpenNoteBlockStudio should press key on piano when playing this instrument's note.
124139
* @return true if the key should be pressed; otherwise, false

src/main/java/cz/koca2000/nbs4j/Layer.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package cz.koca2000.nbs4j;
22

3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
36
import java.util.Collections;
47
import java.util.HashMap;
58
import java.util.Map;
@@ -25,7 +28,7 @@ public Layer(){}
2528
* Makes a copy of the layer and its notes. Copy is not frozen.
2629
* @param layer layer to be copied
2730
*/
28-
public Layer(Layer layer){
31+
public Layer(@NotNull Layer layer){
2932
name = layer.name;
3033
volume = layer.volume;
3134
panning = layer.panning;
@@ -39,7 +42,8 @@ public Layer(Layer layer){
3942
}
4043
}
4144

42-
Layer setSong(Song song){
45+
@NotNull
46+
Layer setSong(@NotNull Song song){
4347
if (this.song != null)
4448
throw new IllegalStateException("Layer was already added to a song.");
4549

@@ -58,7 +62,7 @@ void removedFromSong(){
5862
this.song = null;
5963
}
6064

61-
void setNoteInternal(int tick, Note note, boolean fromSong){
65+
void setNoteInternal(int tick, @NotNull Note note, boolean fromSong){
6266
if (!fromSong && song != null) {
6367
song.setNote(tick, getIndexInSong(), note);
6468
return;
@@ -71,7 +75,8 @@ void setNoteInternal(int tick, Note note, boolean fromSong){
7175
notes.put(tick, note);
7276
}
7377

74-
public Layer setNote(int tick, Note note){
78+
@NotNull
79+
public Layer setNote(int tick, @NotNull Note note){
7580
setNoteInternal(tick, note, false);
7681
return this;
7782
}
@@ -88,6 +93,7 @@ void removeNoteInternal(int tick, boolean fromSong){
8893
}
8994
}
9095

96+
@NotNull
9197
public Layer removeNote(int tick){
9298
removeNoteInternal(tick, false);
9399
return this;
@@ -110,6 +116,7 @@ void freeze(){
110116
* @return this instance of {@link Layer}
111117
* @throws IllegalStateException if the layer is frozen and can not be modified
112118
*/
119+
@NotNull
113120
public Layer setLocked(boolean locked){
114121
throwIfFrozen();
115122

@@ -123,7 +130,8 @@ public Layer setLocked(boolean locked){
123130
* @return this instance of {@link Layer}
124131
* @throws IllegalStateException if the layer is frozen and can not be modified
125132
*/
126-
public Layer setName(String name){
133+
@NotNull
134+
public Layer setName(@NotNull String name){
127135
throwIfFrozen();
128136

129137
this.name = name;
@@ -137,6 +145,7 @@ public Layer setName(String name){
137145
* @throws IllegalArgumentException if the panning is out of range [-100; 100] inclusive]
138146
* @throws IllegalStateException if the layer is frozen and can not be modified
139147
*/
148+
@NotNull
140149
public Layer setPanning(int panning){
141150
throwIfFrozen();
142151

@@ -158,6 +167,7 @@ public Layer setPanning(int panning){
158167
* @throws IllegalArgumentException if volume is outside of range [0; 100] inclusive.
159168
* @throws IllegalStateException if the layer is frozen and can not be modified
160169
*/
170+
@NotNull
161171
public Layer setVolume(int volume){
162172
throwIfFrozen();
163173

@@ -188,6 +198,7 @@ public int getVolume(){
188198
* Returns the display name of the layer
189199
* @return name of the layer
190200
*/
201+
@NotNull
191202
public String getName() {
192203
return name;
193204
}
@@ -221,6 +232,7 @@ public boolean isFrozen(){
221232
* @param tick tick of the note
222233
* @return {@link Note} if there is a note on the give tick; otherwise, null
223234
*/
235+
@Nullable
224236
public Note getNote(int tick){
225237
return notes.getOrDefault(tick, null);
226238
}
@@ -229,6 +241,7 @@ public Note getNote(int tick){
229241
* Returns unmodifiable {@link Map} of notes indexed by their tick.
230242
* @return unmodifiable {@link Map}
231243
*/
244+
@NotNull
232245
public Map<Integer, Note> getNotes(){
233246
return Collections.unmodifiableMap(notes);
234247
}
@@ -252,6 +265,7 @@ public int getIndexInSong(){
252265
* Returns the song this layer belongs to.
253266
* @return {@link Song} if the layer was added to a song; otherwise, null
254267
*/
268+
@Nullable
255269
public Song getSong() {
256270
return song;
257271
}

src/main/java/cz/koca2000/nbs4j/NBSReader.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package cz.koca2000.nbs4j;
22

3+
import org.jetbrains.annotations.NotNull;
4+
35
import java.io.BufferedInputStream;
46
import java.io.DataInputStream;
57
import java.io.IOException;
@@ -9,7 +11,8 @@ class NBSReader {
911

1012
private NBSReader(){}
1113

12-
public static Song readSong(InputStream stream) {
14+
@NotNull
15+
public static Song readSong(@NotNull InputStream stream) {
1316
Song song = new Song();
1417

1518
try {
@@ -32,21 +35,22 @@ public static Song readSong(InputStream stream) {
3235
return song;
3336
}
3437

35-
private static short readShort(DataInputStream dataInputStream) throws IOException {
38+
private static short readShort(@NotNull DataInputStream dataInputStream) throws IOException {
3639
int byte1 = dataInputStream.readUnsignedByte();
3740
int byte2 = dataInputStream.readUnsignedByte();
3841
return (short) (byte1 + (byte2 << 8));
3942
}
4043

41-
private static int readInt(DataInputStream dataInputStream) throws IOException {
44+
private static int readInt(@NotNull DataInputStream dataInputStream) throws IOException {
4245
int byte1 = dataInputStream.readUnsignedByte();
4346
int byte2 = dataInputStream.readUnsignedByte();
4447
int byte3 = dataInputStream.readUnsignedByte();
4548
int byte4 = dataInputStream.readUnsignedByte();
4649
return (byte1 + (byte2 << 8) + (byte3 << 16) + (byte4 << 24));
4750
}
4851

49-
private static String readString(DataInputStream dataInputStream) throws IOException {
52+
@NotNull
53+
private static String readString(@NotNull DataInputStream dataInputStream) throws IOException {
5054
int length = readInt(dataInputStream);
5155
StringBuilder builder = new StringBuilder(length);
5256
for (; length > 0; --length) {
@@ -59,7 +63,8 @@ private static String readString(DataInputStream dataInputStream) throws IOExcep
5963
return builder.toString();
6064
}
6165

62-
private static HeaderData readHeader(Song song, DataInputStream stream) throws IOException {
66+
@NotNull
67+
private static HeaderData readHeader(@NotNull Song song, @NotNull DataInputStream stream) throws IOException {
6368
HeaderData data = new HeaderData();
6469

6570
short length = readShort(stream);
@@ -76,7 +81,7 @@ private static HeaderData readHeader(Song song, DataInputStream stream) throws I
7681
return data;
7782
}
7883

79-
private static void readMetadata(Song song, HeaderData header, DataInputStream stream) throws IOException {
84+
private static void readMetadata(@NotNull Song song, @NotNull HeaderData header, @NotNull DataInputStream stream) throws IOException {
8085
SongMetadata metadata = song.getMetadata();
8186

8287
metadata.setTitle(readString(stream))
@@ -100,7 +105,7 @@ private static void readMetadata(Song song, HeaderData header, DataInputStream s
100105
}
101106
}
102107

103-
private static void readNotes(Song song, HeaderData header, DataInputStream stream) throws IOException {
108+
private static void readNotes(@NotNull Song song, @NotNull HeaderData header, @NotNull DataInputStream stream) throws IOException {
104109
short tick = -1;
105110
while (true) {
106111
short jumpTicks = readShort(stream); // jumps till next tick
@@ -137,7 +142,7 @@ private static void readNotes(Song song, HeaderData header, DataInputStream stre
137142
}
138143
}
139144

140-
private static void readLayers(Song song, HeaderData header, DataInputStream stream) throws IOException {
145+
private static void readLayers(@NotNull Song song, @NotNull HeaderData header, @NotNull DataInputStream stream) throws IOException {
141146
for (int i = 0; i < song.getLayersCount(); i++) {
142147
Layer layer = song.getLayer(i);
143148

@@ -153,7 +158,7 @@ private static void readLayers(Song song, HeaderData header, DataInputStream str
153158
}
154159
}
155160

156-
private static void readCustomInstruments(Song song, DataInputStream stream) throws IOException {
161+
private static void readCustomInstruments(@NotNull Song song, @NotNull DataInputStream stream) throws IOException {
157162
byte customInstrumentCount = stream.readByte();
158163

159164
for (int index = 0; index < customInstrumentCount; index++) {

0 commit comments

Comments
 (0)