diff options
author | Celtic Minstrel <celtic.minstrel.ca@some.place> | 2012-02-29 20:08:40 -0500 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-02-29 22:43:35 -0500 |
commit | 2a1fab3d57d56474a25dd504d8b4f95c5c1e807b (patch) | |
tree | 639ab0ff3c1cd17b18a6fc47f584b98ee6be236c /src/main | |
parent | 674ce005385d50ce18b8626d58189a156e9a9d62 (diff) | |
download | bukkit-2a1fab3d57d56474a25dd504d8b4f95c5c1e807b.tar bukkit-2a1fab3d57d56474a25dd504d8b4f95c5c1e807b.tar.gz bukkit-2a1fab3d57d56474a25dd504d8b4f95c5c1e807b.tar.lz bukkit-2a1fab3d57d56474a25dd504d8b4f95c5c1e807b.tar.xz bukkit-2a1fab3d57d56474a25dd504d8b4f95c5c1e807b.zip |
[Bleeding] Added sharp() and natural() factory functions to mirror the flat() one, sharped() and flattened() functions to get a note from an existing note, a toString(), and more tests. Addresses BUKKIT-861
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/Note.java | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/Note.java b/src/main/java/org/bukkit/Note.java index 8e053fd7..e1102e49 100644 --- a/src/main/java/org/bukkit/Note.java +++ b/src/main/java/org/bukkit/Note.java @@ -131,7 +131,7 @@ public class Note { */ public Note(int octave, Tone tone, boolean sharped) { if (sharped && !tone.isSharpable()) { - tone = tone == Tone.F ? Tone.G : Tone.values()[tone.ordinal() + 1]; + tone = Tone.values()[tone.ordinal() + 1]; sharped = false; } if (octave < 0 || octave > 2 || (octave == 2 && !(tone == Tone.F && sharped))) { @@ -144,16 +144,56 @@ public class Note { /** * Creates a new note for a flat tone, such as A-flat. * - * @param octave The octave where the note is in. Has to be 0 - 2. - * @param tone The tone within the octave. If the octave is 2 the note has to be F#. + * @param octave The octave where the note is in. Has to be 0 - 1. + * @param tone The tone within the octave. * @return The new note. */ public static Note flat(int octave, 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()); } /** + * Creates a new note for a sharp tone, such as A-sharp. + * + * @param octave The octave where the note is in. Has to be 0 - 2. + * @param tone The tone within the octave. If the octave is 2 the note has to be F#. + * @return The new note. + */ + public static Note sharp(int octave, Tone tone) { + return new Note(octave, tone, true); + } + + /** + * Creates a new note for a natural tone, such as A-natural. + * + * @param octave The octave where the note is in. Has to be 0 - 1. + * @param tone The tone within the octave. + * @return The new note. + */ + public static Note natural(int octave, Tone tone) { + Validate.isTrue(octave != 2, "Octave cannot be 2 for naturals"); + return new Note(octave, tone, false); + } + + /** + * @return The note a semitone above this one. + */ + public Note sharped() { + Validate.isTrue(note < 24, "This note cannot be sharped because it is the highest known note!"); + return new Note(note + 1); + } + + /** + * @return The note a semitone below this one. + */ + public Note flattened() { + Validate.isTrue(note > 0, "This note cannot be flattened because it is the lowest known note!"); + return new Note(note - 1); + } + + /** * Returns the internal id of this note. * * @return the internal id of this note. @@ -215,4 +255,9 @@ public class Note { return false; return true; } + + @Override + public String toString() { + return "Note{" + getTone().toString() + (isSharped() ? "#" : "") + "}"; + } } |