org.musicontroller.core
Class Keyword

java.lang.Object
  extended by org.musicontroller.core.LinkableAbs
      extended by org.musicontroller.core.Keyword
All Implemented Interfaces:
java.lang.Comparable<Keyword>, Linkable

public class Keyword
extends LinkableAbs
implements java.lang.Comparable<Keyword>

A Keyword is a namable property of a Song. Keywords are hierarchical objects. Their ordering is lexicographical after their name. The keyword names are case insensitive.

Author:
Varienaja

Field Summary
static int _maxSimilarity
           
static int _maxSimilarityPower
           
 
Constructor Summary
Keyword()
           
 
Method Summary
 boolean addChild(Keyword keyword)
          Adds a Keyword as a Child of this Keyword.
static int calculateSimilarity(boolean commonAncestorFound, int generalisations, int specialisations)
          calculate the similarity score based on the number of generalisations needed to get from one keyword to another.
 int compareTo(Keyword other)
           
static Keyword construct(java.lang.String name)
          Factory method constructs a keyword with the given name and a null parent.
static Keyword construct(java.lang.String name, Keyword parent)
          Factory method constructs a keyword with the given name and parent.
static java.util.Set<Keyword> constructHierarchy(java.util.Collection<Keyword> keywords)
          Constructs a Set of Keywords which are all topmost Keywords in the hierarchical Keyword-ordering.
 boolean equals(java.lang.Object obj)
          Define Keyword business equality.
 int getChildCount()
          Returns the amount of children (including grandchildren, etc) of this parent.
 java.util.Set<Keyword> getChildren()
          The (non-persistent) Children of this Keyword.
 Keyword getParent()
           
 java.lang.String getType()
           
 int hashCode()
           
 boolean isChildOf(Keyword other)
          Determines if this keyword is a child of another keyword.
 void setParent(Keyword parent)
           
 int similarityScore(Keyword keyword, java.lang.StringBuilder sbout)
          Calculates similarity between keywords.
 java.lang.String toString()
          A short human readable representation of the keyword.
 
Methods inherited from class org.musicontroller.core.LinkableAbs
getChanged, getId, getInserted, getName, normalizeName, setChanged, setId, setInserted, setName
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_maxSimilarityPower

public static final int _maxSimilarityPower
See Also:
Constant Field Values

_maxSimilarity

public static final int _maxSimilarity
See Also:
Constant Field Values
Constructor Detail

Keyword

public Keyword()
Method Detail

construct

public static Keyword construct(java.lang.String name)
Factory method constructs a keyword with the given name and a null parent.

Parameters:
name -
Returns:
The Keyword

construct

public static Keyword construct(java.lang.String name,
                                Keyword parent)
Factory method constructs a keyword with the given name and parent.

Parameters:
name -
Returns:
The Keyword

getParent

public Keyword getParent()

setParent

public void setParent(Keyword parent)
               throws KeywordCycleException
Throws:
KeywordCycleException

isChildOf

public boolean isChildOf(Keyword other)
Determines if this keyword is a child of another keyword. Used to prevent cyclic parent relationships.

Parameters:
other - The other keyword.
Returns:
True if this keyword is a child of the other keyword, or false otherwise.

equals

public boolean equals(java.lang.Object obj)
Define Keyword business equality. Two keywords are equal is there names are equal (disregarding case) and their parents are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
A short human readable representation of the keyword.

Overrides:
toString in class java.lang.Object

similarityScore

public int similarityScore(Keyword keyword,
                           java.lang.StringBuilder sbout)
Calculates similarity between keywords. The more parents the two keywords have in common, the more similar they are. The similarity is defined as the length of the common chain of parents the keyword share.

Parameters:
keyword - The Keyword to compare this one to. This may not be NULL (will throw NullPointerException).
Returns:
The amount of similar parents.

calculateSimilarity

public static int calculateSimilarity(boolean commonAncestorFound,
                                      int generalisations,
                                      int specialisations)
calculate the similarity score based on the number of generalisations needed to get from one keyword to another.

Parameters:
commonAncestorFound - True if the compared keyword have a shared ancestor.
generalisations - The number of generalisations.
specialisations - The number of specialisations.
Returns:
The calculated keyword similarity.

getType

public java.lang.String getType()
Specified by:
getType in interface Linkable

getChildren

public java.util.Set<Keyword> getChildren()
The (non-persistent) Children of this Keyword.

Returns:
This Keywords' child-keywords.

addChild

public boolean addChild(Keyword keyword)
Adds a Keyword as a Child of this Keyword. The Childs parent must already be set to this Keyword. The Children-property of a Keyword is non-persistent, and therefore uninitialized after reading a Keyword from persistent storage.

Parameters:
keyword - The (non-null) Child.
Returns:
Whether addition to the Children was successful.

constructHierarchy

public static java.util.Set<Keyword> constructHierarchy(java.util.Collection<Keyword> keywords)
Constructs a Set of Keywords which are all topmost Keywords in the hierarchical Keyword-ordering. The Keywords in the resulting Set all have their non-persistent children-properties initialized. The returned set is in lexicographical order.

Parameters:
keywords - All Keywords.
Returns:
The Set of topmost Keywords.

getChildCount

public int getChildCount()
Returns the amount of children (including grandchildren, etc) of this parent. The Hierarchy of the Keywords must have been constructed, otherwise the result of this method will be 0.

Returns:
The amount of Children.

compareTo

public int compareTo(Keyword other)
Specified by:
compareTo in interface java.lang.Comparable<Keyword>


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