12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import java.util.Arrays;
-
- public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {
-
- public IntegerDuplicateDeleter(Integer[] array) {
- super(array);
- }
-
- public Integer[] removeDuplicates(int maxNumberOfDuplications) {
-
- Integer[] answer = new Integer[array.length];
-
- int answerIndex = 0;
-
- for(int i = 0; i < array.length; i++){
- Integer occurances = getApperances(array[i]);
- if(occurances < maxNumberOfDuplications){
- answer[answerIndex] = array[i];
- answerIndex++;
- }
- }
-
- Integer[] realAnswer = Arrays.copyOf(answer, answerIndex);
-
-
- return realAnswer;
- }
-
- public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
- Integer[] answer = new Integer[array.length];
-
- int answerIndex = 0;
-
- for(int i = 0; i < array.length; i++){
- Integer occurances = getApperances(array[i]);
- if(occurances < exactNumberOfDuplications || occurances > exactNumberOfDuplications){
- answer[answerIndex] = array[i];
- answerIndex++;
- }
- }
- Integer[] realAnswer = Arrays.copyOf(answer, answerIndex);
- return realAnswer;
- }
-
- public int getApperances(Integer value){
- int appearances = 0;
- for(Integer element : array){
- if(element == value){
- appearances++;
- }
- }
- return appearances;
- }
- }
|