Improvements in the ModelComponentToVerilogConverter:
[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 import net.mograsim.logic.model.model.components.ModelComponent;
6 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
7
8 public class PinNameBit
9 {
10         private final String name;
11         private final int bit;
12
13         public PinNameBit(String name, int bit)
14         {
15                 this.name = Objects.requireNonNull(name);
16                 this.bit = bit;
17
18                 check();
19         }
20
21         private void check()
22         {
23                 if (bit < 0)
24                         throw new IllegalArgumentException("Bit out of range: " + bit);
25         }
26
27         public String getName()
28         {
29                 return name;
30         }
31
32         public int getBit()
33         {
34                 return bit;
35         }
36
37         public PinBit toPinBit(ModelComponent pinParent)
38         {
39                 return new PinBit(pinParent.getPin(name), bit);
40         }
41
42         public PinBit toSubmodelPinBit(SubmodelComponent submodelComponent)
43         {
44                 return new PinBit(submodelComponent.getSubmodelPin(name), bit);
45         }
46
47         @Override
48         public String toString()
49         {
50                 return name + "[" + bit + "]";
51         }
52
53         @Override
54         public int hashCode()
55         {
56                 final int prime = 31;
57                 int result = 1;
58                 result = prime * result + bit;
59                 result = prime * result + ((name == null) ? 0 : name.hashCode());
60                 return result;
61         }
62
63         @Override
64         public boolean equals(Object obj)
65         {
66                 if (this == obj)
67                         return true;
68                 if (obj == null)
69                         return false;
70                 if (getClass() != obj.getClass())
71                         return false;
72                 PinNameBit other = (PinNameBit) obj;
73                 if (bit != other.bit)
74                         return false;
75                 if (name == null)
76                 {
77                         if (other.name != null)
78                                 return false;
79                 } else if (!name.equals(other.name))
80                         return false;
81                 return true;
82         }
83 }