org.farng.mp3.lyrics3.Lyrics3v1Iterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jid3lib Show documentation
Show all versions of jid3lib Show documentation
This library reads song information, such as song title, artist, and album, from an MP3 file. It supports ID3v1, ID3v1.1, Lyrics3v1, Lyrics3v2, ID3v2.2, ID3v2.3, and ID3v2.4 tags. MP3 Frame Headers can also be read. There is a FilenameTag, a ID3v2.4 tag that is intelligently derived from the file name. It contains tag synchronization utilities, multiple save options, and easy tag conversion methods.
The newest version!
package org.farng.mp3.lyrics3;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* This is a manual iterator for a Lyrics3v1 tag
*
* @author Eric Farng
* @version $Revision: 1.4 $
*/
public class Lyrics3v1Iterator implements Iterator {
private Lyrics3v1 tag = null;
private int lastIndex = 0;
private int removeIndex = 0;
/**
* Creates a new Lyrics3v1Iterator object.
*/
public Lyrics3v1Iterator(final Lyrics3v1 lyrics3v1Tag) {
this.tag = lyrics3v1Tag;
}
public boolean hasNext() {
return !((this.tag.getLyric().indexOf('\n', this.lastIndex) < 0) &&
(this.lastIndex > this.tag.getLyric().length()));
}
public Object next() {
final int nextIndex = this.tag.getLyric().indexOf('\n', this.lastIndex);
this.removeIndex = this.lastIndex;
final String line;
if (this.lastIndex >= 0) {
if (nextIndex >= 0) {
line = this.tag.getLyric().substring(this.lastIndex, nextIndex);
} else {
line = this.tag.getLyric().substring(this.lastIndex);
}
this.lastIndex = nextIndex;
} else {
throw new NoSuchElementException("Iteration has no more elements.");
}
return line;
}
public void remove() {
final String lyric = this.tag.getLyric().substring(0, this.removeIndex) +
this.tag.getLyric().substring(this.lastIndex);
this.tag.setLyric(lyric);
}
}