org.musicontroller.dao
Class BagAndKeywordUtils

java.lang.Object
  extended by org.musicontroller.dao.BagAndKeywordUtils

public class BagAndKeywordUtils
extends java.lang.Object

This class manages persistent keyword bag objects.

Version:
$Id: BagAndKeywordUtils.java,v 1.1 2010/03/16 18:55:42 varienaja Exp $
Author:
deksels

Constructor Summary
BagAndKeywordUtils()
           
 
Method Summary
static Keywordbag addKeywordToBag(Keywordbag bag, Keyword keyword)
          Tries to find a keyword bag containing all the keywords in this bag plus the keyword in the parameter.
static void addKeywordToSong(Song song, Keyword kw)
          Add a keyword to the song.
static java.util.List<AiRelationBean> buildAiRelationBeanList(Playlist playlist)
          Constructs a list of AiRelationBean objects from a playlist.
static java.util.Set<AIRelation> buildAiRelationList(java.util.List<AiRelationBean> source)
          Converts the Set of AiRelationBean objects into a Set of AiRelation objects.
static java.util.Set<AIRelation> createRelations(java.lang.String artistfirstname, java.lang.String artistlastname, Band band, java.lang.String instruments)
          Construct a set of artist-instrument relations corresponding to an artist with the supplied first name and last name and the specified instrument names.
static AIBag getAIBag(java.util.Set<AIRelation> relations)
          Returns an artist_instrument bag containing exactly the artist-instrument relations specified in the argument.
static java.util.List<AIBag> getAIBags()
          Getter for the list of Artist-Instrument bag objects.
static java.util.List<Keywordbag> getBags()
          Getter for the list of keyword bag objects.
 Dao getDao()
          Getter for the DAO.
static Keyword getKeyword(java.lang.String keywordname)
          Locates the keyword in the database or constructs a new keyword if there isn't one already.
static Keywordbag getKeywordBag(java.util.Collection<Keyword> keywords)
          Returns a persistent keyword bag containing exactly the keywords in the parameter.
static Keywordbag getKeywordBag(java.lang.String songKeywords)
          Returns a keyword bag containing exactly the keywords specified as comma separated keywords in the argument.
static java.util.List<Keyword> getKeywordList(java.lang.String keywords)
          Returns a list of keywords corresponding to the comma separated list of keywords in the parameter.
static java.lang.String listKeywords(Keywordbag bag)
          Returns a String representation of all keywords in the bag, listing all keywords separated by commas.
static Keywordbag removeKeyWordFromBag(Keywordbag bag, Keyword keyword)
          Tries to find a keyword bag with all keywords of this bag minus the parameter keyword.
 void setDao(Dao dao)
          Setter for the DAO.
static java.util.List<Instrument> splitInstrumentList(java.lang.String instruments)
          Splits the string into comma separated instrument names and returns a list with instruments with the names in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BagAndKeywordUtils

public BagAndKeywordUtils()
Method Detail

addKeywordToBag

public static Keywordbag addKeywordToBag(Keywordbag bag,
                                         Keyword keyword)
Tries to find a keyword bag containing all the keywords in this bag plus the keyword in the parameter. Returns the bag when found or constructs a new bag with the required keywords when it does not exist. This will allways return a different bag than the bag on which the method was invoked!

Parameters:
bag - The keyword bag to add the keyword to.
keyword - The keyword to add.
Returns:
the keywordbag containing all current keywords + the new keyword.

removeKeyWordFromBag

public static Keywordbag removeKeyWordFromBag(Keywordbag bag,
                                              Keyword keyword)
Tries to find a keyword bag with all keywords of this bag minus the parameter keyword. Returns the bag when found. If not found, constructs a new bag with the required keywords and return it.

Parameters:
bag - The bag to remove the keyword from.
keyword - The keyword to exclude.
Returns:
A keyword bag with all keywords of this bag minus the keyword parameter.

addKeywordToSong

public static void addKeywordToSong(Song song,
                                    Keyword kw)
Add a keyword to the song. The method will save the keyword and the keyword bag, but not the song (permitting more edits). The method will create a keyword bag for the song if none exists. If the song or kw parameters is null, nothing happens.

Parameters:
song - The song.
kw - The keyword to add.

getKeyword

public static Keyword getKeyword(java.lang.String keywordname)
Locates the keyword in the database or constructs a new keyword if there isn't one already. The returned keyword object is always persistent. Returns NULL if the keyword name is NULL or if the trimmed name is "".

