Make BackupLevel.value public

This commit is contained in:
Alex Bakon
2025-06-18 14:22:14 -04:00
committed by GitHub
parent 3c7fd1679f
commit 8f671bd2d0
2 changed files with 28 additions and 32 deletions

View File

@@ -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);
}
}

View File

@@ -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" }
}
}
}