source: src/main/java/onetomany/bargainingchipsgame/Chip.java@ 271

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
RevLine 
[253]1package onetomany.bargainingchipsgame;
[233]2
[236]3import java.util.Random;
[233]4
[264]5import java.awt.Color;
6
[233]7/**
[264]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.
[271]11 * A chip is a color, where color is the id of the chip.
12 *
13 * Immutable.
[233]14 */
15public class Chip
[264]16{
[271]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"};
[233]19
20 public Chip()
21 {
[271]22 int rnd = new Random().nextInt(colors.length);
23 color = colors[rnd];
[233]24 }
25
[271]26 public Chip(String c)
[233]27 {
[264]28 color = c;
[233]29 }
[236]30
[233]31 /**
32 * @return the color
33 */
34 public String getColor()
35 {
36 return color;
37 }
38
39 @Override
40 public String toString()
41 {
[271]42 return getColor();
[233]43 }
[236]44
[264]45 public Color getRGBcolor()
[236]46 {
[264]47 return Color.decode(color);
[236]48 }
49
[271]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 }
[236]74
[271]75
[233]76}
Note: See TracBrowser for help on using the repository browser.