Skip to content

Package: Value$NullValue

Value$NullValue

nameinstructionbranchcomplexitylinemethod
Value.NullValue()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
stringValue()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.model;
16:
17: import java.util.Objects;
18:
19: /**
20: * Represents assertion value. </p>
21: * <p>
22: * This class is a base for both property and class assertion values.
23: *
24: * @author ledvima1
25: */
26: public class Value<T> {
27:
28: /**
29: * Represents a null value - empty value
30: */
31: public static final Value<Void> NULL_VALUE = new NullValue();
32:
33: private final T value;
34:
35: private Value() {
36: this.value = null;
37: }
38:
39: public Value(T value) {
40: Objects.requireNonNull(value);
41: this.value = value;
42: }
43:
44: /**
45: * Gets this value. </p>
46: *
47: * @return Value of the appropriate type
48: */
49: public T getValue() {
50: return value;
51: }
52:
53: /**
54: * Gets this value as string. </p>
55: *
56: * @return Value as string
57: */
58: public String stringValue() {
59: return value != null ? value.toString() : "";
60: }
61:
62: /**
63: * Returns a Null object for Value. </p>
64: * <p>
65: * Since Value requires a non-null value, this method returns a predefined object which represents a null (empty)
66: * value.
67: *
68: * @return Null value
69: * @see <a href="http://en.wikipedia.org/wiki/Null_Object_pattern">http://en.wikipedia.org/wiki/Null_Object_pattern</a>
70: */
71: public static Value<Void> nullValue() {
72: return NULL_VALUE;
73: }
74:
75: @Override
76: public int hashCode() {
77: final int prime = 31;
78: int result = 1;
79: result = prime * result + ((value == null) ? 0 : value.hashCode());
80: return result;
81: }
82:
83: @Override
84: public boolean equals(Object obj) {
85: if (this == obj)
86: return true;
87: if (obj == null)
88: return false;
89: if (getClass() != obj.getClass())
90: return false;
91: Value<?> other = (Value<?>) obj;
92: if (value == null) {
93: if (other.value != null)
94: return false;
95: } else if (!value.equals(other.value))
96: return false;
97: return true;
98: }
99:
100: @Override
101: public String toString() {
102: return value.toString();
103: }
104:
105: private static final class NullValue extends Value<Void> {
106:
107: private NullValue() {
108: super();
109: }
110:
111: @Override
112: public String stringValue() {
113: return "null";
114: }
115: }
116: }