View Javadoc

1   /*
2    * $Id: DefaultSuggestionCandidate.java,v 1.6 2005/05/31 19:37:20 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8   
9   package com.bbn.swede.editor.contentassist;
10  
11  /***
12   * Default implementation of the ISuggestionCandidate interface. This class also
13   * implements Comparable, and the ordering imposed upon collections of this
14   * class is the same as the <code>name</code> value stored by this objects  
15   * of this class.
16   * 
17   * @author aperezlo
18   */
19  public class DefaultSuggestionCandidate implements ISuggestionCandidate
20  {
21     /***
22      * The type of the autocomplete suggestion.  See {@link ISuggestionCandidate}
23      * for suggestion type constants.
24      */
25     protected int _type;
26  
27     /***
28      * The name of this suggestion candidate.
29      */
30     protected String _name = "";
31  
32     /***
33      * Default constructor.
34      */
35     public DefaultSuggestionCandidate()
36     {
37     }
38  
39     /*
40      * @return true if <code>o</code> is a DefaultSuggestionCandidate with the
41      *         same name and type, false otherwise
42      * 
43      * @see java.lang.Object#equals(java.lang.Object)
44      */
45     public boolean equals(Object o)
46     {
47        boolean toReturn = false;
48        DefaultSuggestionCandidate other = null;
49        if(o instanceof DefaultSuggestionCandidate)
50        {
51           other = (DefaultSuggestionCandidate)o;
52           if(other.getName().equals(_name))
53           {
54              if(other._type == _type)
55              {
56                 toReturn = true;
57              }
58           }
59        }
60  
61        return toReturn;
62     }
63  
64     /***
65      * As per the interface.
66      * 
67      * @see java.lang.Comparable#compareTo(java.lang.Object)
68      */
69     public int compareTo(Object arg0)
70     {
71        int toReturn = 1;
72        if(arg0 != null)
73        {
74           if(arg0 instanceof ISuggestionCandidate)
75           {
76              toReturn = _name.compareTo(((ISuggestionCandidate)arg0).getName());
77           }
78        }
79        else
80        {
81           throw new NullPointerException();
82        }
83  
84        return toReturn;
85     }
86  
87     /***
88      * Creates a suggestion candidate with a specific name and type.
89      * @param name The name of the new candidate
90      * @param type The type of the new candidate.  One of the values in the
91      *             ISuggestionCandidate interface.
92      */
93     public DefaultSuggestionCandidate(String name, int type)
94     {
95        _name = name;
96        _type = type;
97     }
98  
99     /*
100     * @return the _name member variable.
101     * @see java.lang.Object#toString()
102     */
103    public String toString()
104    {
105       return _name;
106    }
107 
108    /***
109     * Retrieves the name of the suggestion candidate.
110     * @return The suggestion candidate's name.
111     */
112    public String getName()
113    {
114       return _name;
115    }
116 
117    /***
118     * Sets the name of the suggestion candidate.
119     * @param sName The name to set.
120     */
121    public void setName(String sName)
122    {
123       this._name = sName;
124    }
125 
126    /***
127     * Retrieves the suggestion candidate's type.
128     * @return Returns the type of this suggestion candidate.
129     */
130    public int getType()
131    {
132       return _type;
133    }
134 
135    /***
136     * Sets the type of the suggestion candidate.
137     * @param sType The type to set.
138     */
139    public void setType(int sType)
140    {
141       this._type = sType;
142    }
143 }