forked from quran/quran_android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move SuraAyahIterator into its own class
- Loading branch information
Showing
4 changed files
with
64 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/quran/labs/androidquran/data/SuraAyahIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.quran.labs.androidquran.data; | ||
|
||
public class SuraAyahIterator { | ||
|
||
private SuraAyah start; | ||
private SuraAyah end; | ||
|
||
private boolean started; | ||
private int curSura; | ||
private int curAyah; | ||
|
||
public SuraAyahIterator(SuraAyah start, SuraAyah end) { | ||
// Sanity check | ||
if (start.compareTo(end) <= 0) { | ||
this.start = start; | ||
this.end = end; | ||
} else { | ||
this.start = end; | ||
this.end = start; | ||
} | ||
reset(); | ||
} | ||
|
||
private void reset() { | ||
curSura = start.sura; | ||
curAyah = start.ayah; | ||
started = false; | ||
} | ||
|
||
public int getSura() { | ||
return curSura; | ||
} | ||
|
||
public int getAyah() { | ||
return curAyah; | ||
} | ||
|
||
private boolean hasNext() { | ||
return !started || curSura < end.sura || curAyah < end.ayah; | ||
} | ||
|
||
public boolean next() { | ||
if (!started) { | ||
return started = true; | ||
} else if (!hasNext()) { | ||
return false; | ||
} | ||
if (curAyah < QuranInfo.getNumAyahs(curSura)) { | ||
curAyah++; | ||
} else { | ||
curAyah = 1; | ||
curSura++; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters