2 * Copyright © 2014, 2017 EBay Software Foundation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.ovsdb.lib.schema;
10 import com.fasterxml.jackson.databind.JsonNode;
11 import java.util.HashSet;
12 import java.util.Optional;
15 final class RealBaseType extends BaseType<RealBaseType> {
16 static final RealBaseType SINGLETON = new RealBaseType();
18 private double min = Double.MIN_VALUE;
19 private double max = Double.MAX_VALUE;
20 private Set<Double> enums;
23 void fillConstraints(final JsonNode type) {
24 JsonNode typeMaxNode = type.get("maxReal");
25 if (typeMaxNode != null) {
26 max = typeMaxNode.asLong();
28 JsonNode typeMinNode = type.get("minReal");
29 if (typeMinNode != null) {
30 min = typeMinNode.asLong();
32 Optional<Set<Double>> typeEnumsOpt = populateEnum(type);
33 if (typeEnumsOpt.isPresent()) {
34 enums = typeEnumsOpt.get();
39 public Object toValue(final JsonNode value) {
40 return value.asDouble();
44 public void validate(final Object value) {
48 private static Optional<Set<Double>> populateEnum(final JsonNode node) {
49 if (node.has("enum")) {
50 Set<Double> nodesEnums = new HashSet<>();
51 JsonNode anEnum = node.get("enum").get(1);
52 for (JsonNode enm : anEnum) {
53 nodesEnums.add(enm.asDouble());
55 return Optional.of(nodesEnums);
57 return Optional.empty();
61 public double getMin() {
65 public double getMax() {
69 public Set<Double> getEnums() {
74 public String toString() {
75 return "RealBaseType";
79 public int hashCode() {
82 result = prime * result + (enums == null ? 0 : enums.hashCode());
84 temp = Double.doubleToLongBits(max);
85 result = prime * result + (int) (temp ^ temp >>> 32);
86 temp = Double.doubleToLongBits(min);
87 result = prime * result + (int) (temp ^ temp >>> 32);
92 public boolean equals(final Object obj) {
99 if (getClass() != obj.getClass()) {
102 RealBaseType other = (RealBaseType) obj;
104 if (other.enums != null) {
107 } else if (!enums.equals(other.enums)) {
110 if (Double.doubleToLongBits(max) != Double.doubleToLongBits(other.max)) {
113 if (Double.doubleToLongBits(min) != Double.doubleToLongBits(other.min)) {