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