001/** 002 * Java Web Archive Toolkit - Software to read and validate ARC, WARC 003 * and GZip files. (http://jwat.org/) 004 * Copyright 2011-2012 Netarkivet.dk (http://netarkivet.dk/) 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.jwat.arc; 019 020/** 021 * Supported ARC file versions. 022 * 023 * @author lbihanic,selghissassi 024 */ 025public enum ArcVersion { 026 027 /** Version 1.0 enum. */ 028 VERSION_1(1, 0, "version-1-block", "URL-record-v1"), 029 /** Version 1.1 enum. */ 030 VERSION_1_1(1, 1, "version-1-block", "URL-record-v1"), 031 /** Version 2.0 enum. */ 032 VERSION_2(2, 0, "version-2-block", "URL-record-v2"); 033 034 /** Major version number. */ 035 public final int major; 036 037 /** Minor version number. */ 038 public final int minor; 039 040 /** Version block field type. */ 041 public final String versionBlockType; 042 043 /** Arc record field type. */ 044 public final String arcRecordType; 045 046 /** 047 * Enum constructor based on version specific parameters. 048 * @param major major version number 049 * @param minor minor version number 050 * @param vBType version block field type 051 * @param aRType arc record field type 052 */ 053 private ArcVersion(int major, int minor, String vBType, String aRType){ 054 this.major = major; 055 this.minor = minor; 056 this.versionBlockType = vBType; 057 this.arcRecordType = aRType; 058 } 059 060 /** 061 * Given a version number return the corresponding <code>ArcVersion</code> 062 * object or null. 063 * @param major major version number 064 * @param minor minor version number 065 * @return <code>ArcVersion</code> object or null. 066 */ 067 public static ArcVersion fromValues(int major, int minor) { 068 ArcVersion version = null; 069 for (ArcVersion v : ArcVersion.values()) { 070 if ((v.major == major) && (v.minor == minor)) { 071 version = v; 072 break; 073 } 074 } 075 return version; 076 } 077 078 @Override 079 public String toString() { 080 return "v" + this.major + '.' + this.minor; 081 } 082 083}