FileDocCategorySizeDatePackage
TRCKTextInformationID3V2Frame.javaAPI Docjid3 0.467420Sun Feb 06 18:11:18 GMT 2005org.blinkenlights.jid3.v2

TRCKTextInformationID3V2Frame

public class TRCKTextInformationID3V2Frame extends TextInformationID3V2Frame
author
paul Text frame containing the track number or position in set of this recording in its original album or collection. The total number of tracks can also optionally be set.

Fields Summary
private int
m_iTrackNumber
private int
m_iTotalTracks
Constructors Summary
public TRCKTextInformationID3V2Frame(int iTrackNumber)
Constructor.

param
iTrackNumber the track number or position in set of this recording in its original album or collection
throws
ID3Exception if the track number is negative

        super(Integer.toString(iTrackNumber));
        
        if (iTrackNumber < 0)
        {
            throw new ID3Exception("Track number cannot be negative.");
        }

        m_iTrackNumber = iTrackNumber;
        m_iTotalTracks = -1;
    
public TRCKTextInformationID3V2Frame(int iTrackNumber, int iTotalTracks)
Constructor.

param
iTrackNumber the track number or position in set of this recording in its original album or collection
param
iTotalTracks the total number of tracks in the album or collection
throws
ID3Exception if the track number is negative, or the total number of tracks is less than the track number

        super(Integer.toString(iTrackNumber) + "/" + Integer.toString(iTotalTracks));

        if (iTrackNumber < 0)
        {
            throw new ID3Exception("Track number cannot be negative.");
        }
        if (iTotalTracks < iTrackNumber)
        {
            throw new ID3Exception("Total number of tracks must be at least as great as the track number.");
        }
        
        m_iTrackNumber = iTrackNumber;
        m_iTotalTracks = iTotalTracks;
    
public TRCKTextInformationID3V2Frame(InputStream oIS)

        super(oIS);

        try
        {
            if (m_sInformation.indexOf('/") == -1)
            {
                // no slash, just the track number
                m_iTrackNumber = Integer.parseInt(m_sInformation);
                m_iTotalTracks = -1;
            }
            else
            {
                String[] asPart = m_sInformation.split("/", 2);
                m_iTrackNumber = Integer.parseInt(asPart[0]);
                m_iTotalTracks = Integer.parseInt(asPart[1]);
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception("Encountered a corrupt TRCK part number frame.", e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitTRCKTextInformationID3V2Frame(this);
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof TRCKTextInformationID3V2Frame)))
        {
            return false;
        }
        
        TRCKTextInformationID3V2Frame oOtherTRCK = (TRCKTextInformationID3V2Frame)oOther;
        
        return ((m_iTrackNumber == oOtherTRCK.m_iTrackNumber) &&
                (m_iTotalTracks == oOtherTRCK.m_iTotalTracks) &&
                m_oTextEncoding.equals(oOtherTRCK.m_oTextEncoding) &&
                m_sInformation.equals(oOtherTRCK.m_sInformation));
    
protected byte[]getFrameId()

        return "TRCK".getBytes();
    
public intgetTotalTracks()
Get the total number of tracks in this album or collection.

return
the total number of tracks in this album or collection
throws
ID3Exception if the total number of tracks has not been set

        if (m_iTotalTracks != -1)
        {
            return m_iTotalTracks;
        }
        else
        {
            throw new ID3Exception("Total number of tracks not set.");
        }
    
public intgetTrackNumber()
Get the track number of this recording.

return
the track number

        return m_iTrackNumber;
    
public voidsetTrackNumber(int iTrackNumber)
Set the track number or position in set of this recording in its original album or collection.

param
iTrackNumber the track number or position in set of this recording in its original album or collection
throws
ID3Exception if the track number is negative

        if (iTrackNumber < 0)
        {
            throw new ID3Exception("Part number cannot be negative.");
        }

        m_iTrackNumber = iTrackNumber;
        m_iTotalTracks = -1;
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sInformation = Integer.toString(iTrackNumber);
    
public voidsetTrackNumberAndTotalTracks(int iTrackNumber, int iTotalTracks)
Set the track number or position in set of this recording in its original album or collection, and the total number of tracks in the complete set.

param
iTrackNumber the track number or position in set of this recording in its original album or collection
param
iTotalTracks the total number of tracks in the album or collection
throws
ID3Exception if the track number is negative, or the total number of tracks is less than the track number

        if (iTrackNumber < 0)
        {
            throw new ID3Exception("Track number cannot be negative.");
        }
        if (iTotalTracks < iTrackNumber)
        {
            throw new ID3Exception("Total number of tracks must be at least as great as the track number.");
        }

        m_iTrackNumber = iTrackNumber;
        m_iTotalTracks = iTotalTracks;
        
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sInformation = iTrackNumber + "/" + iTotalTracks;
    
public java.lang.StringtoString()

        return "Track number/Position in set: [" + m_sInformation + "]";