Skip to content

Commit d1ee7f1

Browse files
authored
Merge pull request #3 from dotSpaceTeam/dev
Dev
2 parents 62c2972 + 2942239 commit d1ee7f1

File tree

6 files changed

+65
-10
lines changed

6 files changed

+65
-10
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dev.dotspace.common;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
/**
6+
* Label an object with a label. The hashCode of the object is used for hashCode of the {@link ObjectLabel} instance.
7+
*
8+
* @param label to set as identifier.
9+
* @param object to bind to label.
10+
* @param <LABEL> Generic type of the label.
11+
* @param <OBJECT> Generic type of the object.
12+
*/
13+
public record ObjectLabel<LABEL, OBJECT>(@NotNull LABEL label,
14+
@NotNull OBJECT object) {
15+
/**
16+
* See: {@link Object#hashCode()}.
17+
*/
18+
@Override
19+
public int hashCode() {
20+
return this.object().hashCode();
21+
}
22+
}

core/src/main/java/dev/dotspace/common/SpaceCollections.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@
88
import java.util.Collection;
99
import java.util.Optional;
1010
import java.util.concurrent.CompletableFuture;
11-
import java.util.concurrent.ExecutorService;
12-
import java.util.concurrent.Executors;
1311
import java.util.concurrent.ThreadLocalRandom;
1412

1513
/**
1614
* Class with {@link Collection} operations
1715
*/
1816
@NoArgsConstructor(access = AccessLevel.PRIVATE)
1917
public final class SpaceCollections {
20-
private final static ExecutorService SERVICE = Executors.newCachedThreadPool();
21-
2218
/**
2319
* Get a random object of collection. Object wrapped in {@link Optional}
2420
*
@@ -46,8 +42,7 @@ public final class SpaceCollections {
4642
* or empty or if the given object is null in list.
4743
*/
4844
public static <T> @NotNull CompletableFuture<@Nullable T> asyncRandom(final Collection<T> collection) {
49-
final CompletableFuture<@Nullable T> completableFuture = new CompletableFuture<>(); //Create new completableFuture
50-
SERVICE.execute(() -> completableFuture.complete(SpaceCollections.random(collection).orElse(null))); //Complete the future in a separate thread
51-
return completableFuture;
45+
return new CompletableFuture<@Nullable T>()
46+
.completeAsync(() -> SpaceCollections.random(collection).orElse(null)); //Complete the future in a separate thread
5247
}
5348
}

core/src/main/java/dev/dotspace/common/color/SimpleColor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
public record SimpleColor(short red,
1313
short green,
1414
short blue) {
15-
private final static int MIN_VALUE;
16-
private final static int MAX_VALUE;
15+
public final static int MIN_VALUE;
16+
public final static int MAX_VALUE;
1717

1818
static {
1919
MIN_VALUE = 0x0;
@@ -59,7 +59,6 @@ public int value() {
5959
}
6060

6161
//static
62-
6362
/**
6463
* Create new color
6564
*
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package dev.dotspace.common.test;
2+
3+
import dev.dotspace.common.ObjectLabel;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
/**
12+
* Test Class {@link dev.dotspace.common.ObjectLabel}.
13+
*/
14+
public class ObjectLabelTest {
15+
16+
@Test
17+
public void testGetter() {
18+
final short label = 1;
19+
final String object = "test";
20+
final ObjectLabel<Short, String> objectLabel = new ObjectLabel<>(label, object);
21+
22+
Assertions.assertEquals(objectLabel.label(), label);
23+
Assertions.assertEquals(objectLabel.object(), object);
24+
}
25+
26+
@Test
27+
public void testHashCode() {
28+
final String label = "testLabel";
29+
final Map<String, Integer> object = new HashMap<>();
30+
31+
Assertions.assertEquals(object.hashCode(), new ObjectLabel<>(label, object).hashCode());
32+
}
33+
}

core/src/test/java/dev/dotspace/common/test/SpaceCollectionsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import java.util.Optional;
1212
import java.util.Set;
1313

14+
/**
15+
* Test class {@link SpaceCollections}.
16+
*/
1417
public class SpaceCollectionsTest {
1518
private final static @NotNull Set<Integer> NUMBERS_LIST = new HashSet<>();
1619

core/src/test/java/dev/dotspace/common/test/SpaceTimeTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import java.util.concurrent.TimeUnit;
99

10+
/**
11+
* Test Class {@link SpaceTime}.
12+
*/
1013
public class SpaceTimeTest {
1114

1215
@Test

0 commit comments

Comments
 (0)