Skip to content

Commit d1cfde7

Browse files
committed
Move stuff to LazyUtilities
1 parent 87e3ce6 commit d1cfde7

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/main/java/xyz/srnyx/lazylibrary/LazyLibrary.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818

1919
import xyz.srnyx.lazylibrary.settings.ApplicationDependency;
2020
import xyz.srnyx.lazylibrary.settings.LazySettings;
21+
import xyz.srnyx.lazylibrary.utility.LazyUtilities;
2122

2223
import java.sql.SQLException;
23-
import java.util.Random;
2424
import java.util.Scanner;
25-
import java.util.concurrent.Executors;
26-
import java.util.concurrent.ScheduledExecutorService;
2725
import java.util.concurrent.TimeUnit;
2826
import java.util.function.Supplier;
2927

@@ -37,22 +35,6 @@ public class LazyLibrary extends Stringable {
3735
* The {@link Logger} instance
3836
*/
3937
@NotNull public static Logger LOGGER = LoggerFactory.getLogger("LazyLibrary");
40-
/**
41-
* A {@link Random} instance
42-
*/
43-
@NotNull public static final Random RANDOM = new Random();
44-
/**
45-
* The number of available CPU processors
46-
*/
47-
public static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
48-
/**
49-
* A {@link ScheduledExecutorService} for CPU intensive tasks (heavy computation, such as mathematical calculations or data processing)
50-
*/
51-
@NotNull public static final ScheduledExecutorService CPU_SCHEDULER = Executors.newScheduledThreadPool(AVAILABLE_PROCESSORS);
52-
/**
53-
* A {@link ScheduledExecutorService} for IO intensive tasks (waiting for external resources, such as reading/writing files, making network requests, or querying a database)
54-
*/
55-
@NotNull public static final ScheduledExecutorService IO_SCHEDULER = Executors.newScheduledThreadPool(AVAILABLE_PROCESSORS * 2);
5638

5739
/**
5840
* The {@link LazySettings settings} for the bot
@@ -136,7 +118,7 @@ public LazyLibrary() {
136118
// Rotating status
137119
if (!settings.activities.isEmpty()) {
138120
final Activity[] array = settings.activities.toArray(new Activity[0]);
139-
CPU_SCHEDULER.scheduleAtFixedRate(() -> jda.getPresence().setActivity(array[RANDOM.nextInt(array.length)]), 0, 1, TimeUnit.MINUTES);
121+
LazyUtilities.CPU_SCHEDULER.scheduleAtFixedRate(() -> jda.getPresence().setActivity(array[LazyUtilities.RANDOM.nextInt(array.length)]), 0, 1, TimeUnit.MINUTES);
140122
}
141123
}
142124

src/main/java/xyz/srnyx/lazylibrary/settings/LazySettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class LazySettings extends Stringable {
6565
* A list of {@link Activity activities} to rotate between every minute
6666
* <br><i>Leave empty to disable</i>
6767
*/
68-
@NotNull public List<Activity> activities = new ArrayList<>();
68+
@NotNull public Set<Activity> activities = new HashSet<>();
6969

7070
/**
7171
* Creates a new {@link LazySettings} for the given {@link LazyLibrary}

src/main/java/xyz/srnyx/lazylibrary/utility/LazyUtilities.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,31 @@
2727
import xyz.srnyx.lazylibrary.LazyEmoji;
2828

2929
import java.util.*;
30+
import java.util.concurrent.Executors;
31+
import java.util.concurrent.ScheduledExecutorService;
3032
import java.util.function.Function;
3133

3234

3335
/**
3436
* Class for miscellaneous utilities
3537
*/
3638
public class LazyUtilities {
39+
/**
40+
* A {@link Random} instance
41+
*/
42+
@NotNull public static final Random RANDOM = new Random();
43+
/**
44+
* The number of available CPU processors
45+
*/
46+
public static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
47+
/**
48+
* A {@link ScheduledExecutorService} for CPU intensive tasks (heavy computation, such as mathematical calculations or data processing)
49+
*/
50+
@NotNull public static final ScheduledExecutorService CPU_SCHEDULER = Executors.newScheduledThreadPool(AVAILABLE_PROCESSORS);
51+
/**
52+
* A {@link ScheduledExecutorService} for IO intensive tasks (waiting for external resources, such as reading/writing files, making network requests, or querying a database)
53+
*/
54+
@NotNull public static final ScheduledExecutorService IO_SCHEDULER = Executors.newScheduledThreadPool(AVAILABLE_PROCESSORS * 2);
3755
/**
3856
* An empty set of {@link Message.MentionType mention types}
3957
*/

0 commit comments

Comments
 (0)