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 IntegerBaseType extends BaseType<IntegerBaseType> {
16 static final IntegerBaseType SINGLETON = new IntegerBaseType();
18 private long min = Long.MIN_VALUE;
19 private long max = Long.MAX_VALUE;
20 private Set<Integer> enums;
23 void fillConstraints(final JsonNode type) {
24 JsonNode typeMaxNode = type.get("maxInteger");
25 if (typeMaxNode != null) {
26 max = typeMaxNode.asLong();
28 JsonNode typeMinNode = type.get("minInteger");
29 if (typeMinNode != null) {
30 min = typeMinNode.asLong();
32 Optional<Set<Integer>> typeEnumsOpt = populateEnum(type);
33 if (typeEnumsOpt.isPresent()) {
34 enums = typeEnumsOpt.get();
39 public Object toValue(final JsonNode value) {
40 return value.asLong();
44 public void validate(final Object value) {
48 private static Optional<Set<Integer>> populateEnum(final JsonNode node) {
49 if (node.has("enum")) {
50 Set<Integer> nodesEnums = new HashSet<>();
51 JsonNode anEnum = node.get("enum").get(1);
52 for (JsonNode enm : anEnum) {
53 nodesEnums.add(enm.asInt());
55 return Optional.of(nodesEnums);
57 return Optional.empty();
61 public long getMin() {
65 public long getMax() {
69 public Set<Integer> getEnums() {
74 public String toString() {
75 return "IntegerBaseType";
79 public int hashCode() {
82 result = prime * result + (enums == null ? 0 : enums.hashCode());
83 result = prime * result + (int) (max ^ max >>> 32);
84 result = prime * result + (int) (min ^ min >>> 32);
89 public boolean equals(final Object obj) {
96 if (getClass() != obj.getClass()) {
99 IntegerBaseType other = (IntegerBaseType) obj;
101 if (other.enums != null) {
104 } else if (!enums.equals(other.enums)) {
107 if (max != other.max) {
110 if (min != other.min) {