Parameters:
keywordname - The sought keyword name.
Returns:
A keyword object with the specified keyword name.

getKeywordBag

public static Keywordbag getKeywordBag(java.lang.String songKeywords)
Returns a keyword bag containing exactly the keywords specified as comma separated keywords in the argument. Empty keywords are ignored.

Parameters:
songKeywords - A comma separated list of Keywords.
Returns:
A KeywordBag containing exactly the keywords listed in the argument.

getKeywordBag

public static Keywordbag getKeywordBag(java.util.Collection<Keyword> keywords)
Returns a persistent keyword bag containing exactly the keywords in the parameter.

Parameters:
keywords - The list of keywords.
Returns:
A keyword bag containing exactly the keywords in the list.

getKeywordList

public static java.util.List<Keyword> getKeywordList(java.lang.String keywords)
Returns a list of keywords corresponding to the comma separated list of keywords in the parameter.

Parameters:
keywords - The comma separted list of keywords.
Returns:
A list of keywords corresponding to the keyword names in the list.

getAIBag

public static AIBag getAIBag(java.util.Set<AIRelation> relations)
Returns an artist_instrument bag containing exactly the artist-instrument relations specified in the argument.

Parameters:
relations - The set of artist instrument relations that must be present in the result.
Returns:
A KeywordBag containing exactly the artist-instrument relations in the argument.

listKeywords

public static java.lang.String listKeywords(Keywordbag bag)
Returns a String representation of all keywords in the bag, listing all keywords separated by commas.

Parameters:
bag - The keyword bag to list.
Returns:
A comma separated list of commas in the keyword bag.

getBags

public static java.util.List<Keywordbag> getBags()
Getter for the list of keyword bag objects.

Returns:
The list of keyword bags.

getAIBags

public static java.util.List<AIBag> getAIBags()
Getter for the list of Artist-Instrument bag objects.

Returns:
The list of AIBags.

getDao

public Dao getDao()
Getter for the DAO.

Returns:
The dao.

setDao

public void setDao(Dao dao)
Setter for the DAO.

Parameters:
dao - The DAO.

buildAiRelationBeanList

public static java.util.List<AiRelationBean> buildAiRelationBeanList(Playlist playlist)
Constructs a list of AiRelationBean objects from a playlist. This method first constructs a hash of hashes containing information on the artists playing instruments on tracks. A graphical rendition of this data-structure: Hash |__A | |__Hash | |__x | | |__List | | |__1,2 | |__y | |__List | |__1,2 |__B |__Hash |__z |__List |__1 Artist A plays Instrument x on tracks 1,2 Artist A plays Instrument y on track 1,2 Artist B plays Instrument z on track 2 Then, this data structure is translated into a list of AiRelationBean objects: [ <"A","x,y",(1,2)> , <"B","z",(1)> ] This list is the final result.

Parameters:
playlist - The playlist to build the aiRelationBeanList for.
Returns:
A list of AiRelationBean objects with all artist-instrument relations in the source.

buildAiRelationList

public static java.util.Set<AIRelation> buildAiRelationList(java.util.List<AiRelationBean> source)
Converts the Set of AiRelationBean objects into a Set of AiRelation objects. This is the reverse operation of the buildAiRelationBeanList() method.

Parameters:
source - The set of AiRelationBean objects to convert.
Returns:
A set of AiRelation objects corresponding to the source parameter.

splitInstrumentList

public static java.util.List<Instrument> splitInstrumentList(java.lang.String instruments)
Splits the string into comma separated instrument names and returns a list with instruments with the names in the list.

Parameters:
instruments - The comma separated list of instruments.
Returns:
A list of persistent instruments.

createRelations

public static java.util.Set<AIRelation> createRelations(java.lang.String artistfirstname,
                                                        java.lang.String artistlastname,
                                                        Band band,
                                                        java.lang.String instruments)
Construct a set of artist-instrument relations corresponding to an artist with the supplied first name and last name and the specified instrument names. Constructs persistent instruments and artists as necessary.

Parameters:
artistfirstname - The first name of the artist.
artistlastname - The last name of the artist.
band - A band the artist is a part of (or null).
instruments - The comma separated list of instruments.
Returns:
A set of artist-instrument relations corresponding to the input parameters.


Copyright © 2010 A.J.V.. All Rights Reserved.