-
Notifications
You must be signed in to change notification settings - Fork 3
/
Item.java
44 lines (37 loc) · 1.07 KB
/
Item.java
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
package producerconsumer;
import com.google.common.base.MoreObjects;
import net.jcip.annotations.ThreadSafe;
import java.util.Random;
import java.util.UUID;
/**
* Created by kennylbj on 16/9/10.
* Item is a element of Buffer.
*/
@ThreadSafe
public final class Item {
private final String itemId;
private final String itemName;
private static final Random random = new Random(System.nanoTime());
private static final String ITEM_NAME[] = {
"apple",
"banana",
"tomato",
"watermelon"
};
private Item(String itemId, String itemName) {
this.itemId = itemId;
this.itemName = itemName;
}
public static Item generate() {
String uuid = UUID.randomUUID().toString();
String name = ITEM_NAME[random.nextInt(ITEM_NAME.length)];
return new Item(uuid, name);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("itemId", itemId)
.add("itemName", itemName)
.toString();
}
}