mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-09 00:22:31 +02:00
Make BackupLevel.value public
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
//
|
||||
// Copyright 2024 Signal Messenger, LLC.
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
package org.signal.libsignal.zkgroup.backups;
|
||||
|
||||
public enum BackupLevel {
|
||||
// This must match the Rust version of the enum.
|
||||
FREE(200),
|
||||
PAID(201);
|
||||
|
||||
private final int value;
|
||||
|
||||
BackupLevel(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static BackupLevel fromValue(int value) {
|
||||
// A linear scan is simpler than a hash lookup for a set of values this small.
|
||||
for (final var backupLevel : BackupLevel.values()) {
|
||||
if (backupLevel.getValue() == value) {
|
||||
return backupLevel;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid backup level: " + value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Copyright 2024 Signal Messenger, LLC.
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
package org.signal.libsignal.zkgroup.backups
|
||||
|
||||
public enum class BackupLevel {
|
||||
// This must match the Rust version of the enum.
|
||||
FREE(200),
|
||||
PAID(201),
|
||||
;
|
||||
|
||||
public val value: Int
|
||||
|
||||
private constructor(value: Int) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
public companion object {
|
||||
@JvmStatic
|
||||
public fun fromValue(value: Int): BackupLevel {
|
||||
// A linear scan is simpler than a hash lookup for a set of values this small.
|
||||
val found = BackupLevel.values().firstOrNull { it.value == value }
|
||||
return requireNotNull(found) { "Invalid backup level: $value" }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user