Config: Make it Comparable

This will be used for future sorting.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-16 01:06:05 -05:00
parent 6d2960b853
commit 76eb65d7d5

View File

@ -5,6 +5,7 @@ import android.databinding.Bindable;
import android.databinding.Observable;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;
import com.wireguard.android.BR;
@ -19,7 +20,8 @@ import java.util.regex.Pattern;
* Represents a wg-quick configuration file, its name, and its connection state.
*/
public class Config extends BaseObservable implements Copyable<Config>, Observable {
public class Config extends BaseObservable
implements Comparable<Config>, Copyable<Config>, Observable {
private static final Pattern PATTERN = Pattern.compile("^[a-zA-Z0-9_=+.-]{1,16}$");
private static boolean isNameValid(final String name) {
@ -31,6 +33,11 @@ public class Config extends BaseObservable implements Copyable<Config>, Observab
private String name;
private final ObservableList<Peer> peers = new ObservableArrayList<>();
@Override
public int compareTo(@NonNull final Config config) {
return getName().compareTo(config.getName());
}
@Override
public Config copy() {
final Config copy = new Config();