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 private double min = Double.MIN_VALUE;
17 private double max = Double.MAX_VALUE;
18 private Set<Double> enums;
21 void fillConstraints(final JsonNode type) {
22 JsonNode typeMaxNode = type.get("maxReal");
23 if (typeMaxNode != null) {
24 setMax(typeMaxNode.asLong());
26 JsonNode typeMinNode = type.get("minReal");
27 if (typeMinNode != null) {
28 setMin(typeMinNode.asLong());
30 Optional<Set<Double>> typeEnumsOpt = populateEnum(type);
31 if (typeEnumsOpt.isPresent()) {
32 setEnums(typeEnumsOpt.get());
37 public Object toValue(final JsonNode value) {
38 return value.asDouble();
42 public void validate(final Object value) {
46 private static Optional<Set<Double>> populateEnum(final JsonNode node) {
47 if (node.has("enum")) {
48 Set<Double> nodesEnums = new HashSet<>();
49 JsonNode anEnum = node.get("enum").get(1);
50 for (JsonNode enm : anEnum) {
51 nodesEnums.add(enm.asDouble());
53 return Optional.of(nodesEnums);
55 return Optional.empty();
59 public double getMin() {
63 public void setMin(final double min) {
67 public double getMax() {
71 public void setMax(final double max) {
75 public Set<Double> getEnums() {
79 public void setEnums(final Set<Double> enums) {
84 public String toString() {
85 return "RealBaseType";
89 public int hashCode() {
92 result = prime * result + (enums == null ? 0 : enums.hashCode());
94 temp = Double.doubleToLongBits(max);
95 result = prime * result + (int) (temp ^ temp >>> 32);
96 temp = Double.doubleToLongBits(min);
97 result = prime * result + (int) (temp ^ temp >>> 32);
102 public boolean equals(final Object obj) {
109 if (getClass() != obj.getClass()) {
112 RealBaseType other = (RealBaseType) obj;
114 if (other.enums != null) {
117 } else if (!enums.equals(other.enums)) {
120 if (Double.doubleToLongBits(max) != Double.doubleToLongBits(other.max)) {
123 if (Double.doubleToLongBits(min) != Double.doubleToLongBits(other.min)) {