FileDocCategorySizeDatePackage
POPMID3V2Frame.javaAPI Docjid3 0.4610167Sun Feb 06 18:11:23 GMT 2005org.blinkenlights.jid3.v2

POPMID3V2Frame

public class POPMID3V2Frame extends ID3V2Frame
Frame containing a popularimeter.
author
paul

Fields Summary
private String
m_sEmailToUser
private int
m_iPopularity
private int
m_iPlayCount
Constructors Summary
public POPMID3V2Frame(String sEmailToUser, int iPopularity, int iPlayCount)
Creates a new instance of POPMID3V2Frame.

param
sEmailToUser the email address of the user to be informed of this track's popularity
param
iPopularity the popularity rating of this track (1=worst, 255=best, 0=unknown)
param
iPlayCount the current playcount of this file (must be positive)
throws
ID3Exception if sEmailToUser not provided, or if either iPopularity or iPlayCount values are out of range

    
                                                                     
          
         
    
        if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
        {
            throw new ID3Exception("Email address is required in POPM frame.");
        }
        m_sEmailToUser = sEmailToUser;
        if ((iPopularity < 0) || (iPopularity > 255))
        {
            throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
        }
        m_iPopularity = iPopularity;
        if (iPlayCount < 0)
        {
            throw new ID3Exception("Play count cannot be negative in POPM frame.");
        }
        m_iPlayCount = iPlayCount;
    
public POPMID3V2Frame(String sEmailToUser, int iPopularity)
Creates a new instance of POPMID3V2Frame, not specifying the play count value.

param
sEmailToUser the email address of the user to be informed of this track's popularity
param
iPopularity the popularity rating of this track (1=worst, 255=best, 0=unknown)
throws
ID3Exception if sEmailToUser not provided, or if either iPopularity or iPlayCount values are out of range

        if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
        {
            throw new ID3Exception("Email address is required in POPM frame.");
        }
        m_sEmailToUser = sEmailToUser;
        if ((iPopularity < 0) || (iPopularity > 255))
        {
            throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
        }
        m_iPopularity = iPopularity;
        m_iPlayCount = -1;
    
public POPMID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // email to user
            m_sEmailToUser = oFrameDataID3DIS.readStringToNull();
            
            // popularity
            m_iPopularity = oFrameDataID3DIS.readUnsignedByte();
            
            // play count (optional)
            if (oFrameDataID3DIS.available() > 0)
            {
                if (oFrameDataID3DIS.available() == 4)
                {
                    m_iPlayCount = oFrameDataID3DIS.readBE32();
                }
                else
                {
                    // overflow (seriously, this will never _really_ happen...)
                    m_iPlayCount = Integer.MAX_VALUE;
                }
            }
            else
            {
                // no play count
                m_iPlayCount = -1;
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

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

        if ((oOther == null) || (!(oOther instanceof POPMID3V2Frame)))
        {
            return false;
        }
        
        POPMID3V2Frame oOtherPOPM = (POPMID3V2Frame)oOther;
        
        return (m_sEmailToUser.equals(oOtherPOPM.m_sEmailToUser) &&
                (m_iPopularity == oOtherPOPM.m_iPopularity) &&
                (m_iPlayCount == oOtherPOPM.m_iPlayCount));
    
public java.lang.StringgetEmailToUser()
Get the email address of the user to be informed about the popularity of this track.

return
the email address of the user

        return m_sEmailToUser;
    
protected byte[]getFrameId()

        return "POPM".getBytes();
    
public intgetPlayCount()
Get the play count value for this track.

return
the play count for this track (-1 = not specified)

        return m_iPlayCount;
    
public intgetPopularity()
Get the popularity rating of this track (1=worst, 255=best, 0=unknown)

return
the popularity of this track

        return m_iPopularity;
    
public voidsetPopularity(java.lang.String sEmailToUser, int iPopularity, int iPlayCount)
Set the popularity values for this frame.

param
sEmailToUser the email address of the user to be informed of this track's popularity
param
iPopularity the popularity rating of this track (1=worst, 255=best, 0=unknown)
param
iPlayCount the current playcount of this file (must be positive)
throws
ID3Exception if sEmailToUser not provided, or if either iPopularity or iPlayCount values are out of range
throws
ID3Exception if this frame is in a tag with another POPM frame which would have the same email address

        String sOrigEmailToUser = m_sEmailToUser;
        int iOrigPopularity = m_iPopularity;
        int iOrigPlayCount = m_iPlayCount;
        
        if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
        {
            throw new ID3Exception("Email address is required in POPM frame.");
        }
        if ((iPopularity < 0) || (iPopularity > 255))
        {
            throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
        }
        if (iPlayCount < 0)
        {
            throw new ID3Exception("Play count cannot be negative in POPM frame.");
        }

        m_sEmailToUser = sEmailToUser;
        m_iPopularity = iPopularity;
        m_iPlayCount = iPlayCount;
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sEmailToUser = sOrigEmailToUser;
            m_iPopularity = iOrigPopularity;
            m_iPlayCount = iOrigPlayCount;
            
            throw e;
        }
    
public voidsetPopularity(java.lang.String sEmailToUser, int iPopularity)
Set the popularity values for this frame, not specifying a play count value.

param
sEmailToUser the email address of the user to be informed of this track's popularity
param
iPopularity the popularity rating of this track (1=worst, 255=best, 0=unknown)
throws
ID3Exception if sEmailToUser not provided, or if either iPopularity or iPlayCount values are out of range
throws
ID3Exception if this frame is in a tag with another AENC frame which would have the same email address

        String sOrigEmailToUser = m_sEmailToUser;
        int iOrigPopularity = m_iPopularity;
        int iOrigPlayCount = m_iPlayCount;
        
        if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
        {
            throw new ID3Exception("Email address is required in POPM frame.");
        }
        if ((iPopularity < 0) || (iPopularity > 255))
        {
            throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
        }

        m_sEmailToUser = sEmailToUser;
        m_iPopularity = iPopularity;
        m_iPlayCount = -1;

        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sEmailToUser = sOrigEmailToUser;
            m_iPopularity = iOrigPopularity;
            m_iPlayCount = iOrigPlayCount;
            
            throw e;
        }
    
public java.lang.StringtoString()

        return "Popularimeter: Email To User=[" + m_sEmailToUser + "], Popularity=" + m_iPopularity +
               "], Play Count=[" + m_iPlayCount + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // email address plus null
        oIDOS.write(m_sEmailToUser.getBytes());
        oIDOS.write(0);
        // popularity
        oIDOS.write(m_iPopularity);
        // play count
        if (m_iPlayCount >= 0)
        {
            oIDOS.writeBE32(m_iPlayCount);
        }