Last change
on this file since 341 was 336, checked in by Tim Baarslag, 5 years ago |
getRGBcolor() was not working
|
File size:
1.4 KB
|
Line | |
---|
1 | package bargainingchips;
|
---|
2 |
|
---|
3 | import java.util.Random;
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Chip is the fundamental element in Bargaining Chips.
|
---|
7 | * A chip could be assumed as any item at any scenario, e.g. Paracetamol in pharmaceutical market,
|
---|
8 | * a chair in furniture market, or a Red Dot.
|
---|
9 | * A chip is a color, where color is the id of the chip.
|
---|
10 | *
|
---|
11 | * Immutable.
|
---|
12 | */
|
---|
13 | public class Chip
|
---|
14 | {
|
---|
15 | private final String color;
|
---|
16 | private static final String [] colors = new String [] {"Black", "Blue", "Cyan", "darkGray", "Gray", "lightGray", "Green", "Magenta", "Orange", "Pink", "Red", "White", "Yellow"};
|
---|
17 |
|
---|
18 | public Chip()
|
---|
19 | {
|
---|
20 | int rnd = new Random().nextInt(colors.length);
|
---|
21 | color = colors[rnd];
|
---|
22 | }
|
---|
23 |
|
---|
24 | public Chip(String c)
|
---|
25 | {
|
---|
26 | color = c;
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * @return the color
|
---|
31 | */
|
---|
32 | public String getColor()
|
---|
33 | {
|
---|
34 | return color;
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public String toString()
|
---|
39 | {
|
---|
40 | return getColor();
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public int hashCode() {
|
---|
45 | final int prime = 31;
|
---|
46 | int result = 1;
|
---|
47 | result = prime * result + ((color == null) ? 0 : color.hashCode());
|
---|
48 | return result;
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public boolean equals(Object obj) {
|
---|
53 | if (this == obj)
|
---|
54 | return true;
|
---|
55 | if (obj == null)
|
---|
56 | return false;
|
---|
57 | if (getClass() != obj.getClass())
|
---|
58 | return false;
|
---|
59 | Chip other = (Chip) obj;
|
---|
60 | if (color == null) {
|
---|
61 | if (other.color != null)
|
---|
62 | return false;
|
---|
63 | } else if (!color.equals(other.color))
|
---|
64 | return false;
|
---|
65 | return true;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.