Removed dead code

This commit is contained in:
David Noble
2019-09-15 21:27:44 -07:00
parent 67ccef3dca
commit 956e44989a
4 changed files with 0 additions and 502 deletions

View File

@@ -1,9 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package tangible;
@FunctionalInterface
public interface Action0Param {
void invoke();
}

View File

@@ -1,9 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package tangible;
@FunctionalInterface
public interface Func1Param<T, TResult> {
TResult invoke(T t);
}

View File

@@ -1,134 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package tangible;
import java.util.ArrayList;
import java.util.function.Predicate;
public final class ListHelper {
public static <T> boolean exists(ArrayList<T> source, Predicate<T> predicate) {
for (T element : source) {
if (predicate.test(element)) {
return true;
}
}
return false;
}
public static <T> T find(ArrayList<T> source, Predicate<T> predicate) {
for (T element : source) {
if (predicate.test(element)) {
return element;
}
}
return null;
}
public static <T> ArrayList<T> findAll(ArrayList<T> source, Predicate<T> predicate) {
ArrayList<T> dest = new ArrayList<T>();
for (T element : source) {
if (predicate.test(element)) {
dest.add(element);
}
}
return dest;
}
public static <T> int findIndex(ArrayList<T> source, Predicate<T> predicate) {
for (int i = 0; i < source.size(); i++) {
if (predicate.test(source.get(i))) {
return i;
}
}
return -1;
}
public static <T> int findIndex(ArrayList<T> source, int start, Predicate<T> predicate) {
for (int i = start; i < source.size(); i++) {
if (predicate.test(source.get(i))) {
return i;
}
}
return -1;
}
public static <T> int findIndex(ArrayList<T> source, int start, int count, Predicate<T> predicate) {
for (int i = start; i < start + count; i++) {
if (predicate.test(source.get(i))) {
return i;
}
}
return -1;
}
public static <T> T findLast(ArrayList<T> source, Predicate<T> predicate) {
for (int i = source.size() - 1; i > -1; i--) {
if (predicate.test(source.get(i))) {
return source.get(i);
}
}
return null;
}
public static <T> int findLastIndex(ArrayList<T> source, Predicate<T> predicate) {
for (int i = source.size() - 1; i > -1; i--) {
if (predicate.test(source.get(i))) {
return i;
}
}
return -1;
}
public static <T> int findLastIndex(ArrayList<T> source, int start, Predicate<T> predicate) {
for (int i = start; i > -1; i--) {
if (predicate.test(source.get(i))) {
return i;
}
}
return -1;
}
public static <T> int findLastIndex(ArrayList<T> source, int start, int count, Predicate<T> predicate) {
for (int i = start; i > start - count; i--) {
if (predicate.test(source.get(i))) {
return i;
}
}
return -1;
}
public static <T> int removeAll(ArrayList<T> source, Predicate<T> predicate) {
int removed = 0;
for (int i = 0; i < source.size(); i++) {
if (predicate.test(source.get(i))) {
source.remove(i);
i--;
removed++;
}
}
return removed;
}
public static <T> boolean trueForAll(ArrayList<T> source, Predicate<T> predicate) {
for (T element : source) {
if (!predicate.test(element)) {
return false;
}
}
return true;
}
}

View File

