-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayTimeApiProvider.java
More file actions
39 lines (31 loc) · 1.01 KB
/
PlayTimeApiProvider.java
File metadata and controls
39 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.github.imdmk.playtime;
import org.jetbrains.annotations.NotNull;
public final class PlayTimeApiProvider {
private static volatile PlayTimeApi API; // visibility across threads
private PlayTimeApiProvider() {
throw new UnsupportedOperationException("This class cannot be instantiated.");
}
@NotNull
public static PlayTimeApi get() {
final PlayTimeApi api = API;
if (api == null) {
throw new IllegalStateException("PlayTimeAPI is not registered.");
}
return api;
}
public static boolean isRegistered() {
return API != null;
}
static synchronized void register(@NotNull PlayTimeApi api) {
if (API != null) {
throw new IllegalStateException("PlayTimeAPI is already registered.");
}
API = api;
}
static synchronized void unregister() {
if (API == null) {
throw new IllegalStateException("PlayTimeAPI is not registered.");
}
API = null;
}
}