The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Sets/Maps help needed

You guys were more than helpful during my last assignment so I figured I would give you guys another try. After all, I have learned more from everyone here than my professor whom I am paying over a thousand dollars this semester to teach me this stuff. /rant

I mainly need help with setting up the map and set. We didn't really cover these data types much before he gave us the assignment, sent us on Spring Break, and told us it would be due the first day back. I have done numerous Google searches to find some basic information on setting these us, but have not had any success. We will be using an AVL tree in coordination with a text file.

Our instructions are to "read a text file and extract all of the identifiers in the file, along with the line numbers on which the identifier appear. An identifier is defined as a string that begins with a letter (A-Z, a-z) and is followed by zero or more other characters that are a letter or a digit (0-9). Note that, if an identifier appears multiple times in a line, only one line number is recorded."

The input is a text file, for example a source code or a text document. The concordance outputs the information for each identifier in the following format:

Here n_1 is the number of lines containing the identifier_1 and L_i(i >= 1) is the list of line numbers on which it appears.

The provided avlTree.java class:
(I also have my regular driver class which really doesn't have much in it because I am stuck trying to figure out how to read the inputs into a set. I also have an AVLMap and AVLSet class which are blank.)

This is my treemap and treeset class. i have another pair of classes called hashmap and hashset but will not include them as they are pretty similar. I pulled most of this information from the Java API and just need to know how to use sets/maps in order to fill out the methods.

The second step has me running three different variants of the previously listed program. Each variant will use a different type of tree/map. The variants are AVL Map/Set, Tree Map/Set, and Hash Map/Set.

importjava.util.AbstractMap;//a red-black tree based navigablemap implementation. *the map is sorted according to the natural ordering of its keys//...or by a comparator provided at map creation time, depending on which constructor is usedpublicclass TreeMap<K,V>extends AbstractMap<K,V>{//constructs a new, empty tree map, using the natural ordering of its keys. *all keys inserted into the map must implement//...the Comparable interface.publicTreeMap(){}//returns the number of key-value mappings in this mappublicint size(){}//returns true if this map contains a mapping for the specified keypublicboolean containsKey(Object key){}//returns true if this map maps one or more keys to the specified value. *more formally, returns true if and only if this map//...contains at least one mapping to a value v such that (value == null ? v == null : value.equals(v)).publicboolean containsValue(Object value){}//returns the value to which the specified key is mapped, or null if this map contains no mapping for the keypublic V get(Object key){}//removes the mapping for this key from this TreeMap if presentpublic V remove(Object key){}//removes all of the mappings from this map. *the map will be empty after this call returnspublicvoid clear(){}}

importjava.util.AbstractSet;importjava.util.Iterator;//stores elements in a red-black tree, orders its elements based on their values; substantially slower than HashSetpublicclass TreeSet<E>extends AbstractSet<E>{//constructs a new, empty tree set, sorted according to the natural ordering of its elementspublicTreeSet(){}//returns an iterator over the elements in this set in ascending orderpublic Iterator<E> iterator(){}//returns the number of elements in this setpublicint size(){}//returns true if this set contains no elementspublicboolean isEmpty(){}//returns true if this set contains the specified elementpublicboolean contains(Object o){}//adds the specified element to this set if it is not already presentpublicboolean add(E e){}//removes the specified element from this set if it is presentpublicboolean remove(Object o){}//removes all of the elements from this set. this set will be empty after this call returnspublicvoid clear(){}}

Re: Sets/Maps help needed

Originally Posted by Norm

Can you explain what objects are to go in the set and how the data from the file is used to create those objects?

he said it could be any reasonably sized document with numbers, punctuation, as well as words. it will not count word occurances that happen more than once on a line
Ex:
Apple Cooperation Monitor Apple
blah blah Apple

Re: Sets/Maps help needed

Originally Posted by Norm

Why are you using a Set vs a Map? It looks like a Map would be more useful: key= token, value= list of line numbers

Im sorry, when I added the new classes, I forgot to add the second step of the instructions. The second step has me running three different variants of the previously listed program. Each variant will use a different type of tree/map. The variants are AVL Map/Set, Tree Map/Set, and Hash Map/Set. Updated the original post.