org.jaudiotagger.audio.generic
Class AbstractTag

java.lang.Object
  extended by org.jaudiotagger.audio.generic.AbstractTag
All Implemented Interfaces:
Tag
Direct Known Subclasses:
GenericTag, Mp4Tag, VorbisCommentTag

public abstract class AbstractTag
extends java.lang.Object
implements Tag

This class is the default implementation for Tag and introduces some more useful functionality to be implemented.

Author:
Raphaël Slinckx

Constructor Summary
AbstractTag()
           
 
Method Summary
 void add(TagField field)
          Add field
 void addAlbum(java.lang.String s)
          Add (another) album
 void addArtist(java.lang.String s)
          Add (another) artist
 void addComment(java.lang.String s)
          Add (another) comment
 void addGenre(java.lang.String s)
          Add (another) genre
 void addTitle(java.lang.String s)
          Add (another) title
 void addTrack(java.lang.String s)
          Add (another) track
 void addYear(java.lang.String s)
          (Add (another) year
abstract  TagField createAlbumField(java.lang.String content)
          Creates a field which represents the "album".
The field will already contain the given content.
abstract  TagField createArtistField(java.lang.String content)
          Creates a field which represents the "artist".
The field will already contain the given content.
abstract  TagField createCommentField(java.lang.String content)
          Creates a field which represents the "comment".
The field will already contain the given content.
abstract  TagField createGenreField(java.lang.String content)
          Creates a field which represents the "genre".
The field will already contain the given content.
 TagField createTagField(TagFieldKey genericKey, java.lang.String value)
          Create a new TagField based on generic key
abstract  TagField createTitleField(java.lang.String content)
          Creates a field which represents the "title".
The field will already contain the given content.
abstract  TagField createTrackField(java.lang.String content)
          Creates a field which represents the "track".
The field will already contain the given content.
abstract  TagField createYearField(java.lang.String content)
          Creates a field which represents the "year".
The field will already contain the given content.
 void deleteTagField(TagFieldKey tagFieldKey)
          Delete any instance of tag fields with this key
 java.util.List<TagField> get(java.lang.String id)
          Get list of fields within this tag with the specified id
 java.util.List<TagField> get(TagFieldKey id)
          Returns a list of TagField objects whose "id" is the specified one.
 java.util.List getAlbum()
          (overridden)
 java.util.List getArtist()
          Get Artist
 java.util.List getComment()
          Get Comment
 int getFieldCount()
          Return field count TODO:There must be a more efficient way to do this.
 java.util.Iterator getFields()
          Iterator over all the fields within the tag, handle multiple fields with the same id
 java.lang.String getFirst(java.lang.String id)
          Retrieve the first value that exists for this key
 java.lang.String getFirst(TagFieldKey genericKey)
          Retrieve String value of first tagfield that exists for this key
 java.lang.String getFirstAlbum()
          Get the first album or empty string if doesnt exist
 java.lang.String getFirstArtist()
          Get the first artist or empty string if doesnt exist
 java.lang.String getFirstComment()
          Get the first comment or empty string if doesnt exist
 TagField getFirstField(java.lang.String id)
          Retrieve the first tagfield that exists for this key
 java.lang.String getFirstGenre()
          Get the first genre or empty string if doesnt exist
 java.lang.String getFirstTitle()
          Get the first title or empty string if doesnt exist
 java.lang.String getFirstTrack()
          Get the first track or empty string if doesnt exist
 java.lang.String getFirstYear()
          Get the first year or empty string if doesnt exist
 java.util.List getGenre()
          Get the genres or empty list if none exist
 java.util.List getTitle()
          Get the titles or empty list if none exist
 java.util.List getTrack()
          Get the tracks or empty list if none exist
 java.util.List getYear()
          Get the years or empty list if none exist
 boolean hasCommonFields()
          Does this tag contain any comon fields
 boolean hasField(java.lang.String id)
          Does this tag contain a field with the specified id
 boolean isEmpty()
          Is this tag empty
 void set(TagField field)
          Set field Changed:Just because field is empty it doesnt mean it should be deleted.
 void setAlbum(java.lang.String s)
          Set or add album
 void setArtist(java.lang.String s)
          Set or add artist
 void setComment(java.lang.String s)
          Set or add comment
 boolean setEncoding(java.lang.String enc)
          Set or add encoding
 void setGenre(java.lang.String s)
          Set or add genre
 void setTitle(java.lang.String s)
          Set or add title
 void setTrack(java.lang.String s)
          Set or add track
 void setYear(java.lang.String s)
          Set or add year
 java.lang.String toString()
          (overridden)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractTag

public AbstractTag()
Method Detail

add

public void add(TagField field)
Add field

Specified by:
add in interface Tag
Parameters:
field - The field to add.
See Also:

Changed so add empty fields


addAlbum

public void addAlbum(java.lang.String s)
Add (another) album

Specified by:
addAlbum in interface Tag
Parameters:
s - Album description
See Also:
Tag.addAlbum(java.lang.String)

addArtist

public void addArtist(java.lang.String s)
Add (another) artist

Specified by:
addArtist in interface Tag
Parameters:
s - Artist's name
See Also:
Tag.addArtist(java.lang.String)

addComment

public void addComment(java.lang.String s)
Add (another) comment

Specified by:
addComment in interface Tag
Parameters:
s - Comment.
See Also:
Tag.addComment(java.lang.String)

addGenre

public void addGenre(java.lang.String s)
Add (another) genre

Specified by:
addGenre in interface Tag
Parameters:
s - Genre
See Also:
Tag.addGenre(java.lang.String)

addTitle

public void addTitle(java.lang.String s)
Add (another) title

Specified by:
addTitle in interface Tag
Parameters:
s - Title
See Also:
Tag.addTitle(java.lang.String)

addTrack

public void addTrack(java.lang.String s)
              throws FieldDataInvalidException
Add (another) track

Specified by:
addTrack in interface Tag
Parameters:
s - Track
Throws:
FieldDataInvalidException
See Also:
Tag.addTrack(java.lang.String)

addYear

public void addYear(java.lang.String s)
(Add (another) year

Specified by:
addYear in interface Tag
Parameters:
s - Year
See Also:
Tag.addYear(java.lang.String)

get

public java.util.List<TagField> get(java.lang.String id)
Get list of fields within this tag with the specified id

Specified by:
get in interface Tag
Parameters:
id - The field id.
Returns:
A list of TagField objects with the given "id".
See Also:
Tag.get(java.lang.String)

get

public java.util.List<TagField> get(TagFieldKey id)
                             throws KeyNotFoundException
Description copied from interface: Tag
Returns a list of TagField objects whose "id" is the specified one.

Specified by:
get in interface Tag
Parameters:
id -
Returns:
Throws:
KeyNotFoundException

getFirst

public java.lang.String getFirst(java.lang.String id)
Description copied from interface: Tag
Retrieve the first value that exists for this key

Specified by:
getFirst in interface Tag
Parameters:
id -
Returns:
matches for this saudio-specific key

getFirstField

public TagField getFirstField(java.lang.String id)
Description copied from interface: Tag
Retrieve the first tagfield that exists for this key

Can be used to retrieve fields with any identifier, useful if the identifier is not within the jaudiotagger enum

Specified by:
getFirstField in interface Tag
Parameters:
id - audio specific key
Returns:
tag field or null if doesnt exist

getAlbum

public java.util.List getAlbum()
(overridden)

Specified by:
getAlbum in interface Tag
Returns:
See Also:
Tag.getAlbum()

getArtist

public java.util.List getArtist()
Get Artist

Specified by:
getArtist in interface Tag
Returns:
See Also:
Tag.getArtist()

getComment

public java.util.List getComment()
Get Comment

Specified by:
getComment in interface Tag
Returns:
See Also:
Tag.getComment()

getFields

public java.util.Iterator getFields()
Description copied from interface: Tag
Iterator over all the fields within the tag, handle multiple fields with the same id

Specified by:
getFields in interface Tag
Returns:
iterator over whole list
See Also:
Tag.getFields()

getFieldCount

public int getFieldCount()
Return field count TODO:There must be a more efficient way to do this.

Specified by:
getFieldCount in interface Tag
Returns:
field count

getFirstAlbum

public java.lang.String getFirstAlbum()
Get the first album or empty string if doesnt exist

Specified by:
getFirstAlbum in interface Tag
Returns:
See Also:
Tag.getFirstAlbum()

getFirstArtist

public java.lang.String getFirstArtist()
Get the first artist or empty string if doesnt exist

Specified by:
getFirstArtist in interface Tag
Returns:
See Also:
Tag.getFirstArtist()

getFirstComment

public java.lang.String getFirstComment()
Get the first comment or empty string if doesnt exist

Specified by:
getFirstComment in interface Tag
Returns:
See Also:
Tag.getFirstComment()

getFirstGenre

public java.lang.String getFirstGenre()
Get the first genre or empty string if doesnt exist

Specified by:
getFirstGenre in interface Tag
Returns:
See Also:
Tag.getFirstGenre()

getFirstTitle

public java.lang.String getFirstTitle()
Get the first title or empty string if doesnt exist

Specified by:
getFirstTitle in interface Tag
Returns:
See Also:
Tag.getFirstTitle()

getFirstTrack

public java.lang.String getFirstTrack()
Get the first track or empty string if doesnt exist

Specified by:
getFirstTrack in interface Tag
Returns:
See Also:
Tag.getFirstTrack()

getFirstYear

public java.lang.String getFirstYear()
Get the first year or empty string if doesnt exist

Specified by:
getFirstYear in interface Tag
Returns:
See Also:
Tag.getFirstYear()

getGenre

public java.util.List getGenre()
Get the genres or empty list if none exist

Specified by:
getGenre in interface Tag
Returns:
See Also:
Tag.getGenre()

getTitle

public java.util.List getTitle()
Get the titles or empty list if none exist

Specified by:
getTitle in interface Tag
Returns:
See Also:
Tag.getTitle()

getTrack

public java.util.List getTrack()
Get the tracks or empty list if none exist

Specified by:
getTrack in interface Tag
Returns:
See Also:
Tag.getTrack()

getYear

public java.util.List getYear()
Get the years or empty list if none exist

Specified by:
getYear in interface Tag
Returns:
See Also:
Tag.getYear()

hasCommonFields

public boolean hasCommonFields()
Does this tag contain any comon fields

Specified by:
hasCommonFields in interface Tag
Returns:
true if a common field is present.
See Also:
Tag.hasCommonFields()

hasField

public boolean hasField(java.lang.String id)
Does this tag contain a field with the specified id

Specified by:
hasField in interface Tag
Parameters:
id - The field id to look for.
Returns:
true if tag contains a TagField with the given id.
See Also:
Tag.hasField(java.lang.String)

isEmpty

public boolean isEmpty()
Is this tag empty

Specified by:
isEmpty in interface Tag
Returns:
true if tag contains no field.
See Also:
Tag.isEmpty()

set

public void set(TagField field)
Set field Changed:Just because field is empty it doesnt mean it should be deleted. That should be the choice of the developer. (Or does this break things)

Specified by:
set in interface Tag
See Also:
Tag.set(org.jaudiotagger.tag.TagField)

setAlbum

public void setAlbum(java.lang.String s)
Set or add album

Specified by:
setAlbum in interface Tag
See Also:
Tag.setAlbum(java.lang.String)

setArtist

public void setArtist(java.lang.String s)
Set or add artist

Specified by:
setArtist in interface Tag
See Also:
Tag.setArtist(java.lang.String)

setComment

public void setComment(java.lang.String s)
Set or add comment

Specified by:
setComment in interface Tag
See Also:
Tag.setComment(java.lang.String)

setEncoding

public boolean setEncoding(java.lang.String enc)
Set or add encoding

Specified by:
setEncoding in interface Tag
See Also:
Tag.setEncoding(java.lang.String)

setGenre

public void setGenre(java.lang.String s)
Set or add genre

Specified by:
setGenre in interface Tag
See Also:
Tag.setGenre(java.lang.String)

setTitle

public void setTitle(java.lang.String s)
Set or add title

Specified by:
setTitle in interface Tag
See Also:
Tag.setTitle(java.lang.String)

setTrack

public void setTrack(java.lang.String s)
              throws FieldDataInvalidException
Set or add track

Specified by:
setTrack in interface Tag
Throws:
FieldDataInvalidException
See Also:
Tag.setTrack(java.lang.String)

setYear

public void setYear(java.lang.String s)
Set or add year

Specified by:
setYear in interface Tag
See Also:
Tag.setYear(java.lang.String)

toString

public java.lang.String toString()
(overridden)

Specified by:
toString in interface Tag
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

createTagField

public TagField createTagField(TagFieldKey genericKey,
                               java.lang.String value)
                        throws KeyNotFoundException,
                               FieldDataInvalidException
Description copied from interface: Tag
Create a new TagField based on generic key

Only textual data supported at the moment. The genericKey will be mapped to the correct implementation key and return a TagField.

Specified by:
createTagField in interface Tag
Parameters:
genericKey - is the generic key
value - to store
Returns:
Throws:
KeyNotFoundException
FieldDataInvalidException

getFirst

public java.lang.String getFirst(TagFieldKey genericKey)
                          throws KeyNotFoundException
Description copied from interface: Tag
Retrieve String value of first tagfield that exists for this key

Specified by:
getFirst in interface Tag
Returns:
String value or empty string
Throws:
KeyNotFoundException

deleteTagField

public void deleteTagField(TagFieldKey tagFieldKey)
                    throws KeyNotFoundException
Description copied from interface: Tag
Delete any instance of tag fields with this key

Specified by:
deleteTagField in interface Tag
Throws:
KeyNotFoundException

createAlbumField

public abstract TagField createAlbumField(java.lang.String content)
Creates a field which represents the "album".
The field will already contain the given content.

Parameters:
content - The content of the created field.
Returns:
tagfield representing the "album"

createArtistField

public abstract TagField createArtistField(java.lang.String content)
Creates a field which represents the "artist".
The field will already contain the given content.

Parameters:
content - The content of the created field.
Returns:
tagfield representing the "artist"

createCommentField

public abstract TagField createCommentField(java.lang.String content)
Creates a field which represents the "comment".
The field will already contain the given content.

Parameters:
content - The content of the created field.
Returns:
tagfield representing the "comment"

createGenreField

public abstract TagField createGenreField(java.lang.String content)
Creates a field which represents the "genre".
The field will already contain the given content.

Parameters:
content - The content of the created field.
Returns:
tagfield representing the "genre"

createTitleField

public abstract TagField createTitleField(java.lang.String content)
Creates a field which represents the "title".
The field will already contain the given content.

Parameters:
content - The content of the created field.
Returns:
tagfield representing the "title"

createTrackField

public abstract TagField createTrackField(java.lang.String content)
                                   throws FieldDataInvalidException
Creates a field which represents the "track".
The field will already contain the given content.

Parameters:
content - The content of the created field.
Returns:
tagfield representing the "track"
Throws:
FieldDataInvalidException

createYearField

public abstract TagField createYearField(java.lang.String content)
Creates a field which represents the "year".
The field will already contain the given content.

Parameters:
content - The content of the created field.
Returns:
tagfield representing the "year"