IntegerDuplicateDeleter.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
  2. public IntegerDuplicateDeleter(Integer[] array){
  3. super(array);
  4. }
  5. public Integer[] removeDuplicates(int maxNumberOfDuplications){
  6. Integer[] newArr = new Integer[0];
  7. int occur = 0;
  8. for(Integer i : array){
  9. occur=0;
  10. for(Integer j : array){
  11. if(i==j){
  12. occur++;
  13. }
  14. }
  15. if(occur < maxNumberOfDuplications){
  16. Integer[] temp = new Integer[newArr.length+1];
  17. for(int k = 0; k<newArr.length; k++){
  18. temp[k] = newArr[k];
  19. }
  20. temp[temp.length-1] = i;
  21. newArr = temp;
  22. }
  23. }
  24. Integer[] nullArr = new Integer[]{};
  25. if(newArr.length ==1 && newArr[0] == 0){
  26. return nullArr;
  27. }
  28. else{
  29. return newArr;
  30. }
  31. }
  32. public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications){
  33. Integer[] newArr = new Integer[0];
  34. int occur = 0;
  35. for(Integer i : array){
  36. occur = 0;
  37. for(Integer j : array){
  38. if(j == i){
  39. occur++;
  40. }
  41. }
  42. if(occur != exactNumberOfDuplications){
  43. Integer[] temp = new Integer[newArr.length +1];
  44. for(int k = 0; k<newArr.length; k++){
  45. temp[k] = newArr[k];
  46. }
  47. temp[temp.length-1] = i;
  48. newArr = temp;
  49. }
  50. }
  51. return newArr;
  52. }
  53. }