/*
 * $Id: VKCKeyword.java,v 1.16 2005/01/07 13:16:04 jonyp Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: VKCKeyword.java,v $
 * Revision 1.16  2005/01/07 13:16:04  jonyp
 * changed toString method
 *
 * Revision 1.15  2004/06/27 17:16:55  marbobo
 * + Quellcode maintenance
 *
 * Revision 1.14  2003/07/31 08:53:25  lawern
 * VKCKeyword(String term) erzeugt jetzt externe Keywords
 *
 * Revision 1.13  2003/07/31 08:02:49  lawern
 * internal auf boolean umgestellt
 *
 * Revision 1.12  2003/07/30 12:32:38  jonyp
 * *** empty log message ***
 *
 * Revision 1.11  2003/04/24 12:07:04  jonyp
 * double return of getWeight
 *
 * Revision 1.10  2003/04/23 12:51:59  marbobo
 * bugfix
 *
 * Revision 1.9  2003/04/14 14:04:18  lawern
 * der TermDescriptor wird jetzt innerhalb des Objektes erzeugt
 *
 * Revision 1.8  2003/04/14 13:44:23  lawern
 * Im Konstruktor ohne weight wird das weight jetzt auf 1 gesetzt, da das keyword ansonsten nicht berücksichtigt wird.
 *
 * Revision 1.7  2003/04/08 13:03:41  lawern
 * compareTo-Methode eingefügt
 *
 * Revision 1.6  2003/04/08 10:46:26  lawern
 * hashCode und equals berücksichtigen jetzt nicht mehr das weight
 *
 * Revision 1.5  2003/02/07 02:06:20  koppy
 * keywords + groups überarbeitet
 *
 * Revision 1.4  2002/12/12 02:39:07  koppy
 * Acl editing feature for categories added
 *
 * Revision 1.3  2002/11/25 10:59:58  jonyp
 * term/termdescription added
 *
 * Revision 1.2  2002/11/04 02:04:32  koppy
 * long --> Integer
 *
 * Revision 1.1  2002/10/21 14:35:39  bigmac
 * empty log message
 *
 * Revision 1.1  2002/09/13 11:42:32  koppy
 * Initiale version
 */
package vkc.db.entities;

/**
 * Klasse stellt ein Keyword im VKC-System dar
 *
 * @author koppy
 */
public final class VKCKeyword implements java.io.Serializable, Comparable {
    private String term = "";
    private String termDescriptor = "";
    private double weight;
    private boolean internal = true;

    /**
     * Konstruktor
     */
    public VKCKeyword() {
    }

    /**
     * Konstruktor
     *
     * @param term Name des Schlüsselbegriffs
     */
    public VKCKeyword(String term) {
        this.term = term;

        //TODO Synonymklasse noch berechnen
        this.termDescriptor = term;
        this.weight = 1;
        internal = false;
    }

    /**
     * Konstruktor
     *
     * @param term Name des Schlüsselbegriffs
     * @param termDescriptor Name des Descriptors für den term (Synonymklasse)
     * @param weight Gewicht des Schlüsselbegriffs
     */
    public VKCKeyword(String term, String termDescriptor, double weight,
        boolean internal) {
        this.term = term;
        this.termDescriptor = termDescriptor;
        this.weight = weight;
        this.internal = internal;
    }

    /**
     * Konstruktor
     *
     * @param term Name des Schlüsselbegriffs
     * @param termDescriptor Name des Descriptors für den term (Synonymklasse)
     */
    public VKCKeyword(String term, String termDescriptor) {
        this.term = term;
        this.termDescriptor = termDescriptor;
        this.weight = 1;
    }

    /**
     * Konstruktor
     *
     * @param term Name des Schlüsselbegriffs
     * @param termDescriptor Name des Descriptors für den term (Synonymklasse)
     * @param weight Gewicht des Schlüsselbegriffs
     */
    public VKCKeyword(String term, String termDescriptor, double weight,
        Integer internal) {
        this.term = term;
        this.termDescriptor = termDescriptor;
        this.weight = weight;

        if (internal.intValue() == 0) {
            this.internal = false;
        }
    }

    public void setTerm(String term) {
        this.term = (term == null) ? "" : term.trim();
    }

    public String getTerm() {
        return term;
    }

    public void setTermDescriptor(String termDescriptor) {
        this.termDescriptor = termDescriptor;
    }

    public String getTermDescriptor() {
        return this.termDescriptor;
    }

    public double getWeight() {
        return this.weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public boolean equals(Object o) {
        if (!(o instanceof VKCKeyword)) {
            return false;
        }

        String s = ((VKCKeyword) o).getTermDescriptor();

        if (s == null) {
            s = "";
        }

        return s.equals(this.termDescriptor);
    }

    public int hashCode() {
        return (this.termDescriptor == null) ? "".hashCode()
                                             : this.termDescriptor.hashCode();
    }

    public String toString() {
        return this.termDescriptor + "( " + this.term + "): " + weight + " /internal: " + this.getInternal();
    }

    public int compareTo(Object o) {
        double oWeight = ((VKCKeyword) o).getWeight();

        return ((oWeight < weight) ? (-1) : ((oWeight == weight) ? 0 : 1));
    }

    public int getInternal() {
        if (internal) {
            return 1;
        } 

        return 0;
    }

    public boolean isInternal() {
        return internal;
    }

    public void setInternal(boolean internal) {
        this.internal = internal;
    }

    public void setInternal(Integer internal) {
        if (internal.intValue() == 0) {
            this.internal = false;
        }
    }   
    
}
