Skip to contentMethod: LiteralNode(Object)
1: /*
2: * JB4JSON-LD
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jsonld.serialization.model;
19:
20: import java.util.Objects;
21:
22: public abstract class LiteralNode<T> extends JsonNode {
23:
24: final T value;
25:
26: public LiteralNode(T value) {
27: this.value = Objects.requireNonNull(value);
28: }
29:
30: public LiteralNode(String name, T value) {
31: super(name);
32: this.value = Objects.requireNonNull(value);
33: }
34:
35: public T getValue() {
36: return value;
37: }
38:
39: @Override
40: public String toString() {
41: return super.toString() + value + "}";
42: }
43:
44: @Override
45: public boolean equals(Object o) {
46: if (this == o) return true;
47: if (o == null || getClass() != o.getClass()) return false;
48:
49: LiteralNode<?> that = (LiteralNode<?>) o;
50:
51: return (getName() == null || getName().equals(that.getName())) &&
52: (getName() != null || that.getName() == null) && value.equals(that.value);
53:
54: }
55:
56: @Override
57: public int hashCode() {
58: int result = value.hashCode();
59: if (getName() != null) {
60: result = 31 * result + getName().hashCode();
61: }
62: return result;
63: }
64: }