From 4acee49d4b0da6273cd9ffef1573185f955b5774 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Tue, 19 Jun 2018 00:47:48 -0500 Subject: 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 --- .../android/databinding/BindingAdapters.java | 2 +- .../databinding/ObservableKeyedListAdapter.java | 2 +- .../java/com/wireguard/android/model/Tunnel.java | 2 +- .../java/com/wireguard/android/util/Keyed.java | 15 ----------- .../java/com/wireguard/android/util/KeyedList.java | 29 ---------------------- .../android/util/ObservableKeyedArrayList.java | 2 ++ .../android/util/ObservableKeyedList.java | 3 +++ .../util/ObservableSortedKeyedArrayList.java | 3 +++ .../android/util/ObservableSortedKeyedList.java | 3 +++ .../wireguard/android/util/SortedKeyedList.java | 28 --------------------- 10 files changed, 14 insertions(+), 75 deletions(-) delete mode 100644 app/src/main/java/com/wireguard/android/util/Keyed.java delete mode 100644 app/src/main/java/com/wireguard/android/util/KeyedList.java delete mode 100644 app/src/main/java/com/wireguard/android/util/SortedKeyedList.java (limited to 'app/src/main/java/com/wireguard/android') diff --git a/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java b/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java index bd8d6efd..ba6845ba 100644 --- a/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java +++ b/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java @@ -15,7 +15,7 @@ import android.widget.ListView; import android.widget.TextView; import com.wireguard.android.R; -import com.wireguard.android.util.Keyed; +import com.wireguard.util.Keyed; import com.wireguard.android.util.ObservableKeyedList; import com.wireguard.android.widget.ToggleSwitch; import com.wireguard.android.widget.ToggleSwitch.OnBeforeCheckedChangeListener; diff --git a/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedListAdapter.java b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedListAdapter.java index 90c85582..452d2ec4 100644 --- a/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedListAdapter.java +++ b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedListAdapter.java @@ -16,7 +16,7 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import com.wireguard.android.BR; -import com.wireguard.android.util.Keyed; +import com.wireguard.util.Keyed; import com.wireguard.android.util.ObservableKeyedList; import java.lang.ref.WeakReference; diff --git a/app/src/main/java/com/wireguard/android/model/Tunnel.java b/app/src/main/java/com/wireguard/android/model/Tunnel.java index bdfa0dbc..0b1ba895 100644 --- a/app/src/main/java/com/wireguard/android/model/Tunnel.java +++ b/app/src/main/java/com/wireguard/android/model/Tunnel.java @@ -13,7 +13,7 @@ import android.support.annotation.Nullable; import com.wireguard.android.BR; import com.wireguard.android.util.ExceptionLoggers; -import com.wireguard.android.util.Keyed; +import com.wireguard.util.Keyed; import com.wireguard.config.Config; import java.util.regex.Pattern; 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 - * Copyright © 2018 Jason A. Donenfeld . 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 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 - * Copyright © 2018 Jason A. Donenfeld . 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> extends List { - boolean containsAllKeys(Collection 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 - * Copyright © 2018 Jason A. Donenfeld . 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> extends KeyedList { - Comparator comparator(); - - K firstKey(); - - Set keySet(); - - K lastKey(); - - Collection values(); -} -- cgit v1.2.3