123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
-
- public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
- public IntegerDuplicateDeleter(Integer[] array){
- super(array);
-
- }
-
- public Integer[] removeDuplicates(int maxNumberOfDuplications){
- Integer[] newArr = new Integer[0];
- int occur = 0;
- for(Integer i : array){
- occur=0;
- for(Integer j : array){
- if(i==j){
- occur++;
- }
- }
- if(occur < maxNumberOfDuplications){
- Integer[] temp = new Integer[newArr.length+1];
- for(int k = 0; k<newArr.length; k++){
- temp[k] = newArr[k];
- }
- temp[temp.length-1] = i;
- newArr = temp;
- }
- }
- Integer[] nullArr = new Integer[]{};
- if(newArr.length ==1 && newArr[0] == 0){
- return nullArr;
- }
- else{
- return newArr;
- }
-
- }
-
- public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications){
- Integer[] newArr = new Integer[0];
- int occur = 0;
- for(Integer i : array){
-
- occur = 0;
- for(Integer j : array){
- if(j == i){
- occur++;
- }
-
- }
- if(occur != exactNumberOfDuplications){
- Integer[] temp = new Integer[newArr.length +1];
- for(int k = 0; k<newArr.length; k++){
- temp[k] = newArr[k];
- }
- temp[temp.length-1] = i;
- newArr = temp;
- }
-
- }
-
- return newArr;
- }
-
- }
|