-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create PersonalDuplicateRemover.java
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
Week9/DuplicateRemover/tools/PersonalDuplicateRemover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
package tools; | ||
|
||
/** | ||
* | ||
* @author giuseppedesantis | ||
*/ | ||
|
||
import java.util.Set; | ||
import java.util.HashSet; | ||
|
||
public class PersonalDuplicateRemover implements DuplicateRemover{ | ||
private Set<String> entries; | ||
private int numberOfDuplicates; | ||
|
||
public PersonalDuplicateRemover(){ | ||
this.numberOfDuplicates = 0; | ||
this.entries = new HashSet<String>(); | ||
} | ||
|
||
@Override | ||
public void add(String characterString){ | ||
if(!entries.contains(characterString)){ | ||
entries.add(characterString); | ||
}else{ | ||
numberOfDuplicates++; | ||
} | ||
} | ||
|
||
@Override | ||
public int getNumberOfDetectedDuplicates(){ | ||
return numberOfDuplicates; | ||
} | ||
|
||
@Override | ||
public Set<String> getUniqueCharacterStrings(){ | ||
return entries; | ||
} | ||
|
||
@Override | ||
public void empty(){ | ||
entries.clear(); | ||
numberOfDuplicates = 0; | ||
} | ||
} |