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/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/util')
-rw-r--r-- | app/src/main/java/com/wireguard/util/Keyed.java | 14 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/util/KeyedList.java | 28 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/util/SortedKeyedList.java | 27 |
3 files changed, 69 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/util/Keyed.java b/app/src/main/java/com/wireguard/util/Keyed.java new file mode 100644 index 00000000..f0b32b6d --- /dev/null +++ b/app/src/main/java/com/wireguard/util/Keyed.java @@ -0,0 +1,14 @@ +/* + * Copyright © 2018 Samuel Holland <samuel@sholland.org> + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +package com.wireguard.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/util/KeyedList.java b/app/src/main/java/com/wireguard/util/KeyedList.java new file mode 100644 index 00000000..1478dc19 --- /dev/null +++ b/app/src/main/java/com/wireguard/util/KeyedList.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2018 Samuel Holland <samuel@sholland.org> + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +package com.wireguard.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/util/SortedKeyedList.java b/app/src/main/java/com/wireguard/util/SortedKeyedList.java new file mode 100644 index 00000000..85aeecff --- /dev/null +++ b/app/src/main/java/com/wireguard/util/SortedKeyedList.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2018 Samuel Holland <samuel@sholland.org> + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +package com.wireguard.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(); +} |