-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log matches with sequential match ids
- Loading branch information
Showing
4 changed files
with
34 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
server/src/main/java/ru/croccode/hypernull/server/MatchId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ru.croccode.hypernull.server; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public final class MatchId { | ||
|
||
private final static AtomicInteger COUNTER = new AtomicInteger(0); | ||
|
||
private MatchId() { | ||
} | ||
|
||
public static String nextId() { | ||
// format: current time (epoch millis) | ||
// + 2 chars of sync match counter reminder | ||
// separated by underscore | ||
int n = 'z' - 'a' + 1; | ||
int mod = n * n; | ||
int k = COUNTER.getAndIncrement() % mod; | ||
if (k < 0) | ||
k += mod; | ||
long now = System.currentTimeMillis(); | ||
return now | ||
+ "_" | ||
+ (char)('a' + (k / n)) | ||
+ (char)('a' + (k % n)); | ||
} | ||
} |