Skip to content

Instantly share code, notes, and snippets.

@jeorfevre
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeorfevre/946ede55ad93cc811cf8 to your computer and use it in GitHub Desktop.
Save jeorfevre/946ede55ad93cc811cf8 to your computer and use it in GitHub Desktop.
ref: 30246966
uri: http://stackoverflow.com/questions/30246966
je@rizze.com
/**
*
* @author Jean-Emmanuel je@Rizze.com
*
*/
public class WordsIndex{
HashMap<String, Word> words = new HashMap<String, Word>();
public static void put(String word, int line, int paragraph){
word=word.toLowerCase();
if(words.containsKey(word)){
Word w=words.get(word);
w.count++;
}else{
//new word
Word w = new Word();
w.count=1;
w.line=line;
w.paragraph=paragraph;
w.word=word;
words.put(word, w);
}
//return this;
}
}
public class Word{
String word;
int count;
int line;
int paragraph;
}
//how to use it ?
add a word : WordsIndex.put(.....)
get word : WordIndex.words.get(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment