From 4b1bf80095052a288c287d0fe25db1768e5a5834 Mon Sep 17 00:00:00 2001 From: kshields412 Date: Sat, 16 Nov 2019 11:34:06 -0500 Subject: [PATCH] completed lab --- .../looplabs/IntegerDuplicateDeleter.java | 20 +++++++++++++++++++ .../looplabs/StringDuplicateDeleter.java | 18 +++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java index ee550c5..6ca8dfd 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java @@ -1,8 +1,28 @@ 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 { + + public IntegerDuplicateDeleter(Integer[] intArray) { + super(intArray); + } + + @Override + public Integer[] removeDuplicates(int maxNumberOfDuplications) { + return Arrays.stream(array).filter(y -> getOccurance(y) < maxNumberOfDuplications).toArray(Integer[] :: new); + } + + @Override + public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) { + return Arrays.stream(array).filter(t -> getOccurance(t) != exactNumberOfDuplications).toArray(Integer[] :: new); + } + + public Long getOccurance (Integer x){ + return Arrays.stream(array).filter(z -> z.equals(x)).count(); + } } diff --git a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java index 4818fe3..cce843f 100644 --- a/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java +++ b/src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java @@ -1,8 +1,26 @@ 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 { + public StringDuplicateDeleter(String[] intArray) { + super(intArray); + } + + @Override + public String[] removeDuplicates(int maxNumberOfDuplications) { + return Arrays.stream(array).filter(y -> getOccurance(y) < maxNumberOfDuplications).toArray(String[] :: new); + } + + @Override + public String[] removeDuplicatesExactly(int exactNumberOfDuplications) { + return Arrays.stream(array).filter(t -> getOccurance(t) != exactNumberOfDuplications).toArray(String[] :: new); + } + public Long getOccurance (String x){ + return Arrays.stream(array).filter(z -> z.equals(x)).count(); + } }