12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
-
- public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
- public IntegerDuplicateDeleter(Integer[] array){
- super(array);
- }
-
- public int numberOfOccurences(Integer occurence){
- int counter = 0;
-
- for(int i = 0; i < array.length; i++){
- if(array[i].equals(occurence)){
- counter++;
- }
- }
- return counter;
- }
-
- public Integer[] removeDuplicates(int maxNumberOfDuplications){
- Integer[] occurenceArray = new Integer[100];
-
- int nums = 0;
- for(int i = 0; i < array.length; i++)
- {
- int occurences = numberOfOccurences(array[i]);
-
- if(occurences < maxNumberOfDuplications)
- {
- occurenceArray[nums] = array[i];
-
- nums++;
-
- }
- }
-
- Integer[] result = new Integer[nums];
- for(int i = 0; i < nums; i++)
- {
- result[i] = occurenceArray[i];
- }
- return result;
- }
-
- public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications){
- Integer[] newArray=new Integer[100];
-
- int nums = 0;
- for(int i = 0; i < array.length; i++)
- {
- int occurences = numberOfOccurences(array[i]);
- if(occurences != exactNumberOfDuplications)
- {
- newArray[nums]=array[i];
-
- nums++;
-
- }
- }
-
- Integer[] result = new Integer[nums];
- for(int i = 0; i < nums; i++)
- {
- result[i]=newArray[i];
- }
- return result;
- }
- }
|