Skip to content

Commit

Permalink
Create PersonalMultipleEntryDictionary.java
Browse files Browse the repository at this point in the history
  • Loading branch information
giusepped committed Aug 24, 2014
1 parent 2f32155 commit 1875572
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Week9/MultipleEntryDictionary/PersonalMultipleEntryDictionary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

package dictionary;

/**
*
* @author giuseppedesantis
*/

import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;

public class PersonalMultipleEntryDictionary implements MultipleEntryDictionary{
private Map<String, Set<String>> dict;

public PersonalMultipleEntryDictionary(){
this.dict = new HashMap<String, Set<String>>();
}

@Override
public void add(String word, String entry){
if(!this.dict.containsKey(word)){
this.dict.put(word, new HashSet<String>());
}

Set<String> translations = this.dict.get(word);
translations.add(entry);
}

@Override
public Set<String> translate(String word){
Set<String> translations = this.dict.get(word);
return translations;
}

@Override
public void remove(String word){
this.dict.remove(word);
}
}

0 comments on commit 1875572

Please sign in to comment.