Rebuild the full mapping from persistence-jpa-1.5.1 to reproduce the bug
[jpa-converters] / src / test / java / de / juplo / yourshouter / api / persistence / jpa / PrimaryKey.java
1 package de.juplo.yourshouter.api.persistence.jpa;
2
3
4 import de.juplo.yourshouter.api.model.DataEntry.NodeType;
5 import de.juplo.yourshouter.api.model.Node;
6 import de.juplo.yourshouter.api.model.NodeData;
7 import de.juplo.yourshouter.api.storage.Storage;
8 import de.juplo.yourshouter.api.storage.Uri;
9 import java.io.Serializable;
10 import java.net.URI;
11 import java.util.Objects;
12
13
14
15 /**
16  * Class, that acts as primary key for {@link Node}s.
17  * @author Kai Moritz
18  */
19 public class PrimaryKey implements Serializable
20 {
21   private URI source;
22   private NodeType nodeType;
23   private String id;
24
25
26   public PrimaryKey() {}
27
28   public PrimaryKey(Uri uri)
29   {
30     this.source = uri.source;
31     this.nodeType = uri.type;
32     this.id = uri.id;
33   }
34
35   public PrimaryKey(NodeData node)
36   {
37     this.source = node.getSource();
38     this.nodeType = node.getNodeType();
39     this.id = node.getId();
40   }
41
42   public PrimaryKey(NodeType type, String id)
43   {
44     this(Storage.getSource(), type, id);
45   }
46
47   public PrimaryKey(URI source, NodeType type, String id)
48   {
49     this.source = source;
50     this.nodeType = type;
51     this.id = id;
52   }
53
54
55   public URI getSource()
56   {
57     return source;
58   }
59
60   public void setSource(URI source)
61   {
62     this.source = source;
63   }
64
65   public NodeType getNodeType()
66   {
67     return nodeType;
68   }
69
70   public void setNodeType(NodeType nodeType)
71   {
72     this.nodeType = nodeType;
73   }
74
75   public String getId()
76   {
77     return id;
78   }
79
80   public void setId(String id)
81   {
82     this.id = id;
83   }
84
85
86   @Override
87   public int hashCode()
88   {
89     int hash = 3;
90     hash = 53 * hash + Objects.hashCode(this.source);
91     hash = 53 * hash + Objects.hashCode(this.nodeType);
92     hash = 53 * hash + Objects.hashCode(this.id);
93     return hash;
94   }
95
96   @Override
97   public boolean equals(Object o)
98   {
99     if (this == o)
100       return true;
101
102     if (o == null)
103       return false;
104
105     if (!(o instanceof PrimaryKey))
106       return false;
107
108     final PrimaryKey other = (PrimaryKey)o;
109     if (!Objects.equals(this.source, other.source))
110       return false;
111     if (this.nodeType != other.nodeType)
112       return false;
113     return Objects.equals(this.id, other.id);
114   }
115
116
117   @Override
118   public String toString()
119   {
120     StringBuilder builder = new StringBuilder();
121     builder.append(source);
122     builder.append('/');
123     builder.append(nodeType);
124     builder.append('/');
125     builder.append(id);
126     builder.append('/');
127     return builder.toString();
128   }
129 }