SPIGOT-2540: Add nullability annotations to entire Bukkit API

By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
Bukkit/Spigot
2019-03-13 17:42:57 +11:00
parent e069a80fd8
commit 416c865476
565 changed files with 5372 additions and 2008 deletions

View File

@ -5,6 +5,8 @@ import java.util.Map;
import org.apache.commons.lang.Validate;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A note class to store a specific note.
@ -100,6 +102,7 @@ public class Note {
* @deprecated Magic value
*/
@Deprecated
@Nullable
public static Tone getById(byte id) {
return BY_DATA.get(id);
}
@ -139,7 +142,7 @@ public class Note {
* to be F#.
* @param sharped Set if the tone is sharped (e.g. for F#).
*/
public Note(int octave, Tone tone, boolean sharped) {
public Note(int octave, @NotNull Tone tone, boolean sharped) {
if (sharped && !tone.isSharpable()) {
tone = Tone.values()[tone.ordinal() + 1];
sharped = false;
@ -158,7 +161,8 @@ public class Note {
* @param tone The tone within the octave.
* @return The new note.
*/
public static Note flat(int octave, Tone tone) {
@NotNull
public static Note flat(int octave, @NotNull Tone tone) {
Validate.isTrue(octave != 2, "Octave cannot be 2 for flats");
tone = tone == Tone.G ? Tone.F : Tone.values()[tone.ordinal() - 1];
return new Note(octave, tone, tone.isSharpable());
@ -172,7 +176,8 @@ public class Note {
* to be F#.
* @return The new note.
*/
public static Note sharp(int octave, Tone tone) {
@NotNull
public static Note sharp(int octave, @NotNull Tone tone) {
return new Note(octave, tone, true);
}
@ -183,7 +188,8 @@ public class Note {
* @param tone The tone within the octave.
* @return The new note.
*/
public static Note natural(int octave, Tone tone) {
@NotNull
public static Note natural(int octave, @NotNull Tone tone) {
Validate.isTrue(octave != 2, "Octave cannot be 2 for naturals");
return new Note(octave, tone, false);
}
@ -191,6 +197,7 @@ public class Note {
/**
* @return The note a semitone above this one.
*/
@NotNull
public Note sharped() {
Validate.isTrue(note < 24, "This note cannot be sharped because it is the highest known note!");
return new Note(note + 1);
@ -199,6 +206,7 @@ public class Note {
/**
* @return The note a semitone below this one.
*/
@NotNull
public Note flattened() {
Validate.isTrue(note > 0, "This note cannot be flattened because it is the lowest known note!");
return new Note(note - 1);
@ -233,6 +241,7 @@ public class Note {
*
* @return the tone of this note.
*/
@NotNull
public Tone getTone() {
return Tone.getById(getToneByte());
}