-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathStringDuplicateDeleter.java
More file actions
35 lines (29 loc) · 1.15 KB
/
StringDuplicateDeleter.java
File metadata and controls
35 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.zipcodewilmington.looplabs;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* Created by leon on 1/28/18.
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
public StringDuplicateDeleter(String[] stringArray) {
super(stringArray);
}
public long getNumberOfOccurrances(String element) {
return (Arrays.stream(array)
.filter(word -> word.equals(element))
.count());
}
public String[] removeDuplicates(int maxNumberOfDuplications) {
return Arrays.stream(array)
.filter(element -> getNumberOfOccurrances(element) < maxNumberOfDuplications)
.collect(Collectors.toList())
.toArray(new String[0]);
}
public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
return Arrays.stream(array)
.filter(element -> getNumberOfOccurrances(element) != exactNumberOfDuplications)
.collect(Collectors.toList())
.toArray(new String[0]);
}
}