A couple of API improvements.
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -21,14 +21,15 @@ package itdelatrisu.opsu.beatmap;
|
||||
import itdelatrisu.opsu.GameMod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Data type containing all beatmaps in a beatmap set.
|
||||
*/
|
||||
public class BeatmapSet {
|
||||
public class BeatmapSet implements Iterable<Beatmap> {
|
||||
/** List of associated beatmaps. */
|
||||
private ArrayList<Beatmap> beatmaps;
|
||||
private final ArrayList<Beatmap> beatmaps;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -58,6 +59,9 @@ public class BeatmapSet {
|
||||
*/
|
||||
public Beatmap remove(int index) { return beatmaps.remove(index); }
|
||||
|
||||
@Override
|
||||
public Iterator<Beatmap> iterator() { return beatmaps.iterator(); }
|
||||
|
||||
/**
|
||||
* Returns an array of strings containing beatmap information.
|
||||
* <ul>
|
||||
@@ -139,7 +143,7 @@ public class BeatmapSet {
|
||||
|
||||
/**
|
||||
* Checks whether the beatmap set matches a given condition.
|
||||
* @param type the condition type (ar, cs, od, hp, bpm, length)
|
||||
* @param type the condition type (ar, cs, od, hp, bpm, length, star/stars)
|
||||
* @param operator the operator {@literal (=/==, >, >=, <, <=)}
|
||||
* @param value the value
|
||||
* @return true if the condition is met
|
||||
|
||||
@@ -171,8 +171,7 @@ public class BeatmapSetList {
|
||||
mapCount -= beatmapSet.size();
|
||||
if (beatmap.beatmapSetID > 0)
|
||||
MSIDdb.remove(beatmap.beatmapSetID);
|
||||
for (int i = 0, n = beatmapSet.size(); i < n; i++) {
|
||||
Beatmap bm = beatmapSet.get(i);
|
||||
for (Beatmap bm : beatmapSet) {
|
||||
if (bm.md5Hash != null)
|
||||
this.beatmapHashDB.remove(bm.md5Hash);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.newdawn.slick.Image;
|
||||
*/
|
||||
public class BeatmapSetNode {
|
||||
/** The associated beatmap set. */
|
||||
private BeatmapSet beatmapSet;
|
||||
private final BeatmapSet beatmapSet;
|
||||
|
||||
/** Index of the selected beatmap (-1 if not focused). */
|
||||
public int beatmapIndex = -1;
|
||||
@@ -57,6 +57,14 @@ public class BeatmapSetNode {
|
||||
*/
|
||||
public BeatmapSet getBeatmapSet() { return beatmapSet; }
|
||||
|
||||
/**
|
||||
* Returns the selected beatmap (based on {@link #beatmapIndex}).
|
||||
* @return the beatmap, or null if the index is invalid
|
||||
*/
|
||||
public Beatmap getSelectedBeatmap() {
|
||||
return (beatmapIndex < 0 || beatmapIndex >= beatmapSet.size()) ? null : beatmapSet.get(beatmapIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the button.
|
||||
* @param x the x coordinate
|
||||
|
||||
@@ -123,13 +123,11 @@ public enum BeatmapSortOrder {
|
||||
@Override
|
||||
public int compare(BeatmapSetNode v, BeatmapSetNode w) {
|
||||
int vMax = 0, wMax = 0;
|
||||
for (int i = 0, size = v.getBeatmapSet().size(); i < size; i++) {
|
||||
Beatmap beatmap = v.getBeatmapSet().get(i);
|
||||
for (Beatmap beatmap : v.getBeatmapSet()) {
|
||||
if (beatmap.endTime > vMax)
|
||||
vMax = beatmap.endTime;
|
||||
}
|
||||
for (int i = 0, size = w.getBeatmapSet().size(); i < size; i++) {
|
||||
Beatmap beatmap = w.getBeatmapSet().get(i);
|
||||
for (Beatmap beatmap : w.getBeatmapSet()) {
|
||||
if (beatmap.endTime > wMax)
|
||||
wMax = beatmap.endTime;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user