123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
-
-
-
- public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
-
- public IntegerDuplicateDeleter(Integer[] array) {
- super(array);
- }
-
- public Integer[] removeDuplicates(int maxNumberOfDuplications) {
- StringBuilder sb = new StringBuilder();
-
-
-
- for (int i = 0; i < array.length; i++) {
-
- if(getCount(array[i]) < maxNumberOfDuplications){
-
- sb.append((array[i]) + " ");
- }
- }
- String arrString = sb.toString();
- String [] arrPlus = arrString.split(" ");
- Integer[] newArr = new Integer[arrPlus.length];
-
- for (int i = 0; i < newArr.length; i++) {
- try {newArr[i] = Integer.parseInt(arrPlus[i]);}
- catch (NumberFormatException e){}
- }
-
- Integer[] empty = new Integer[]{};
-
- if (newArr.length == 1 && newArr[0] == null) {
- return empty;
- } else { return newArr;}
-
-
- }
-
- public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
- StringBuilder sb = new StringBuilder();
-
- String tester = array.toString();
-
- for (int i = 0; i < array.length; i++) {
-
- if(getCount(array[i]) < exactNumberOfDuplications || getCount(array[i])
- > exactNumberOfDuplications) {
-
- sb.append((array[i]) + " ");
- }
- }
- String arrString = sb.toString();
- String [] arrPlus = arrString.split(" ");
- Integer[] newArr = new Integer[arrPlus.length];
-
- for (int i = 0; i < newArr.length; i++) {
- try {newArr[i] = Integer.parseInt(arrPlus[i]);}
- catch (NumberFormatException e){}
- }
-
- Integer[] empty = new Integer[]{};
-
- if (newArr.length == 1 && newArr[0] == null) {
- return empty;
- } else { return newArr;}
-
-
- }
-
-
- private int getCount (Integer value){
- int count = 0;
-
-
- for (Integer e : array){
-
- if (e == value) {
-
- count++;
-
- }
- }
- return count;
- }
- }
|