X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fyourshouter%2Fapi%2Fpersistence%2Fjpa%2FPrimaryKey.java;fp=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fyourshouter%2Fapi%2Fpersistence%2Fjpa%2FPrimaryKey.java;h=83f6942a92e84cb2169c14cea159c71b799e06c6;hb=6cdcdbafafc905304c5b8b7549401548e0eb0926;hp=0000000000000000000000000000000000000000;hpb=ec7b19b3af030b6d30d751f4f959da5cd552572b;p=jpa-converters diff --git a/src/test/java/de/juplo/yourshouter/api/persistence/jpa/PrimaryKey.java b/src/test/java/de/juplo/yourshouter/api/persistence/jpa/PrimaryKey.java new file mode 100644 index 0000000..83f6942 --- /dev/null +++ b/src/test/java/de/juplo/yourshouter/api/persistence/jpa/PrimaryKey.java @@ -0,0 +1,129 @@ +package de.juplo.yourshouter.api.persistence.jpa; + + +import de.juplo.yourshouter.api.model.DataEntry.NodeType; +import de.juplo.yourshouter.api.model.Node; +import de.juplo.yourshouter.api.model.NodeData; +import de.juplo.yourshouter.api.storage.Storage; +import de.juplo.yourshouter.api.storage.Uri; +import java.io.Serializable; +import java.net.URI; +import java.util.Objects; + + + +/** + * Class, that acts as primary key for {@link Node}s. + * @author Kai Moritz + */ +public class PrimaryKey implements Serializable +{ + private URI source; + private NodeType nodeType; + private String id; + + + public PrimaryKey() {} + + public PrimaryKey(Uri uri) + { + this.source = uri.source; + this.nodeType = uri.type; + this.id = uri.id; + } + + public PrimaryKey(NodeData node) + { + this.source = node.getSource(); + this.nodeType = node.getNodeType(); + this.id = node.getId(); + } + + public PrimaryKey(NodeType type, String id) + { + this(Storage.getSource(), type, id); + } + + public PrimaryKey(URI source, NodeType type, String id) + { + this.source = source; + this.nodeType = type; + this.id = id; + } + + + public URI getSource() + { + return source; + } + + public void setSource(URI source) + { + this.source = source; + } + + public NodeType getNodeType() + { + return nodeType; + } + + public void setNodeType(NodeType nodeType) + { + this.nodeType = nodeType; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + + @Override + public int hashCode() + { + int hash = 3; + hash = 53 * hash + Objects.hashCode(this.source); + hash = 53 * hash + Objects.hashCode(this.nodeType); + hash = 53 * hash + Objects.hashCode(this.id); + return hash; + } + + @Override + public boolean equals(Object o) + { + if (this == o) + return true; + + if (o == null) + return false; + + if (!(o instanceof PrimaryKey)) + return false; + + final PrimaryKey other = (PrimaryKey)o; + if (!Objects.equals(this.source, other.source)) + return false; + if (this.nodeType != other.nodeType) + return false; + return Objects.equals(this.id, other.id); + } + + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append(source); + builder.append('/'); + builder.append(nodeType); + builder.append('/'); + builder.append(id); + builder.append('/'); + return builder.toString(); + } +}