Improvements in the ModelComponentToVerilogConverter:
[Mograsim.git] / plugins / net.mograsim.logic.model.verilog / src / net / mograsim / logic / model / verilog / model / VerilogComponentDeclaration.java
1 package net.mograsim.logic.model.verilog.model;
2
3 import java.util.HashSet;
4 import java.util.List;
5 import java.util.Objects;
6 import java.util.Set;
7
8 import net.mograsim.logic.model.verilog.model.signals.IOPort;
9
10 public class VerilogComponentDeclaration
11 {
12         private final String id;
13         private final List<IOPort> ioPorts;
14
15         public VerilogComponentDeclaration(String id, List<IOPort> ioPorts)
16         {
17                 this.id = Objects.requireNonNull(id);
18                 this.ioPorts = List.copyOf(ioPorts);
19
20                 check();
21         }
22
23         private void check()
24         {
25                 Set<String> usedNames = new HashSet<>();
26
27                 for (IOPort ioPort : ioPorts)
28                         if (!usedNames.add(ioPort.getName()))
29                                 throw new IllegalArgumentException("Name occurs twice: " + ioPort.getName());
30         }
31
32         public String getID()
33         {
34                 return id;
35         }
36
37         public List<IOPort> getIOPorts()
38         {
39                 return ioPorts;
40         }
41
42         @Override
43         public int hashCode()
44         {
45                 final int prime = 31;
46                 int result = 1;
47                 result = prime * result + ((ioPorts == null) ? 0 : ioPorts.hashCode());
48                 result = prime * result + ((id == null) ? 0 : id.hashCode());
49                 return result;
50         }
51
52         @Override
53         public String toString()
54         {
55                 return id + "[" + ioPorts.size() + "]";
56         }
57
58         @Override
59         public boolean equals(Object obj)
60         {
61                 if (this == obj)
62                         return true;
63                 if (obj == null)
64                         return false;
65                 if (getClass() != obj.getClass())
66                         return false;
67                 VerilogComponentDeclaration other = (VerilogComponentDeclaration) obj;
68                 if (ioPorts == null)
69                 {
70                         if (other.ioPorts != null)
71                                 return false;
72                 } else if (!ioPorts.equals(other.ioPorts))
73                         return false;
74                 if (id == null)
75                 {
76                         if (other.id != null)
77                                 return false;
78                 } else if (!id.equals(other.id))
79                         return false;
80                 return true;
81         }
82 }