id
stringlengths
36
36
text
stringlengths
1
1.25M
7621bff9-3232-433f-8b65-1ea2931cb4fa
@Override public ChessMoves.MoveType isValidMove(ChessBoard b, ChessPosition p) { if (p == null) return ChessMoves.MoveType.INVALID; if ((p.getCol() < 0) || (p.getCol() > 7) || (p.getRow() < 0) || (p.getRow() > 7)) return ChessMoves.MoveType.INVALID; int i = this.getPosition().getRow(); int j = this.getPosition().getCol(); if ((i == p.getRow()) && (j == p.getCol())) return ChessMoves.MoveType.INVALID; int row_diff = i - p.getRow(); int col_diff = j - p.getCol(); // Since bishops move only diagonally, this check covers it if (Math.abs(row_diff) != Math.abs(col_diff)) return ChessMoves.MoveType.INVALID; ChessMoves.MoveType can_move = ChessMoves.MoveType.NORMAL; // Figure out if you are going forward or backward int row_increment = (i < p.getRow())?1:-1; int col_increment = (j < p.getCol())?1:-1; try { for (i += row_increment, j += col_increment; (i != p.getRow()) && (j != p.getCol()); i += row_increment, j += col_increment) { ChessPiece piece = b.pieceAt(new ChessPosition(i, j)); if (piece != null) { can_move = ChessMoves.MoveType.INVALID; break; } } // One last check to make sure that there is nothing in the landing square ChessPiece piece = b.pieceAt(new ChessPosition(p.getRow(), p.getCol())); if (piece != null) { if (piece.getColor() != this.getColor()) can_move = ChessMoves.MoveType.CAPTURE; else can_move = ChessMoves.MoveType.INVALID; } } catch (ChessException e) { can_move = ChessMoves.MoveType.INVALID; } return can_move; }
3c6dd82d-cfb8-4365-b0b8-85d0f5990168
@Override public String getShortDescription() { if (this.clr == ChessColor.COLOR_BLACK) return new String("b"); else return new String("B"); }
1f28c118-8561-4dc8-a10f-7f7698cbd9f5
public String getImage() { if (this.clr == ChessColor.COLOR_BLACK) return new String("\u265D"); else return new String("\u2657"); }
0c0b85b1-7a21-456c-9157-9c75b3d781e6
protected ChessPiece(ChessColor c) { has_moved = false; clr = c; pos = null; }
302218ad-5baa-4562-ba0e-090897e59b69
public boolean madeFirstMove() { return has_moved; }
c0e4a6a2-b200-4c22-8f91-0173d426df26
protected void setColor(ChessColor c) { clr = c; }
5e0d04b3-f665-4c7c-9fce-58f0b2921f3a
protected void setPosition(ChessPosition p) { pos = p; }
611a475e-0168-4a27-a5ca-7645ecc0dd2d
public void capture() { pos = null; }
336a28d9-6b28-44be-87f7-436667da8383
public ChessColor getColor() { return clr; }
b4c81f81-2305-46e4-b717-1c9d6a1b0657
public ChessPosition getPosition() { return pos; }
60c3fa71-29ab-42eb-8361-72dd1164ad0b
public abstract ChessMoves nextMoves(ChessBoard b);
79651f9a-be04-43b5-a270-8d98e18753ba
public abstract ChessMoves.MoveType isValidMove(ChessBoard b, ChessPosition p);
e5655464-36bb-43f1-bf60-2fee7b155c72
protected abstract String getShortDescription();
980f4db5-049a-4eef-a20a-31d7a5dca940
protected abstract String getImage();
06c4aa9f-6499-42be-932d-557c2e8ddf37
public void makeMove(ChessBoard b, ChessPosition p) throws ChessException { ChessMoves.MoveType mt = isValidMove(b, p); if (mt != ChessMoves.MoveType.INVALID) { has_moved = true; pos = p; } else throw new ChessException("Invalid move to make for " + getShortDescription()); }
7eaf859e-676b-482b-ae12-421c238e8c99
private void printChessBoard() { System.out.print(" \t"); for (int i = 0; i < 8; i++) System.out.format("%5c ", (char)('A'+i)); System.out.print("\n"); // for each row for (int i = 0; i < 8; i++) { // Print the row number System.out.format("%4d\t", (8-i)); // Now print the moves for each cell on that row for (int j = 0; j < 8; j++) if (board[i][j] != null) System.out.printf("%5s ", board[i][j].getShortDescription()); else System.out.printf(" "); // Move to the next line System.out.print("\n"); } }
49da8e10-9622-445b-a2da-b141cb593839
public TextChessBoard() throws ChessException { super(); printChessBoard(); }
62cddded-c868-4a6e-8aa3-90571ddd04eb
public void makeMove(ChessPosition from, ChessPosition to) throws ChessException { super.makeMove(from, to); printChessBoard(); }
1549eee1-1de4-4e16-a353-c082405a6dd0
public void startGame() { Scanner s = new Scanner(System.in); ChessColor turn = ChessColor.COLOR_WHITE; do { System.out.printf("\n>> "); if (s.findInLine("([a-hA-H][1-8])\\s+([a-hA-H][1-8])") != null) { try { MatchResult mr = s.match(); if (mr.groupCount() == 2) { ChessPosition from_pos = new ChessPosition(mr.group(1)); ChessPiece from = pieceAt(from_pos); if (from != null) { if (from.getColor() != turn) System.out.println("Cannot move this piece. Not your turn"); else { // Make a move and switch sides ChessPosition to = new ChessPosition(mr.group(2)); makeMove(from_pos, to); turn = (turn == ChessColor.COLOR_BLACK)?ChessColor.COLOR_WHITE:ChessColor.COLOR_BLACK; } } else System.out.println("No piece to move at that position"); } else System.out.println("You must give the full move"); } catch (IllegalStateException is) { System.out.println("----> Error in input"); } catch (ChessException ce) { System.out.println(ce.getMessage()); } } else if (s.findInLine("([a-hA-H][1-8])") != null) { try { MatchResult mr = s.match(); if (mr.groupCount() == 1) { ChessPosition from_pos = new ChessPosition(mr.group(1)); ChessPiece from = pieceAt(from_pos); if (from != null) { if (from.getColor() != turn) System.out.println("Cannot move this piece. Not your turn"); else { ChessMoves moves = from.nextMoves(this); for (int i = 0; i < moves.getCount(); i++) { ChessPosition pos = moves.getMove(i); ChessMoves.MoveType mt = moves.moveType(i); System.out.printf("\t%d: [%c,%c]", i+1, pos.getBoardCol(), pos.getBoardRow()); switch (mt) { case CAPTURE: System.out.println(" - Capture"); break; case CASTLE: case INVALID: case NORMAL: case PROMOTE: default: System.out.println(); break; } } } } else System.out.println("No piece to move at that position"); } } catch (IllegalStateException is) { System.out.println("----> Error in input"); } catch (ChessException ce) { System.out.println(ce.getMessage()); } } else System.out.println("Improper input given"); s.nextLine(); } while(true); }
da4183be-8611-42dd-b23b-6f8d026a3c81
public Knight(ChessColor c, int num) throws ChessException { super(c); int r = (c == ChessColor.COLOR_BLACK?0:7); if ((num != 1) && (num != 2)) throw new ChessException("Only two knights are allowed for each color"); if (num == 1) setPosition(new ChessPosition(r, 1)); else setPosition(new ChessPosition(r, 6)); }
f5c8df0c-adf8-4531-ae64-52c512590597
public Knight(ChessColor c, ChessPosition p) throws ChessException { super(c); setPosition(p); }
b921c031-6489-483d-b18d-378218102d62
public ChessMoves nextMoves(ChessBoard b) { // Initialize moves to 0 int i = this.getPosition().getRow(); int j = this.getPosition().getCol(); ChessMoves moves = new ChessMoves(); try { if (((i+2) < 8) && ((j+1) < 8)) { ChessPosition p = new ChessPosition(i+2, j+1); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } if (((i+2) < 8) && ((j-1) >= 0)) { ChessPosition p = new ChessPosition(i+2, j-1); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } if (((i-2) >= 0) && ((j+1) < 8)) { ChessPosition p = new ChessPosition(i-2, j+1); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } if (((i-2) >= 0) && ((j-1) >= 0)) { ChessPosition p = new ChessPosition(i-2, j-1); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } if (((i+1) < 8) && ((j+2) < 8)) { ChessPosition p = new ChessPosition(i+1, j+2); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } if (((i+1) < 8) && ((j-2) >= 0)) { ChessPosition p = new ChessPosition(i+1, j-2); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } if (((i-1) >= 0) && ((j+2) < 8)) { ChessPosition p = new ChessPosition(i-1, j+2); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } if (((i-1) >= 0) && ((j-2) >= 0)) { ChessPosition p = new ChessPosition(i-1, j-2); ChessPiece tp = b.pieceAt(p); if ((tp != null) && (tp.getColor() != this.clr)) moves.addMove(p, ChessMoves.MoveType.CAPTURE); else if (tp == null) moves.addMove(p); } } catch (Exception e) { // Since only valid positions are created, don't worry about exceptions moves = null; } return moves; }
858a4114-5a70-48cd-9124-1b426c7f7d26
@Override public ChessMoves.MoveType isValidMove(ChessBoard b, ChessPosition p) { if ((p.getCol() < 0) || (p.getCol() > 7) || (p.getRow() < 0) || (p.getRow() > 7)) return ChessMoves.MoveType.INVALID; ChessPosition cur_pos = this.getPosition(); int dx = Math.abs(cur_pos.getCol() - p.getCol()); int dy = Math.abs(cur_pos.getRow() - p.getRow()); if (((dx == 2) && (dy == 1)) || ((dx == 1) && (dy == 2))) { ChessPiece cp = b.pieceAt(p); if ((cp == null) || (cp.getColor() == this.getColor())) return ChessMoves.MoveType.NORMAL; else return ChessMoves.MoveType.CAPTURE; } else return ChessMoves.MoveType.INVALID; }
40c49770-1aa5-4921-96a7-64500b00c13f
@Override public String getShortDescription() { if (this.clr == ChessColor.COLOR_BLACK) return new String("n"); else return new String("N"); }
00447b30-9759-4e49-9a1b-11c595fe44de
public String getImage() { if (this.clr == ChessColor.COLOR_BLACK) return new String("\u265E"); else return new String("\u2658"); }
d7e3b6fd-a6ee-40bf-9381-6293be53656e
public ChessMoves() { count = 0; moves = null; }
33df8b52-f8b3-46bf-954f-f19cf96b6de8
public int getCount() { return count; }
d4ac4b1a-4e6f-45dd-b8b6-88684c0aa30d
public ChessPosition getMove(int num) throws ChessException { if (num > count) throw new ChessException("Moves out of bounds"); if (count == 0) throw new ChessException("No moves"); Move m = moves; for (int i = 0; i < num; i++) m = m.next; return m.pos; }
2b573f7a-2d57-40cf-ba7c-fb5adffb6f20
public MoveType moveType(int num) throws ChessException { if (num > count) throw new ChessException("Moves out of bounds"); if (count == 0) throw new ChessException("No moves"); Move m = moves; for (int i = 0; i < num; i++) m = m.next; return m.type; }
f7c34be4-2b5b-4885-b636-6bbb7c6e06f3
public void addMove(ChessPosition p) throws ChessException { addMove(p, MoveType.NORMAL); }
2df466af-25a4-43c5-b21e-0abcb53ade4d
public void addMove(ChessPosition p, MoveType t) throws ChessException { if (p == null) throw new ChessException("No move to add"); Move m = new Move(); m.pos = p; m.type = t; m.next = moves; moves = m; count++; }
961745b0-9b7c-42fd-863f-08cae41865bb
public Note(double frequency) throws IllegalArgumentException { this(frequency, DEFAULT_DURATION, DEFAULT_VOLUME); }
44064ba3-8e51-4fed-9b46-12461d7ca7f4
public Note(double frequency, Duration duration) throws IllegalArgumentException { this(frequency, duration, DEFAULT_VOLUME); }
b8802ea1-b421-476c-8417-4bcf3f1e58a1
public Note(double frequency, Duration duration, int volume) throws IllegalArgumentException { super(duration, volume); this.midiNumber = Frequency.getMIDINumber(frequency); this.frequency = frequency; this.tone = new Tone(frequency); this.octave = (midiNumber / 12) - 1; }
0b50c92b-e750-4273-b2e5-5133fb5de682
public Note(int midiNumber) throws IllegalArgumentException { this(midiNumber, DEFAULT_DURATION, DEFAULT_VOLUME); }
cf8f49d8-938a-4405-8c70-45eb23733d35
public Note(int midiNumber, Duration duration) throws IllegalArgumentException { this(midiNumber, duration, DEFAULT_VOLUME); }
4e640b3a-6e82-4890-b629-a0d828eadd48
public Note(int midiNumber, Duration duration, int volume) throws IllegalArgumentException { super(duration, volume); this.frequency = Frequency.getMIDINumberFrequency(midiNumber); this.midiNumber = midiNumber; this.tone = new Tone(midiNumber); this.octave = (midiNumber / 12) - 1; }
7f15d034-3511-4f48-b329-7ae1c0161549
public Note(String note) throws IllegalArgumentException { this(note, DEFAULT_DURATION, DEFAULT_VOLUME); }
30354662-75fa-4eb8-877b-20fd50fcd328
public Note(String note, Duration duration) throws IllegalArgumentException { this(note, duration, DEFAULT_VOLUME); }
68d90345-f40d-403a-820d-fda0a40f3ffb
public Note(String note, Duration duration, int volume) throws IllegalArgumentException { super(duration, volume); Note newNote = StringParser.getNote(note); this.frequency = newNote.frequency; this.midiNumber = newNote.midiNumber; this.tone = newNote.tone; this.octave = newNote.octave; }
41b027e6-173d-4206-953e-e9b4f7b2d932
public Note(Tone tone, int octave) { this(tone, octave, DEFAULT_DURATION, DEFAULT_VOLUME); }
c3aa6e1e-9dcd-4449-a242-711026ccd896
public Note(Tone tone, int octave, Duration duration) { this(tone, octave, duration, DEFAULT_VOLUME); }
11083678-142f-4cf3-898e-ddcbec05e571
public Note(Tone tone, int octave, Duration duration, int volume) { super(duration, volume); this.tone = tone; this.octave = octave; this.midiNumber = tone.getPitchClass() + 12 * (octave + 1); this.frequency = Frequency.getMIDINumberFrequency(midiNumber); }
d0a7dbc9-1148-45a1-9b12-f5bb08a40680
public Note(Note note) { this.frequency = note.frequency; this.midiNumber = note.midiNumber; this.tone = note.tone; this.octave = note.octave; // Inherited fields this.duration = note.duration; this.volume = note.volume; }
e2359de4-e91f-41f8-b72b-72c0b75c2b30
public Name getName() { return tone.getName(); }
4cad5839-eb1b-458e-b241-3f9d8d9a987c
public Accidental getAccidental() { return tone.getAccidental(); }
049c98d7-b45b-4ee0-ade5-047306eb9d58
public int getOctave() { return octave; }
4aec8bee-360d-42e5-9d21-e9db5c317e69
public double getFrequency() { return frequency; }
916ded96-ff26-433d-85e5-f56cd83022b6
public int getMIDINumber() { return midiNumber; }
6b6b91ca-ef9f-4ec4-8a60-b9d083ca1aba
public void semitoneUp() { transpose(1); }
82c3d607-6842-4402-97fe-55da6b0a7037
public void semitoneDown() { transpose(-1); }
2de596d8-011e-41af-8570-7f0fc24d00a1
public void transpose(int semitones) throws IllegalArgumentException { if (semitones == 0) { return; } Validator.transpose(midiNumber, semitones); this.midiNumber += semitones; this.frequency = Frequency.getMIDINumberFrequency(midiNumber); this.tone = new Tone(midiNumber); this.octave = (midiNumber / 12) - 1; }
5c777389-42ae-419b-a77d-0cb04824c40e
public void switchAccidental() { // Adjusts the octave when switching from C to B-Sharp... if (tone.getName() == Name.C && tone.getAccidental() == Accidental.Natural) { octave--; } // ...and viceversa. if (tone.getName() == Name.B && tone.getAccidental() == Accidental.Sharp) { octave++; } tone.switchAccidental(); }
507f6afe-daad-4350-a08a-460112f7992f
public String toStringExt() { StringBuilder sb = new StringBuilder(); sb.append("\nNOTE:\t\t"); sb.append(this.toString()); sb.append("\nName:\t\t"); sb.append(tone.getName()); sb.append("\nAccidental:\t"); sb.append(tone.getAccidental().getName()); sb.append("\nOctave:\t\t"); sb.append(octave); sb.append("\nFrequency:\t"); sb.append(String.format(Locale.ENGLISH, "%1.3f", frequency)); sb.append("Hz"); sb.append("\nMIDI number:\t"); sb.append(midiNumber); sb.append("\nDuration:\t"); sb.append(duration); sb.append("\nDuration Value:\t"); sb.append(duration.getDurationValue()); sb.append("\nVolume:\t\t"); sb.append(volume); sb.append("\n"); return sb.toString(); }
0c4e0ae2-7e41-44e2-9711-a0bf095f8601
@Override public String toString() { StringBuilder sb = new StringBuilder(3); sb.append(tone.getName()); if (tone.getAccidental() != Accidental.Natural) { sb.append(tone.getAccidental()); } sb.append(octave); return sb.toString(); }
a6babfc9-07e2-4dc3-bed3-2b3ebe84fb2c
@Override public boolean equals(Object o) { if (!(o instanceof Note)) { return false; } if (o == this) { return true; } Note n = (Note) o; if (n.getFrequency() == this.frequency && n.duration.equals(this.duration)) { return true; } return false; }
119e2e43-a9e9-4603-9d28-84009462b5ab
@Override public int hashCode() { final int prime = 911; int hash = super.hashCode(); hash = prime * hash + new Double(frequency).hashCode(); hash = prime * hash + midiNumber; hash = prime * hash + tone.hashCode(); hash = prime * hash + octave; return hash; }
64cd07ab-5f62-401c-8bc2-a7ba18cc0cbd
public Rest(Duration duration) { super(duration, 0); }
b0285ae2-1f3e-4113-a280-f167ebee80b4
@Override public void setVolume(int volume) throws UnsupportedOperationException { StringBuilder e = new StringBuilder(60); e.append("Invalid operation! "); e.append("The volume of a rest cannot be edited."); throw new UnsupportedOperationException(e.toString()); }
79079caf-22d1-4920-b2f8-172cd30654b6
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Rest ("); sb.append(duration); sb.append(")"); return sb.toString(); }
0869ee17-5b85-4e2e-a639-de5b21a74483
@Override public boolean equals(Object o) { if (!(o instanceof Rest)) { return false; } if (o == this) { return true; } Rest r = (Rest) o; if (r.duration.equals(this.duration)) { return true; } return false; }
30e6b503-5647-442d-932c-8e12ec16c5f5
@Override public int hashCode() { final int prime = 911; int hash = 1; hash = prime * hash + duration.hashCode(); hash = prime * hash + volume; return hash; }
fe48b4a1-95dd-4474-875e-24cbbb5cd0bf
Value(double value) { this.value = value; }
f30174ee-8382-4997-89f7-f22d63bc699b
public double getDurationValue() { return value; }
1702764b-0731-4003-9721-b32d88b43052
public Duration(Value value) { this.value = value; this.dots = Element.DEFAULT_DOTS; }
3656500e-4369-4d25-b7f6-ef8f6e54e92b
public Duration(Value value, int dots) throws IllegalArgumentException { Validator.dots(dots); this.value = value; this.dots = dots; }
cf662a85-e51f-4a08-adc5-959f5e2304ee
public Duration(Duration duration) { this.value = duration.value; this.dots = duration.dots; }
763ff6a7-8863-4923-a51a-17293ee1f576
public Value getValue() { return value; }
27c8df4e-b057-48d6-ae5a-03a2b0206687
public void setValue(Value value) { this.value = value; }
7d1e1fee-bb9f-4e7a-8f80-d66473d434a2
public int getDots() { return dots; }
a5793797-4e99-42be-98cb-6fb443df04c8
public void setDots(int dots) throws IllegalArgumentException { Validator.dots(dots); this.dots = dots; }
3f4cbfaa-b417-47f9-91ba-1cc59f196ab7
public double getDurationValue() { if (dots != 0) { switch (dots) { case 1: return increaseDurationValue(1 / 2.0); case 2: return increaseDurationValue(1 / 2.0 + 1 / 4.0); case 3: return increaseDurationValue(1 / 2.0 + 1 / 4.0 + 1 / 8.0); } } return value.getDurationValue(); }
48b875c9-01d9-454b-aa57-76ff4d9442cd
private double increaseDurationValue(double increment) { return value.getDurationValue() + value.getDurationValue() * increment; }
d3f23336-f685-4f26-bf53-35d112a24622
public String verboseString() { return null; }
dc8ff785-a6d8-4583-988b-69c999cd3216
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(value); if (dots > 0) { sb.append(" with "); sb.append(dots); sb.append((dots == 1 ? " dot" : " dots")); } return sb.toString(); }
e67b6ac5-8bb9-4c4b-ac35-bcb55d17d92d
@Override public boolean equals(Object o) { if (!(o instanceof Duration)) { return false; } if (o == this) { return true; } Duration d = (Duration) o; if (d.getDurationValue() != this.getDurationValue()) { return false; } if (d.getValue() == this.value && d.getDots() == this.dots){ return true; } return false; }
fb692c80-5633-4955-aeb3-48f165b2531c
@Override public int hashCode() { final int prime = 911; int hash = 1; hash = prime * hash + value.hashCode(); hash = prime * hash + dots; return hash; }
4dc9b752-96be-4021-b297-be0c57a96a6f
Value getValue();
60eba281-8a53-4e54-8a1e-315f30205a8b
void setValue(Value value);
dfb29318-1d03-4b54-b45c-5996ae817712
int getDots();
c3ba872f-d37f-47ec-8df2-3c82743420dc
void setDots(int dots);
da5ca58e-d38e-4006-8d20-3d438d1d66d0
double getDurationValue();
d22455c2-5060-41c0-abcf-73a938d165f7
int getVolume();
a8407ae1-d76e-4edd-b3ea-59afcf6eb9a7
void setVolume(int volume);
6478f5e2-1de0-4830-86d4-60cfd04286d4
public ScoreElement() { this(DEFAULT_DURATION, DEFAULT_VOLUME); }
20355ce0-0f8d-410d-bb0f-9f0b3d7c98d2
public ScoreElement(Duration duration) { this(duration, DEFAULT_VOLUME); }
33521d41-4869-4afc-b0a6-250435bd97e2
public ScoreElement(Duration duration, int volume) { this.duration = duration; this.volume = volume; }
84b059f5-c925-4216-afc9-758e4c0b8f65
public Value getValue() { return duration.getValue(); }
ba28bde9-d804-40ac-99a0-dd20bb0d652b
public void setValue(Value value) { duration.setValue(value); }
ff1c6a07-3660-4b34-b26c-fe2d701e93c9
public int getDots() { return duration.getDots(); }
ba256381-4820-48bb-b1c1-dae8287ef4e3
public void setDots(int dots) throws IllegalArgumentException { duration.setDots(dots); }
4d5a46a3-d772-4c21-975e-6fd12b8a94ae
public double getDurationValue() { return duration.getDurationValue(); }
f0c7a6c8-5529-4baf-b076-771271a05c67
public int getVolume() { return volume; }
3929a3da-d241-43d8-b3fa-b4ebe750a3d4
public void setVolume(int volume) throws IllegalArgumentException { Validator.volume(volume); this.volume = volume; }
fb227bd5-5435-45d0-a607-fcccdc6ed7fb
@Override public boolean equals(Object o) { if (!super.equals(o)) { return false; } if (!(o instanceof ScoreElement)) { return false; } if (o == this) { return true; } ScoreElement se = (ScoreElement) o; if (se.getDurationValue() == this.getDurationValue()) { return true; } return false; }
5b9c65b0-6b99-4635-96eb-4236b5e24539
@Override public int hashCode() { final int prime = 911; int hash = 1; hash = prime * hash + duration.hashCode(); hash = prime * hash + volume; return hash; }
b437c454-a833-4c91-a45b-f73cac658c3c
private StringParser() {}
8fc63dc9-eacc-4bcd-9508-69b3995e433e
public static Name getName(String noteName) { noteName = noteName.toUpperCase(); if (!(noteName.matches(NOTE_NAME_PATTERN))) { throw new IllegalArgumentException("Invalid note name!"); } switch (noteName) { case "C": return Name.C; case "D": return Name.D; case "E": return Name.E; case "F": return Name.F; case "G": return Name.G; case "A": return Name.A; case "B": return Name.B; default: return null; } }
9c9f48ee-104e-410d-8241-ac6576d473ad
public static Accidental getAccidental(String noteAccidental) { if (!(noteAccidental.matches(NOTE_ACCIDENTAL_PATTERN))) { throw new IllegalArgumentException("Invalid note accidental!"); } switch (noteAccidental) { case "b": return Accidental.Flat; case "#": return Accidental.Sharp; default: return null; } }
0d231e93-2949-4f46-8920-0a58c0511e1c
public static Note getNote(String note) { if (!(note.matches(NOTE_PATTERN))) { throw new IllegalArgumentException("Invalid note!"); } int argLength = note.length(); String name = String.valueOf(note.charAt(0)); if (argLength > 1) { // Name + Octave if (note.substring(1, argLength).matches("(-)?[0-9]+")) { String octave = note.substring(1, argLength); Tone tone = Tone.getTone(StringParser.getName(name), Element.DEFAULT_ACCIDENTAL); return new Note(tone, Integer.parseInt(octave)); } String accidental = String.valueOf(note.charAt(1)); // Name + Accidental + Octave if (argLength > 2) { String octave = note.substring(2, argLength); Tone tone = Tone.getTone(StringParser.getName(name), StringParser.getAccidental(accidental)); return new Note(tone, Integer.parseInt(octave)); } // Name + Accidental Tone tone = Tone.getTone(StringParser.getName(name), StringParser.getAccidental(accidental)); return new Note(tone, Element.DEFAULT_OCTAVE); } // Name Tone tone = Tone.getTone(StringParser.getName(name), Element.DEFAULT_ACCIDENTAL); return new Note(tone, Element.DEFAULT_OCTAVE); }