001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 028 package org.opends.server.util; 029 030 /** 031 * Represents a particular version of OpenDS useful for making 032 * comparisons between versions. 033 */ 034 @org.opends.server.types.PublicAPI( 035 stability=org.opends.server.types.StabilityLevel.VOLATILE, 036 mayInstantiate=false, 037 mayExtend=false, 038 mayInvoke=true) 039 public final class BuildVersion implements Comparable<BuildVersion> { 040 041 /** Major release number. */ 042 int major; 043 044 /** Minor release number. */ 045 int minor; 046 047 /** Point release number. */ 048 int point; 049 050 /** Subversion revision number. */ 051 long rev; 052 053 /** 054 * Creates a new instance using current build data. 055 * 056 * @return BuildVersion representing current data 057 */ 058 static public BuildVersion getCurrent() { 059 return new BuildVersion( 060 DynamicConstants.MAJOR_VERSION, 061 DynamicConstants.MINOR_VERSION, 062 DynamicConstants.POINT_VERSION, 063 DynamicConstants.REVISION_NUMBER); 064 } 065 066 /** 067 * Constructs an instance from build data. 068 * @param major release number 069 * @param minor release number 070 * @param point release number 071 * @param rev Subversion revision number 072 */ 073 public BuildVersion(int major, int minor, int point, long rev) { 074 this.major = major; 075 this.minor = minor; 076 this.point = point; 077 this.rev = rev; 078 } 079 080 /** 081 * Gets the major release number. 082 * @return int major release number 083 */ 084 public int getMajorVersion() { 085 return major; 086 } 087 088 /** 089 * Gets the minor release number. 090 * @return int minor release number 091 */ 092 public int getMinorVersion() { 093 return minor; 094 } 095 096 /** 097 * Gets the point release number. 098 * @return int point release number 099 */ 100 public int getPointVersion() { 101 return point; 102 } 103 104 /** 105 * Gets the Subversion revision number. 106 * @return long Subversion revision number 107 */ 108 public long getRevisionNumber() { 109 return rev; 110 } 111 112 /** 113 * Retrieves an integer value that indicates the relative order between this 114 * build version and the provided build version object. 115 * 116 * @param version The build version object for which to make the 117 * determination. 118 * 119 * @return A negative integer if this build version should be ordered before 120 * the provided build version in a sorted list, a positive integer if 121 * this build version should be ordered after the provided build 122 * version in a sorted list, or zero if there is no difference in the 123 * relative order between the build version objects. 124 */ 125 public int compareTo(BuildVersion version) { 126 if (major == version.major) { 127 if (minor == version.minor) { 128 if (point == version.point) { 129 if (rev == version.rev) { 130 return 0; 131 } else if (rev < version.rev) { 132 return -1; 133 } 134 } else if (point < version.point) { 135 return -1; 136 } 137 } else if (minor < version.minor) { 138 return -1; 139 } 140 } else if (major < version.major) { 141 return -1; 142 } 143 return 1; 144 } 145 146 }