Results 1 to 6 of 6
Thread: TreeMap vs Map
- 03-26-2011, 09:20 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 57
- Rep Power
- 0
TreeMap vs Map
So I have a TreeMap class that is working fine in that class I have a add method:
Now I have to use this same method in a regular Map class:Java Code:public class DefaultIndexImpl extends TreeMap<String, List<Integer>> implements Index { @Override public void add(final String word, final int line) { if(containsKey(word)){ get(word).add(line); } else{ List<Integer> list = new LinkedList<Integer>(); list.add(line); put(word,list); } } }
The issue I am having is that Eclipse is telling me that I need to add a get and put method but in my original TreeMap class I did not have to do this. For regular Map class do I have to instantiate get() and put() or should this function be in that type?Java Code:public class DefaultIndexImpl implements Index { @Override public void add(final String word, final int line) { // TODO your job if(contains(word)){ get(word).add(line); } else{ List<Integer> list = new LinkedList<Integer>(); list.add(line); put(word,list); } } }
-
If you're talking about the core Map, it is not a class but an interface and would require that you implement ALL of its declared methods,... many more than just put and get. But a question for you, what is the Index interface? Does it require that you have get and put methods?
- 03-26-2011, 10:17 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 57
- Rep Power
- 0
Here is my Index class:
package occurences;
import java.util.List;
import java.util.Map;
public interface Index extends Iterable<Map.Entry<String, List<Integer>>> {
void add(String word, int line);
boolean contains(String word);
int frequency(String word);
List<Integer> lines(String word);
void clear();
int size();
}
So would I add put() and get() in this class?
-
- 03-27-2011, 06:03 PM #5
Member
- Join Date
- Mar 2009
- Posts
- 57
- Rep Power
- 0
so would i add the put and get to the interface class or the DefaultIndexImpl
-
Similar Threads
-
[JAVA] TreeMap
By watle in forum Advanced JavaReplies: 3Last Post: 03-16-2011, 05:39 PM -
Treemap question
By dave120 in forum New To JavaReplies: 0Last Post: 10-13-2009, 02:31 AM -
TreeMap class and message not understood issues - help please
By trueblue in forum New To JavaReplies: 8Last Post: 07-22-2009, 01:16 AM -
Sorting Elements in a TreeMap
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:47 PM -
How to use treemap
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks