diff --git a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java index ee550c5..7650db3 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java @@ -1,8 +1,29 @@ package com.zipcodewilmington.looplabs; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.Collectors; + /** * 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 { + public IntegerDuplicateDeleter(Integer[] intArray) { + super(intArray); + } + + @Override + public Integer[] removeDuplicates(int maxNumberOfDuplications) { + return Arrays.stream(array) + .filter(j -> Collections.frequency(Arrays.asList(array), j) < maxNumberOfDuplications) + .toArray(Integer[]::new); + } + + @Override + public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { + return Arrays.stream(array) + .filter(j -> Collections.frequency(Arrays.asList(array), j) != exactNumberOfDuplications) + .toArray(Integer[]::new); + } } diff --git a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java index 4818fe3..eeb1d6e 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java @@ -1,8 +1,30 @@ package com.zipcodewilmington.looplabs; +import java.util.Arrays; +import java.util.Collections; + /** * 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 { + public StringDuplicateDeleter(String[] intArray) { + super(intArray); + } + + @Override + public String[] removeDuplicates(int maxNumberOfDuplications) { + + return Arrays.stream(array) + .filter(j -> Collections.frequency(Arrays.asList(array), j) < maxNumberOfDuplications) + .toArray(String[]::new); + } + + @Override + public String[] removeDuplicatesExactly(int exactNumberOfDuplications) { + + return Arrays.stream(array) + .filter(j -> Collections.frequency(Arrays.asList(array), j) != exactNumberOfDuplications) + .toArray(String[]::new); + } }