aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/util
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-24 08:16:16 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-24 08:16:16 +0000
commit3e2786a004eddf968a5fa7d5a92dff5b1b5f7734 (patch)
tree7fa1bcc1e484cd0ef782f64baf504ee83333d397 /src/main/java/org/zwobble/mammoth/util
parent0dc3a12affc2e46c1a0df2899cf51a1ae3fdbd61 (diff)
Create internal package
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/util')
-rw-r--r--src/main/java/org/zwobble/mammoth/util/Casts.java13
-rw-r--r--src/main/java/org/zwobble/mammoth/util/InputStreamSupplier.java9
-rw-r--r--src/main/java/org/zwobble/mammoth/util/MammothIterables.java11
-rw-r--r--src/main/java/org/zwobble/mammoth/util/MammothLists.java50
-rw-r--r--src/main/java/org/zwobble/mammoth/util/MammothMaps.java32
-rw-r--r--src/main/java/org/zwobble/mammoth/util/MammothOptionals.java30
-rw-r--r--src/main/java/org/zwobble/mammoth/util/MammothStrings.java11
7 files changed, 0 insertions, 156 deletions
diff --git a/src/main/java/org/zwobble/mammoth/util/Casts.java b/src/main/java/org/zwobble/mammoth/util/Casts.java
deleted file mode 100644
index 0925990..0000000
--- a/src/main/java/org/zwobble/mammoth/util/Casts.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.zwobble.mammoth.util;
-
-import java.util.Optional;
-
-public class Casts {
- public static <T> Optional<T> tryCast(Class<T> type, Object value) {
- try {
- return Optional.of(type.cast(value));
- } catch (ClassCastException exception) {
- return Optional.empty();
- }
- }
-}
diff --git a/src/main/java/org/zwobble/mammoth/util/InputStreamSupplier.java b/src/main/java/org/zwobble/mammoth/util/InputStreamSupplier.java
deleted file mode 100644
index 0f42389..0000000
--- a/src/main/java/org/zwobble/mammoth/util/InputStreamSupplier.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.zwobble.mammoth.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-@FunctionalInterface
-public interface InputStreamSupplier {
- InputStream open() throws IOException;
-}
diff --git a/src/main/java/org/zwobble/mammoth/util/MammothIterables.java b/src/main/java/org/zwobble/mammoth/util/MammothIterables.java
deleted file mode 100644
index 89caf61..0000000
--- a/src/main/java/org/zwobble/mammoth/util/MammothIterables.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.zwobble.mammoth.util;
-
-import com.google.common.collect.Iterables;
-
-import java.util.Optional;
-
-public class MammothIterables {
- public static <T> Optional<T> tryGetLast(Iterable<T> iterable) {
- return Optional.ofNullable(Iterables.getLast(iterable, null));
- }
-}
diff --git a/src/main/java/org/zwobble/mammoth/util/MammothLists.java b/src/main/java/org/zwobble/mammoth/util/MammothLists.java
deleted file mode 100644
index bbdaa7b..0000000
--- a/src/main/java/org/zwobble/mammoth/util/MammothLists.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.zwobble.mammoth.util;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Ordering;
-
-import java.util.List;
-
-public class MammothLists {
- public static <T> List<T> list() {
- return ImmutableList.of();
- }
-
- public static <T> List<T> list(T value1) {
- return ImmutableList.of(value1);
- }
-
- public static <T> List<T> list(T value1, T value2) {
- return ImmutableList.of(value1, value2);
- }
-
- public static <T> List<T> list(T value1, T value2, T value3) {
- return ImmutableList.of(value1, value2, value3);
- }
-
- public static <T> List<T> cons(T head, Iterable<T> tail) {
- return concat(list(head), tail);
- }
-
- public static <T> List<T> concat(Iterable<T> first, Iterable<T> second) {
- return ImmutableList.copyOf(Iterables.concat(first, second));
- }
-
- public static <T, R> List<R> eagerMap(Iterable<T> iterable, Function<T, R> function) {
- return ImmutableList.copyOf(Iterables.transform(iterable, function));
- }
-
- public static <T, R> List<R> eagerFlatMap(Iterable<T> iterable, Function<T, Iterable<R>> function) {
- return ImmutableList.copyOf(Iterables.concat(Iterables.transform(iterable, function)));
- }
-
- public static <T, R extends Comparable<R>> List<T> orderedBy(Iterable<T> iterable, Function<T, R> getKey) {
- return orderBy(getKey).sortedCopy(iterable);
- }
-
- private static <T, R extends Comparable<R>> Ordering<T> orderBy(Function<T, R> getKey) {
- return Ordering.from((first, second) -> getKey.apply(first).compareTo(getKey.apply(second)));
- }
-}
diff --git a/src/main/java/org/zwobble/mammoth/util/MammothMaps.java b/src/main/java/org/zwobble/mammoth/util/MammothMaps.java
deleted file mode 100644
index 782bd91..0000000
--- a/src/main/java/org/zwobble/mammoth/util/MammothMaps.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.zwobble.mammoth.util;
-
-import com.google.common.collect.ImmutableMap;
-
-import java.util.Map;
-import java.util.function.Function;
-
-public class MammothMaps {
- public static <K, V> Map<K, V> map() {
- return ImmutableMap.of();
- }
-
- public static <K, V> Map<K, V> map(K key1, V value1) {
- return ImmutableMap.of(key1, value1);
- }
-
- public static <K, V> Map<K, V> map(K key1, V value1, K key2, V value2) {
- return ImmutableMap.of(key1, value1, key2, value2);
- }
-
- public static <K, V> Map<K, V> map(K key1, V value1, K key2, V value2, K key3, V value3) {
- return ImmutableMap.of(key1, value1, key2, value2, key3, value3);
- }
-
- public static <T, K, V> Map<K, V> toMap(Iterable<T> iterable, Function<T, Map.Entry<K, V>> function) {
- ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
- for (T element : iterable) {
- builder.put(function.apply(element));
- }
- return builder.build();
- }
-}
diff --git a/src/main/java/org/zwobble/mammoth/util/MammothOptionals.java b/src/main/java/org/zwobble/mammoth/util/MammothOptionals.java
deleted file mode 100644
index 6890f16..0000000
--- a/src/main/java/org/zwobble/mammoth/util/MammothOptionals.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.zwobble.mammoth.util;
-
-import java.util.Optional;
-import java.util.function.BiFunction;
-
-public class MammothOptionals {
- public static <T1, T2, R> Optional<R> flatMap(
- Optional<T1> first,
- Optional<T2> second,
- BiFunction<T1, T2, Optional<R>> function)
- {
- if (first.isPresent() && second.isPresent()) {
- return function.apply(first.get(), second.get());
- } else {
- return Optional.empty();
- }
- }
-
- public static <T1, T2, R> Optional<R> map(
- Optional<T1> first,
- Optional<T2> second,
- BiFunction<T1, T2, R> function)
- {
- if (first.isPresent() && second.isPresent()) {
- return Optional.of(function.apply(first.get(), second.get()));
- } else {
- return Optional.empty();
- }
- }
-}
diff --git a/src/main/java/org/zwobble/mammoth/util/MammothStrings.java b/src/main/java/org/zwobble/mammoth/util/MammothStrings.java
deleted file mode 100644
index bdd826c..0000000
--- a/src/main/java/org/zwobble/mammoth/util/MammothStrings.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.zwobble.mammoth.util;
-
-public class MammothStrings {
- public static String trimLeft(String value, char character) {
- int index = 0;
- while (index < value.length() && value.charAt(index) == character) {
- index++;
- }
- return value.substring(index);
- }
-}