Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
public abstract class DuplicateDeleter<T> implements DuplicateDeleterInterface<T> {
protected final T[] array;


public DuplicateDeleter(T[] intArray) {
this.array = intArray;
}

abstract public T[] removeDuplicates(int maxNumberOfDuplications);
{

}
abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,77 @@
package com.zipcodewilmington.looplabs;

import java.util.Arrays;

/**
* Created by leon on 1/29/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {
}

public IntegerDuplicateDeleter(Integer[] intArray) {
super(intArray);
}

Integer[] myCopyOfArray = Arrays.copyOf(this.array, this.array.length);

/**
*
* @param maxNumberOfDuplications
* @return returns an array with integers occuring less than the maxNumberOfDuplications
*/
@Override
public Integer[] removeDuplicates(int maxNumberOfDuplications) {
Integer[] outPut = new Integer[0];
int outPutIndex = 0;
for (int s : myCopyOfArray) {

if (getNumberOfOccurrences(myCopyOfArray, s) < maxNumberOfDuplications) {
outPut = Arrays.copyOf(outPut, outPut.length + 1);
outPut[outPutIndex] = s;
outPutIndex++;
}
}
return outPut;
}

/**
*
* @param exactNumberOfDuplications
* @return returns an array of Integers not the exactNumberOfDuplications
*/

@Override
public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {
Integer[] outPut = new Integer[0];
int outPutIndex = 0;
for (int s : myCopyOfArray) {

if (getNumberOfOccurrences(myCopyOfArray, s) != exactNumberOfDuplications) {
outPut = Arrays.copyOf(outPut, outPut.length + 1);
outPut[outPutIndex] = s;
outPutIndex++;
}
}

return outPut;
}

/**
*
* @param array an array of Integers
* @param value the value to which the number of occurence in the array is to be determined
* @return the number of times a value occurs in the array
*/
public static int getNumberOfOccurrences(Integer[] array, Integer value) {

int counter = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] == value) {
counter++;
}
}
return counter;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
package com.zipcodewilmington.looplabs;

import java.util.Arrays;

/**
* Created by leon on 1/28/18.
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class StringDuplicateDeleter extends DuplicateDeleter<String> {

public StringDuplicateDeleter(String[] stringArray) {
super(stringArray);
}
String[] myCopyOfArray = Arrays.copyOf(this.array,this.array.length);

/**
*
* @param maxNumberOfDuplications
* @return
*/
@Override
public String[] removeDuplicates(int maxNumberOfDuplications) {
String[] outPut = new String[0];
int outPutIndex = 0;
for (String s : myCopyOfArray) {

if(getNumberOfOccurrences(myCopyOfArray, s)< maxNumberOfDuplications) {
outPut = Arrays.copyOf(outPut, outPut.length+1);
outPut[outPutIndex] = s;
outPutIndex++;
}
}

return outPut;
}
@Override
public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {
String[] outPut = new String[0];
int outPutIndex = 0;
for (String s : myCopyOfArray) {
if (getNumberOfOccurrences(myCopyOfArray, s) != exactNumberOfDuplications) {
outPut = Arrays.copyOf(outPut, outPut.length+1);
outPut[outPutIndex] = s;
outPutIndex++;
}

}
return outPut;
}

public static int getNumberOfOccurrences(String[] array, String value) {

int counter = 0;
for(int i=0;i<array.length;i++){
if(array[i].equalsIgnoreCase(value)){
counter++;
}
}
return counter;
}

}