1 /* 2 * Copyright (c) 2020 Network New Technologies Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.networknt.schema; 17 18 import java.util.Optional; 19 20 public class SpecVersion { 21 22 public enum VersionFlag { 23 24 V4(1 << 0, SchemaId.V4), 25 V6(1 << 1, SchemaId.V6), 26 V7(1 << 2, SchemaId.V7), 27 V201909(1 << 3, SchemaId.V201909), 28 V202012(1 << 4, SchemaId.V202012); 29 30 31 private final long versionFlagValue; 32 private final String id; 33 VersionFlag(long versionFlagValue, String id)34 VersionFlag(long versionFlagValue, String id) { 35 this.versionFlagValue = versionFlagValue; 36 this.id = id; 37 } 38 getId()39 public String getId() { 40 return this.id; 41 } 42 getVersionFlagValue()43 public long getVersionFlagValue() { 44 return this.versionFlagValue; 45 } 46 fromId(String id)47 public static Optional<VersionFlag> fromId(String id) { 48 for (VersionFlag v: VersionFlag.values()) { 49 if (v.id.equals(id)) return Optional.of(v); 50 } 51 return Optional.empty(); 52 } 53 } 54 55 } 56