diff options
author | Samuel Holland <samuel@sholland.org> | 2018-06-19 00:47:48 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-06-19 21:59:44 -0500 |
commit | 4acee49d4b0da6273cd9ffef1573185f955b5774 (patch) | |
tree | 3f322d5255209c3d14d50eec30f17e60c3e46101 /app/src/main/java/com/wireguard/android/util | |
parent | d3a8291a7a0706337531e368e0ad9f584534aa7d (diff) |
util: Extract non-Android utility interfaces
As part of a refactoring that will likely introduce more custom
collection classes, move the non-Android-specific parts outside the
com.wireguard.android package.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/util')
7 files changed, 11 insertions, 72 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/Keyed.java b/app/src/main/java/com/wireguard/android/util/Keyed.java deleted file mode 100644 index ca8c142a..00000000 --- a/app/src/main/java/com/wireguard/android/util/Keyed.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright © 2018 Samuel Holland <samuel@sholland.org> - * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -package com.wireguard.android.util; - -/** - * Interface for objects that have a identifying key of the given type. - */ - -public interface Keyed<K> { - K getKey(); -} diff --git a/app/src/main/java/com/wireguard/android/util/KeyedList.java b/app/src/main/java/com/wireguard/android/util/KeyedList.java deleted file mode 100644 index 9518758e..00000000 --- a/app/src/main/java/com/wireguard/android/util/KeyedList.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright © 2018 Samuel Holland <samuel@sholland.org> - * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -package com.wireguard.android.util; - -import java.util.Collection; -import java.util.List; - -/** - * A list containing elements that can be looked up by key. A {@code KeyedList} cannot contain - * {@code null} elements. - */ - -public interface KeyedList<K, E extends Keyed<? extends K>> extends List<E> { - boolean containsAllKeys(Collection<K> keys); - - boolean containsKey(K key); - - E get(K key); - - E getLast(K key); - - int indexOfKey(K key); - - int lastIndexOfKey(K key); -} diff --git a/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java index 70842052..10558319 100644 --- a/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java @@ -9,6 +9,8 @@ package com.wireguard.android.util; import android.databinding.ObservableArrayList; import android.support.annotation.NonNull; +import com.wireguard.util.Keyed; + import java.util.Collection; import java.util.ListIterator; import java.util.Objects; diff --git a/app/src/main/java/com/wireguard/android/util/ObservableKeyedList.java b/app/src/main/java/com/wireguard/android/util/ObservableKeyedList.java index d810b703..169afe42 100644 --- a/app/src/main/java/com/wireguard/android/util/ObservableKeyedList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableKeyedList.java @@ -8,6 +8,9 @@ package com.wireguard.android.util; import android.databinding.ObservableList; +import com.wireguard.util.Keyed; +import com.wireguard.util.KeyedList; + /** * A list that is both keyed and observable. */ diff --git a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java index 0612deb5..58ec4383 100644 --- a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java @@ -8,6 +8,9 @@ package com.wireguard.android.util; import android.support.annotation.NonNull; +import com.wireguard.util.Keyed; +import com.wireguard.util.SortedKeyedList; + import java.util.AbstractList; import java.util.Collection; import java.util.Collections; diff --git a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedList.java b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedList.java index 5a821689..8ebc5985 100644 --- a/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedList.java @@ -6,6 +6,9 @@ package com.wireguard.android.util; +import com.wireguard.util.Keyed; +import com.wireguard.util.SortedKeyedList; + /** * A list that is both sorted/keyed and observable. */ diff --git a/app/src/main/java/com/wireguard/android/util/SortedKeyedList.java b/app/src/main/java/com/wireguard/android/util/SortedKeyedList.java deleted file mode 100644 index cca6d017..00000000 --- a/app/src/main/java/com/wireguard/android/util/SortedKeyedList.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2018 Samuel Holland <samuel@sholland.org> - * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -package com.wireguard.android.util; - -import java.util.Collection; -import java.util.Comparator; -import java.util.Set; - -/** - * A keyed list where all elements are sorted by the comparator returned by {@code comparator()} - * applied to their keys. - */ - -public interface SortedKeyedList<K, E extends Keyed<? extends K>> extends KeyedList<K, E> { - Comparator<? super K> comparator(); - - K firstKey(); - - Set<K> keySet(); - - K lastKey(); - - Collection<E> values(); -} |