12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Created by leon on 1/25/18.
  3. */
  4. public abstract class DuplicateDeleter<T> {
  5. protected T[] array;
  6. public DuplicateDeleter(T[] array) {
  7. this.array = array;
  8. }
  9. /**
  10. * Removes all values in the array which occur n or more times
  11. *
  12. * DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter();
  13. * Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
  14. * deleter.removeDuplicateExactly(array, 2); // => {56, 57, 58}
  15. *
  16. * @param maxNumberOfDuplications
  17. * @return
  18. */
  19. abstract public T[] removeDuplicates(int maxNumberOfDuplications);
  20. /**
  21. * Removes all the values in the array which occurs exactly n times
  22. *
  23. * DuplicateDeleter<Integer> = new IntegerDuplicateDeleter();
  24. * Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
  25. * deleter.removeDuplicateExactly(array, 2); // => {1, 1, 1, 56, 57, 58}
  26. *
  27. * @param exactNumberOfDuplications
  28. * @return
  29. */
  30. abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications);
  31. }