Coverage Summary for Class: Id (com.acciente.oacc.sql.internal.persister.id)
Class | Class, % | Method, % | Line, % |
---|---|---|---|
Id | 100% (1/ 1) | 83.3% (5/ 6) | 63.2% (12/ 19) |
1 /*
2 * Copyright 2009-2018, Acciente LLC
3 *
4 * Acciente LLC licenses this file to you under the
5 * Apache License, Version 2.0 (the "License"); you
6 * may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
14 * OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License.
17 */
18 package com.acciente.oacc.sql.internal.persister.id;
19
20 public class Id<T> {
21 private final long idValue;
22
23 private Id(long idValue) {
24 this.idValue = idValue;
25 }
26
27 public long getValue() {
28 return idValue;
29 }
30
31 public static <T> Id<T> from(Long idValue) {
32 if (idValue == null) {
33 return null;
34 }
35 return new Id<>(idValue);
36 }
37
38 public static <T> Id<T> from(Integer idValue) {
39 if (idValue == null) {
40 return null;
41 }
42 return new Id<>(idValue);
43 }
44
45 @Override
46 public boolean equals(Object other) {
47 if (this == other) {
48 return true;
49 }
50 if (other == null || getClass() != other.getClass()) {
51 return false;
52 }
53
54 Id otherId = (Id) other;
55
56 if (idValue != otherId.idValue) {
57 return false;
58 }
59
60 return true;
61 }
62
63 @Override
64 public int hashCode() {
65 return (int) (idValue ^ (idValue >>> 32));
66 }
67 }