@@ -1,350 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package tangible;
public final class StringHelper {
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'IndexOfAny' (1 parameter version).
//------------------------------------------------------------------------------------
public static int indexOfAny(String string, char[] anyOf) {
int lowestIndex = -1;
for (char c : anyOf) {
int index = string.indexOf(c);
if (index > -1) {
if (lowestIndex == -1 || index < lowestIndex) {
lowestIndex = index;
if (index == 0) {
break;
}
}
}
}
return lowestIndex;
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'IndexOfAny' (2 parameter version).
//------------------------------------------------------------------------------------
public static int indexOfAny(String string, char[] anyOf, int startIndex) {
int indexInSubstring = indexOfAny(string.substring(startIndex), anyOf);
if (indexInSubstring == -1) {
return -1;
} else {
return indexInSubstring + startIndex;
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'IndexOfAny' (3 parameter version).
//------------------------------------------------------------------------------------
public static int indexOfAny(String string, char[] anyOf, int startIndex, int count) {
int endIndex = startIndex + count;
int indexInSubstring = indexOfAny(string.substring(startIndex, endIndex), anyOf);
if (indexInSubstring == -1) {
return -1;
} else {
return indexInSubstring + startIndex;
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET static string method 'IsNullOrEmpty'.
//------------------------------------------------------------------------------------
public static boolean isNullOrEmpty(String string) {
return string == null || string.length() == 0;
}
//------------------------------------------------------------------------------------
// This method replaces the .NET static string method 'IsNullOrWhiteSpace'.
//------------------------------------------------------------------------------------
public static boolean isNullOrWhiteSpace(String string) {
if (string == null) {
return true;
}
for (int index = 0; index < string.length(); index++) {
if (!Character.isWhitespace(string.charAt(index))) {
return false;
}
}
return true;
}
//------------------------------------------------------------------------------------
// This method replaces the .NET static string method 'Join' (2 parameter version).
//------------------------------------------------------------------------------------
public static String join(String separator, String[] stringArray) {
if (stringArray == null) {
return null;
} else {
return join(separator, stringArray, 0, stringArray.length);
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET static string method 'Join' (4 parameter version).
//------------------------------------------------------------------------------------
public static String join(String separator, String[] stringArray, int startIndex, int count) {
String result = "";
if (stringArray == null) {
return null;
}
for (int index = startIndex; index < stringArray.length && index - startIndex < count; index++) {
if (separator != null && index > startIndex) {
result += separator;
}
if (stringArray[index] != null) {
result += stringArray[index];
}
}
return result;
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'LastIndexOf' (char version).
//------------------------------------------------------------------------------------
public static int lastIndexOf(String string, char value, int startIndex, int count) {
int leftMost = startIndex + 1 - count;
int rightMost = startIndex + 1;
String substring = string.substring(leftMost, rightMost);
int lastIndexInSubstring = substring.lastIndexOf(value);
if (lastIndexInSubstring < 0) {
return -1;
} else {
return lastIndexInSubstring + leftMost;
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'LastIndexOf' (string version).
//------------------------------------------------------------------------------------
public static int lastIndexOf(String string, String value, int startIndex, int count) {
int leftMost = startIndex + 1 - count;
int rightMost = startIndex + 1;
String substring = string.substring(leftMost, rightMost);
int lastIndexInSubstring = substring.lastIndexOf(value);
if (lastIndexInSubstring < 0) {
return -1;
} else {
return lastIndexInSubstring + leftMost;
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'LastIndexOfAny' (1 parameter version).
//------------------------------------------------------------------------------------
public static int lastIndexOfAny(String string, char[] anyOf) {
int highestIndex = -1;
for (char c : anyOf) {
int index = string.lastIndexOf(c);
if (index > highestIndex) {
highestIndex = index;
if (index == string.length() - 1) {
break;
}
}
}
return highestIndex;
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'LastIndexOfAny' (2 parameter version).
//------------------------------------------------------------------------------------
public static int lastIndexOfAny(String string, char[] anyOf, int startIndex) {
String substring = string.substring(0, startIndex + 1);
int lastIndexInSubstring = lastIndexOfAny(substring, anyOf);
if (lastIndexInSubstring < 0) {
return -1;
} else {
return lastIndexInSubstring;
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'LastIndexOfAny' (3 parameter version).
//------------------------------------------------------------------------------------
public static int lastIndexOfAny(String string, char[] anyOf, int startIndex, int count) {
int leftMost = startIndex + 1 - count;
int rightMost = startIndex + 1;
String substring = string.substring(leftMost, rightMost);
int lastIndexInSubstring = lastIndexOfAny(substring, anyOf);
if (lastIndexInSubstring < 0) {
return -1;
} else {
return lastIndexInSubstring + leftMost;
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'PadLeft' (1 parameter version).
//------------------------------------------------------------------------------------
public static String padLeft(String string, int totalWidth) {
return padLeft(string, totalWidth, ' ');
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'PadLeft' (2 parameter version).
//------------------------------------------------------------------------------------
public static String padLeft(String string, int totalWidth, char paddingChar) {
StringBuilder sb = new StringBuilder();
while (sb.length() + string.length() < totalWidth) {
sb.append(paddingChar);
}
sb.append(string);
return sb.toString();
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'PadRight' (1 parameter version).
//------------------------------------------------------------------------------------
public static String padRight(String string, int totalWidth) {
return padRight(string, totalWidth, ' ');
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'PadRight' (2 parameter version).
//------------------------------------------------------------------------------------
public static String padRight(String string, int totalWidth, char paddingChar) {
StringBuilder sb = new StringBuilder(string);
while (sb.length() < totalWidth) {
sb.append(paddingChar);
}
return sb.toString();
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'Remove' (1 parameter version).
//------------------------------------------------------------------------------------
public static String remove(String string, int start) {
return string.substring(0, start);
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'Remove' (2 parameter version).
//------------------------------------------------------------------------------------
public static String remove(String string, int start, int count) {
return string.substring(0, start) + string.substring(start + count);
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string constructor which repeats a character.
//------------------------------------------------------------------------------------
public static String repeatChar(char charToRepeat, int count) {
String newString = "";
for (int i = 1; i <= count; i++) {
newString += charToRepeat;
}
return newString;
}
//------------------------------------------------------------------------------------
// This method is used for string equality comparisons when the option
// 'Use helper 'stringsEqual' method to handle null strings' is selected
// (The Java String 'equals' method can't be called on a null instance).
//------------------------------------------------------------------------------------
public static boolean stringsEqual(String s1, String s2) {
if (s1 == null && s2 == null) {
return true;
} else {
return s1 != null && s1.equals(s2);
}
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'Substring' when 'start' is a method
// call or calculated value to ensure that 'start' is obtained just once.
//------------------------------------------------------------------------------------
public static String substring(String string, int start, int length) {
if (length < 0) {
throw new IndexOutOfBoundsException("Parameter length cannot be negative.");
}
return string.substring(start, start + length);
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'Trim' when arguments are used.
//------------------------------------------------------------------------------------
public static String trim(String string, Character... charsToTrim) {
return trimEnd(trimStart(string, charsToTrim), charsToTrim);
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'TrimEnd'.
//------------------------------------------------------------------------------------
public static String trimEnd(String string, Character... charsToTrim) {
if (string == null || charsToTrim == null) {
return string;
}
int lengthToKeep = string.length();
for (int index = string.length() - 1; index >= 0; index--) {
boolean removeChar = false;
if (charsToTrim.length == 0) {
if (Character.isWhitespace(string.charAt(index))) {
lengthToKeep = index;
removeChar = true;
}
} else {
for (int trimCharIndex = 0; trimCharIndex < charsToTrim.length; trimCharIndex++) {
if (string.charAt(index) == charsToTrim[trimCharIndex]) {
lengthToKeep = index;
removeChar = true;
break;
}
}
}
if (!removeChar) {
break;
}
}
return string.substring(0, lengthToKeep);
}
//------------------------------------------------------------------------------------
// This method replaces the .NET string method 'TrimStart'.
//------------------------------------------------------------------------------------
public static String trimStart(String string, Character... charsToTrim) {
if (string == null || charsToTrim == null) {
return string;
}
int startingIndex = 0;
for (int index = 0; index < string.length(); index++) {
boolean removeChar = false;
if (charsToTrim.length == 0) {
if (Character.isWhitespace(string.charAt(index))) {
startingIndex = index + 1;
removeChar = true;
}
} else {
for (int trimCharIndex = 0; trimCharIndex < charsToTrim.length; trimCharIndex++) {
if (string.charAt(index) == charsToTrim[trimCharIndex]) {
startingIndex = index + 1;
removeChar = true;
break;
}
}
}
if (!removeChar) {
break;
}
}
return string.substring(startingIndex);
}
}