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