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
@@ -1,7 +1,78 @@
package com.zipcodewilmington.arrayutility;

import com.sun.deploy.util.ArrayUtil;
import com.sun.tools.javac.util.ArrayUtils;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
* Created by leon on 3/6/18.
*/
public class ArrayUtility {
public class ArrayUtility<SomeType> {
SomeType[] intArray;
public ArrayUtility(SomeType[] intArray){
this.intArray = intArray;
}
public Integer countDuplicatesInMerge(SomeType[] arrayToMerge, SomeType valueToEvaluate) {
Integer originalCounter = 0;
Integer mergeCounter = 0;
for(SomeType type : intArray){
if(type == valueToEvaluate)
originalCounter++;
}
for(SomeType type : arrayToMerge){
if(type == valueToEvaluate)
mergeCounter++;
}
Integer result = originalCounter + mergeCounter;

return result;
}

public SomeType getMostCommonFromMerge(SomeType[] arrayToMerge) {
Stream<SomeType> stream = Stream.concat(Arrays.stream(intArray), Arrays.stream(arrayToMerge));
SomeType[] work = (SomeType[]) stream.toArray();
SomeType element = null;
int counter = 0;
for (int i = 0; i < work.length; i++) {
SomeType currentType = work[i];
int currentTypeCount = 0;
for(int j = 0; j < work.length; j++){
if (work[j] == currentType){
currentTypeCount++;
}
if(currentTypeCount > counter){
element = currentType;
counter = currentTypeCount;
}
}

}
return element;
}

public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
int counter = 0;
for (int j = 0; j < intArray.length; j++) {
if(intArray[j] == valueToEvaluate){
counter++;
}

}
return counter;
}

public SomeType[] removeValue(SomeType valueToRemove) {
List<SomeType> list = new ArrayList<>();
for(SomeType type : intArray){
if(type != valueToRemove)
list.add(type);
}
SomeType[] result = list.toArray(Arrays.copyOf(intArray,list.size()));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.zipcodewilmington.arrayutility;

import com.zipcodewilmington.UnitTestingUtils;
import org.junit.Test;

/**
Expand Down