📄 abstracttag.java
字号:
* @see com.hadeslee.jaudiotagger.tag.Tag#getFirstTrack()
*/
public String getFirstTrack()
{
List l = getTrack();
return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : "";
}
/**
* Get the first year or empty string if doesnt exist
*
* @see com.hadeslee.jaudiotagger.tag.Tag#getFirstYear()
*/
public String getFirstYear()
{
List l = getYear();
return (l.size() != 0) ? ((TagTextField) l.get(0)).getContent() : "";
}
/**
* Get the genres or empty list if none exist
*
* @see com.hadeslee.jaudiotagger.tag.Tag#getGenre()
*/
public List getGenre()
{
return get(getGenreId());
}
/**
* Returns the identifier for a field representing the "genre"<br>
*
* @return identifier for the "genre" field.
* @see TagField#getId()
*/
protected abstract String getGenreId();
/**
* Get the titles or empty list if none exist
*
* @see com.hadeslee.jaudiotagger.tag.Tag#getTitle()
*/
public List getTitle()
{
return get(getTitleId());
}
/**
* Returns the identifier for a field representing the "title"<br>
*
* @return identifier for the "title" field.
* @see TagField#getId()
*/
protected abstract String getTitleId();
/**
* Get the tracks or empty list if none exist
*
* @see com.hadeslee.jaudiotagger.tag.Tag#getTrack()
*/
public List getTrack()
{
return get(getTrackId());
}
/**
* Returns the identifier for a field representing the "track"<br>
*
* @return identifier for the "track" field.
* @see TagField#getId()
*/
protected abstract String getTrackId();
/**
* Get the years or empty list if none exist
*
* @see com.hadeslee.jaudiotagger.tag.Tag#getYear()
*/
public List getYear()
{
return get(getYearId());
}
/**
* Returns the identifier for a field representing the "year"<br>
*
* @return identifier for the "year" field.
* @see TagField#getId()
*/
protected abstract String getYearId();
/**
* Does this tag contain any comon fields
*
* @see com.hadeslee.jaudiotagger.tag.Tag#hasCommonFields()
*/
public boolean hasCommonFields()
{
return commonNumber != 0;
}
/**
* Does this tag contain a field with the specified id
*
* @see com.hadeslee.jaudiotagger.tag.Tag#hasField(java.lang.String)
*/
public boolean hasField(String id)
{
return get(id).size() != 0;
}
/**
* Determines whether the given charset encoding may be used for the
* represented tagging system.
*
* @param enc charset encoding.
* @return <code>true</code> if the given encoding can be used.
*/
protected abstract boolean isAllowedEncoding(String enc);
/**
* Is this tag empty
*
* @see com.hadeslee.jaudiotagger.tag.Tag#isEmpty()
*/
public boolean isEmpty()
{
return fields.size() == 0;
}
/**
* 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)
*
* @see com.hadeslee.jaudiotagger.tagcom.hadeslee.jaudiotaggerdiotagger.tag.TagField)
*/
public void set(TagField field)
{
if (field == null)
{
return;
}
// If there is already an existing field with same id
// and both are TextFields, we replace the first element
List<TagField> list = fields.get(field.getId());
if (list != null)
{
list.set(0,field);
return;
}
// Else we put the new field in the fields.
list = new ArrayList<TagField> ();
list.add(field);
fields.put(field.getId(), list);
if (field.isCommon())
{
commonNumber++;
}
}
/**
* Set or add album
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setAlbum(java.lang.String)
*/
public void setAlbum(String s)
{
set(createAlbumField(s));
}
/**
* Set or add artist
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setArtist(java.lang.String)
*/
public void setArtist(String s)
{
set(createArtistField(s));
}
/**
* Set or add comment
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setComment(java.lang.String)
*/
public void setComment(String s)
{
set(createCommentField(s));
}
/**
* Set or add encoding
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setEncoding(java.lang.String)
*/
public boolean setEncoding(String enc)
{
if (!isAllowedEncoding(enc))
{
return false;
}
Iterator it = getFields();
while (it.hasNext())
{
TagField field = (TagField) it.next();
if (field instanceof TagTextField)
{
((TagTextField) field).setEncoding(enc);
}
}
return true;
}
/**
* Set or add genre
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setGenre(java.lang.String)
*/
public void setGenre(String s)
{
set(createGenreField(s));
}
/**
* Set or add title
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setTitle(java.lang.String)
*/
public void setTitle(String s)
{
set(createTitleField(s));
}
/**
* Set or add track
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setTrack(java.lang.String)
*/
public void setTrack(String s)
throws FieldDataInvalidException
{
set(createTrackField(s));
}
/**
* Set or add year
*
* @see com.hadeslee.jaudiotagger.tag.Tag#setYear(java.lang.String)
*/
public void setYear(String s)
{
set(createYearField(s));
}
/**
* (overridden)
*
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuffer out = new StringBuffer();
out.append("Tag content:\n");
Iterator it = getFields();
while (it.hasNext())
{
TagField field = (TagField) it.next();
out.append("\t");
out.append(field.getId());
out.append(":");
out.append(field.toString());
out.append("\n");
}
return out.toString().substring(0, out.length() - 1);
}
//Should be overridden by all subclasses but provided empty impl
//as working one format at a time
//TODO remove
public TagField createTagField(TagFieldKey genericKey, String value)
throws KeyNotFoundException,FieldDataInvalidException
{
return null;
}
//Should be overridden by all subclasses but provided empty impl
//as working one format at a time
//TODO remove
public String getFirst(TagFieldKey genericKey)throws KeyNotFoundException
{
return null;
}
//Should be overridden by all subclasses but provided empty impl
//as working one format at a time
//TODO remove
public void deleteTagField(TagFieldKey tagFieldKey)
throws KeyNotFoundException
{
;
}
/**
* Delete all ocurrences of field.
*
* @param key
*/
protected void deleteField(String key)
{
Object removed = fields.remove(key);
//if (removed != null && field.isCommon())
// commonNumber--;
return;
}
/**
* Creates a field which represents the "album".<br>
* The field will already contain the given content.
*
* @param content The content of the created field.
* @return tagfield representing the "album"
*/
public abstract TagField createAlbumField(String content);
/**
* Creates a field which represents the "artist".<br>
* The field will already contain the given content.
*
* @param content The content of the created field.
* @return tagfield representing the "artist"
*/
public abstract TagField createArtistField(String content);
/**
* Creates a field which represents the "comment".<br>
* The field will already contain the given content.
*
* @param content The content of the created field.
* @return tagfield representing the "comment"
*/
public abstract TagField createCommentField(String content);
/**
* Creates a field which represents the "genre".<br>
* The field will already contain the given content.
*
* @param content The content of the created field.
* @return tagfield representing the "genre"
*/
public abstract TagField createGenreField(String content);
/**
* Creates a field which represents the "title".<br>
* The field will already contain the given content.
*
* @param content The content of the created field.
* @return tagfield representing the "title"
*/
public abstract TagField createTitleField(String content);
/**
* Creates a field which represents the "track".<br>
* The field will already contain the given content.
*
* @param content The content of the created field.
* @return tagfield representing the "track"
*/
public abstract TagField createTrackField(String content)
throws FieldDataInvalidException;
/**
* Creates a field which represents the "year".<br>
* The field will already contain the given content.
*
* @param content The content of the created field.
* @return tagfield representing the "year"
*/
public abstract TagField createYearField(String content);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -