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