461aa02d30bcbabc9a25ef4eba3971ae536a409b
[Mograsim.git] / plugins / net.mograsim.logic.model.verilog / src / net / mograsim / logic / model / verilog / converter / PinNameBit.java
1 package net.mograsim.logic.model.verilog.converter;
2
3 import java.util.Objects;
4
5 public class PinNameBit
6 {
7         private final String name;
8         private final int bit;
9
10         public PinNameBit(String name, int bit)
11         {
12                 this.name = Objects.requireNonNull(name);
13                 this.bit = bit;
14
15                 check();
16         }
17
18         private void check()
19         {
20                 if (bit < 0)
21                         throw new IllegalArgumentException("Bit out of range: " + bit);
22         }
23
24         public String getName()
25         {
26                 return name;
27         }
28
29         public int getBit()
30         {
31                 return bit;
32         }
33
34         @Override
35         public String toString()
36         {
37                 return name + "[" + bit + "]";
38         }
39
40         @Override
41         public int hashCode()
42         {
43                 final int prime = 31;
44                 int result = 1;
45                 result = prime * result + bit;
46                 result = prime * result + ((name == null) ? 0 : name.hashCode());
47                 return result;
48         }
49
50         @Override
51         public boolean equals(Object obj)
52         {
53                 if (this == obj)
54                         return true;
55                 if (obj == null)
56                         return false;
57                 if (getClass() != obj.getClass())
58                         return false;
59                 PinNameBit other = (PinNameBit) obj;
60                 if (bit != other.bit)
61                         return false;
62                 if (name == null)
63                 {
64                         if (other.name != null)
65                                 return false;
66                 } else if (!name.equals(other.name))
67                         return false;
68                 return true;
69         }
70 }