1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
-
-
-
- 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;
-
- for (Integer num : array) {
- int occurence = countOccurance(num);
- if (occurence < maxNumberOfDuplications) {
- newArray[newArrayIndex] = num;
- newArrayIndex++;
- }
- }
-
- 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;
-
- for (Integer num : array) {
- int occurence = countOccurance(num);
- if (occurence != exactNumberOfDuplications) {
- newArray[newArrayIndex] = num;
- newArrayIndex++;
- }
- }
-
- 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 = count + 1;
- }
- }
- return count;
- }
- }
|