1 package de.juplo.yourshouter.api.persistence.jpa;
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;
11 import java.util.Objects;
16 * Class, that acts as primary key for {@link Node}s.
19 public class PrimaryKey implements Serializable
22 private NodeType nodeType;
26 public PrimaryKey() {}
28 public PrimaryKey(Uri uri)
30 this.source = uri.source;
31 this.nodeType = uri.type;
35 public PrimaryKey(NodeData node)
37 this.source = node.getSource();
38 this.nodeType = node.getNodeType();
39 this.id = node.getId();
42 public PrimaryKey(NodeType type, String id)
44 this(Storage.getSource(), type, id);
47 public PrimaryKey(URI source, NodeType type, String id)
55 public URI getSource()
60 public void setSource(URI source)
65 public NodeType getNodeType()
70 public void setNodeType(NodeType nodeType)
72 this.nodeType = nodeType;
80 public void setId(String id)
90 hash = 53 * hash + Objects.hashCode(this.source);
91 hash = 53 * hash + Objects.hashCode(this.nodeType);
92 hash = 53 * hash + Objects.hashCode(this.id);
97 public boolean equals(Object o)
105 if (!(o instanceof PrimaryKey))
108 final PrimaryKey other = (PrimaryKey)o;
109 if (!Objects.equals(this.source, other.source))
111 if (this.nodeType != other.nodeType)
113 return Objects.equals(this.id, other.id);
118 public String toString()
120 StringBuilder builder = new StringBuilder();
121 builder.append(source);
123 builder.append(nodeType);
127 return builder.toString();