From 8b487d79e4d14a8d695e983fe35ad779746d352a Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Mon, 15 Nov 2021 04:20:08 -0500 Subject: [PATCH] Adds Comparable to identifiers that are used in TreeSets. (#1103) Co-authored-by: Dennis Sheirer --- .../mdc1200/identifier/MDC1200Identifier.java | 37 ++++++++++--------- .../tait/identifier/TaitIdentifier.java | 16 +++++--- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/java/io/github/dsheirer/module/decode/mdc1200/identifier/MDC1200Identifier.java b/src/main/java/io/github/dsheirer/module/decode/mdc1200/identifier/MDC1200Identifier.java index bd3794e0..84ad27e2 100644 --- a/src/main/java/io/github/dsheirer/module/decode/mdc1200/identifier/MDC1200Identifier.java +++ b/src/main/java/io/github/dsheirer/module/decode/mdc1200/identifier/MDC1200Identifier.java @@ -1,23 +1,20 @@ /* + * ***************************************************************************** + * Copyright (C) 2014-2021 Dennis Sheirer * - * * ****************************************************************************** - * * Copyright (C) 2014-2019 Dennis Sheirer - * * - * * This program is free software: you can redistribute it and/or modify - * * it under the terms of the GNU General Public License as published by - * * the Free Software Foundation, either version 3 of the License, or - * * (at your option) any later version. - * * - * * This program is distributed in the hope that it will be useful, - * * but WITHOUT ANY WARRANTY; without even the implied warranty of - * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * * GNU General Public License for more details. - * * - * * You should have received a copy of the GNU General Public License - * * along with this program. If not, see - * * ***************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * **************************************************************************** */ package io.github.dsheirer.module.decode.mdc1200.identifier; @@ -29,7 +26,7 @@ import io.github.dsheirer.protocol.Protocol; /** * Identifier for an MDC1200 radio identity */ -public class MDC1200Identifier extends TalkgroupIdentifier +public class MDC1200Identifier extends TalkgroupIdentifier implements Comparable { /** @@ -61,4 +58,10 @@ public class MDC1200Identifier extends TalkgroupIdentifier { return new MDC1200Identifier(value, Role.FROM); } + + @Override + public int compareTo(MDC1200Identifier other) + { + return Integer.compare(getValue(), other != null ? other.getValue() : 0); + } } diff --git a/src/main/java/io/github/dsheirer/module/decode/tait/identifier/TaitIdentifier.java b/src/main/java/io/github/dsheirer/module/decode/tait/identifier/TaitIdentifier.java index 32b5148a..69729a37 100644 --- a/src/main/java/io/github/dsheirer/module/decode/tait/identifier/TaitIdentifier.java +++ b/src/main/java/io/github/dsheirer/module/decode/tait/identifier/TaitIdentifier.java @@ -1,7 +1,6 @@ /* - * ****************************************************************************** - * sdrtrunk - * Copyright (C) 2014-2018 Dennis Sheirer + * ***************************************************************************** + * Copyright (C) 2014-2021 Dennis Sheirer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see - * ***************************************************************************** + * **************************************************************************** */ package io.github.dsheirer.module.decode.tait.identifier; @@ -25,11 +24,12 @@ import io.github.dsheirer.identifier.IdentifierClass; import io.github.dsheirer.identifier.Role; import io.github.dsheirer.identifier.string.StringIdentifier; import io.github.dsheirer.protocol.Protocol; +import org.apache.commons.lang3.StringUtils; /** * Tait-1200 String (ASCII) Identifier */ -public class TaitIdentifier extends StringIdentifier +public class TaitIdentifier extends StringIdentifier implements Comparable { /** * Constructs an identifier with the specified role @@ -60,4 +60,10 @@ public class TaitIdentifier extends StringIdentifier { return new TaitIdentifier(value, Role.TO); } + + @Override + public int compareTo(TaitIdentifier other) + { + return StringUtils.compare(getValue(), other != null ? other.getValue() : null); + } }