123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
-
-
-
- public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
-
- public IntegerDuplicateDeleter(Integer[] array){
- super(array);
- }
-
- public Integer[] removeDuplicates(int maxNumberOfDuplications){
- Integer[] newArray =new Integer[array.length];
- int newArrayIndex= 0;
- //go through each element in the array
- for(Integer num : array) {
- int occurance = countOccurance(num);
- if(occurance < maxNumberOfDuplications) {
- newArray[newArrayIndex] = num;
- newArrayIndex++;
- }
- }
- //count occurrance
- Integer[] finalArray = new Integer[newArrayIndex];
- System.arraycopy(newArray, 0, finalArray, 0, newArrayIndex);
- return finalArray;
- }
-
-
-
-
- public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications){
- Integer[] newArray =new Integer[array.length];
- int newArrayIndex= 0;
- //go through each element in the array
- for(Integer num : array) {
- int occurance = countOccurance(num);
- if(occurance != exactNumberOfDuplications) {
- newArray[newArrayIndex] = num;
- newArrayIndex++;
- }
- }
- //count occurrance
- Integer[] finalArray = new Integer[newArrayIndex];
- System.arraycopy(newArray, 0, finalArray, 0, newArrayIndex);
- return finalArray;
- }
-
- private int countOccurance(Integer number){
- int count =0;
- for(Integer i : array) {
- if(number == i) {
- count++;
- }
-
- //
- //when number ==}
-
- }
- return count;
- }
-
-
- }
-
-
-
|