FileDocCategorySizeDatePackage
TDATTextInformationID3V2Frame.javaAPI Docjid3 0.466194Sun Feb 06 18:11:21 GMT 2005org.blinkenlights.jid3.v2

TDATTextInformationID3V2Frame

public class TDATTextInformationID3V2Frame extends TextInformationID3V2Frame
author
paul Text frame which contains the date of the recording, not including the year.

Fields Summary
private int
m_iDay
private int
m_iMonth
Constructors Summary
public TDATTextInformationID3V2Frame(int iDay, int iMonth)
Constructor.

param
iDay the day on which the recording was made
param
iMonth the month in which the recording was made
throws
ID3Exception if the given day/month combination is not valid

        // make sure the values we've been given for day and month are legal
        if ( ! checkDayMonthValidity(iDay, iMonth))
        {
            throw new ID3Exception("Invalid day/month combination " + iDay + "/" + iMonth + ".");
        }
        
        NumberFormat oNF = new DecimalFormat("00");
        m_sInformation = oNF.format(iDay) + oNF.format(iMonth);
        
        m_iDay = iDay;
        m_iMonth = iMonth;
    
public TDATTextInformationID3V2Frame(InputStream oIS)

        super(oIS);
        
        // try to parse day and month (we aren't going to require valid dates when reading from a file,
        // but they do have to be numbers)
        try
        {
            String sDay = m_sInformation.substring(0, 2);
            m_iDay = Integer.parseInt(sDay);
            
            String sMonth = m_sInformation.substring(2, 4);
            m_iMonth = Integer.parseInt(sMonth);
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception("Encountered a corrupt TDAT recording date frame.", e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitTDATTextInformationID3V2Frame(this);
    
private booleancheckDayMonthValidity(int iDay, int iMonth)
Internal method which checks a given day/month combination to see if it is valid.

param
iDay day value
param
iMonth month value
return
true if day/month are valid, false otherwise

        return !
        ( 
          (iDay < 1) ||
          // months with 31 days
          (
            (
              (iMonth == 1) ||
              (iMonth == 3) ||
              (iMonth == 5) ||
              (iMonth == 7) ||
              (iMonth == 8) ||
              (iMonth == 10) ||
              (iMonth == 12)
            ) &&
            (iDay > 31)
          ) ||
          // months with 30 days
          (
            (
              (iMonth == 4) ||
              (iMonth == 6) ||
              (iMonth == 9) ||
              (iMonth == 11)
            ) &&
            (iDay > 30)
          ) ||
          // february (no year specified, so can't check for leap years
          (
            (iMonth == 2) &&
            (iDay > 29) 
          )
        );
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof TDATTextInformationID3V2Frame)))
        {
            return false;
        }
        
        TDATTextInformationID3V2Frame oOtherTDAT = (TDATTextInformationID3V2Frame)oOther;
        
        return ((m_iDay == oOtherTDAT.m_iDay) &&
                (m_iMonth == oOtherTDAT.m_iMonth) &&
                m_oTextEncoding.equals(oOtherTDAT.m_oTextEncoding) &&
                m_sInformation.equals(oOtherTDAT.m_sInformation));
    
public intgetDay()
Get the day on which this recording was made.

return
the day on which the recording was made

        return m_iDay;
    
protected byte[]getFrameId()

        return "TDAT".getBytes();
    
public intgetMonth()
Get the month in which the recording was made.

return
the month in which the recording was made

        return m_iMonth;
    
public voidsetDate(int iDay, int iMonth)
Set the date on which this recording was made.

param
iDay the day on which the recording was made
param
iMonth the month in which the recording was made
throws
ID3Exception if the given day/month combination is not valid/

        // make sure the values we've been given for day and month are legal
        if ( ! checkDayMonthValidity(iDay, iMonth))
        {
            throw new ID3Exception("Invalid day/month combination " + iDay + "/" + iMonth + ".");
        }

        NumberFormat oNF = new DecimalFormat("00");
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sInformation = oNF.format(iDay) + oNF.format(iMonth);
        
        m_iDay = iDay;
        m_iMonth = iMonth;
    
public java.lang.StringtoString()

        return "Date (DDMM): [" + m_sInformation + "]";