-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathG.java
More file actions
65 lines (58 loc) · 2.11 KB
/
Copy pathG.java
File metadata and controls
65 lines (58 loc) · 2.11 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.util.EnumMap;
import java.util.Random;
import java.util.Vector;
import java.util.concurrent.Semaphore;
// A "Globals" class containing utilities used in every other class
public class G{
public final static long start_time=time();
public final static int T_PRICE=10,
O_PRICE=20,
O_QUANT=100,
O_THR=10,
MINUTE_DURN=10, //seconds
PREP_TIME=1, //*MINUTE_DURN
DLRY_TIME=2;
// random seed
public final static Random rand = new Random();
// For prep time calculation
public static Semaphore teaSema = new Semaphore(1);
public static int teaCounter = 0;
public static Semaphore coffeeSema = new Semaphore(1);
public static int coffeeCounter = 0;
// these are initialized by shop server
public final static EnumMap<Itemtype, Integer> Prices = new EnumMap<Itemtype, Integer>(Itemtype.class);
public static Vector<Item> items;
// current day offset
public static int day_number=0;
// utility functions
public static long seconds(){
return (time()-start_time)/1000;
}
public static long time(){
return System.currentTimeMillis();
}
// public static void printt(String msg){
// System.out.println(Thread.currentThread().getName()+": "+msg);
// }
public static void println_t(String msg){
System.out.println("["+seconds()+"s] "+msg);
}
public static void println(String msg){
System.out.println(msg);
}
public static void print(String msg){
System.out.print(msg);
}
public static String timestamp(LocalDateTime date){
return DateTimeFormatter.ofPattern("dd-MM HH:mm:ss").format(date);
}
public static String timestamp(int day){
return DateTimeFormatter.ofPattern("dd-MM HH:mm:ss").format(LocalDateTime.now().plusDays(day));
}
public static String timestamp(){
return DateTimeFormatter.ofPattern("dd-MM HH:mm:ss").format(LocalDateTime.now().plusDays(day_number));
}
}