Main Page | Class List | File List | Class Members | Related Pages

DoxygenVersion.java

00001 // -*- Mode: Java; indent-tabs-mode: nil; c-basic-offset: 4; -*-
00002 /*
00003  * The Apache Software License, Version 1.1
00004  *
00005  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution, if
00021  *    any, must include the following acknowlegement:
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowlegement may appear in the software itself,
00025  *    if and wherever such third-party acknowlegements normally appear.
00026  *
00027  * 4. The names "The Jakarta Project", "Ant", and "Apache Software
00028  *    Foundation" must not be used to endorse or promote products derived
00029  *    from this software without prior written permission. For written
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache"
00033  *    nor may "Apache" appear in their names without prior written
00034  *    permission of the Apache Group.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation.  For more
00052  * information on the Apache Software Foundation, please see
00053  * <http://www.apache.org/>.
00054  */
00055  // $Header: /cvsroot/ant-doxygen/ant_task/src/org/doxygen/tools/DoxygenVersion.java,v 1.2.4.5 2004/01/30 23:15:49 akkumar Exp $
00056 package org.doxygen.tools;
00057 
00058 import java.util.StringTokenizer;
00059 
00060 
00061 
00062 
00071 public class DoxygenVersion implements Comparable {
00072 
00074     private int[] versions;
00075 
00077     private static final int DEFAULT_MAGNITUDE = 3;
00078 
00083     private boolean upwards = false;
00084 
00085     //----------------------------------------------------------------------
00098     public DoxygenVersion(String releaseMajorMinor,
00099                           final int orderOfMagnitude) 
00100                           throws NumberFormatException {
00101         if (releaseMajorMinor.endsWith("+")) {
00102             upwards = true;
00103             int len = releaseMajorMinor.length();
00104             releaseMajorMinor = releaseMajorMinor.substring(0, len -1);
00105         }                            
00106         StringTokenizer st =
00107                     new StringTokenizer(releaseMajorMinor, ".");
00108 
00109         versions = new int[orderOfMagnitude];
00110 
00111         for (int i = 0; (i < orderOfMagnitude); i++) {
00112             versions[i] =
00113                 Integer.parseInt((String) st.nextToken());
00114         }
00115     }
00116 
00117 
00118 
00119 
00120 
00121     //----------------------------------------------------------------------
00130     public DoxygenVersion(final String releaseMajorMinor) {
00131         this(releaseMajorMinor, DEFAULT_MAGNITUDE);
00132     }
00133 
00134 
00135 
00136 
00137     //----------------------------------------------------------------------
00152     public final int compareTo(final Object obj) {
00153         if (obj instanceof DoxygenVersion) {
00154             DoxygenVersion dv = (DoxygenVersion) obj;
00155 
00156             for (int i = 0; (i < versions.length); i++) {
00157                 if (this.versions[i] > dv.versions[i]) {
00158                     return 1;
00159                 } else if (this.versions[i] == dv.versions[i]) {
00160                     continue;
00161                 } else {
00162                     return -1;
00163                 }
00164             }
00165             return 0; //Equal
00166         } else {
00167             return -1;
00168         }
00169     }
00170 
00171 
00172     //-------------------------------------------
00179     public boolean isCompatible(String version) {
00180         DoxygenVersion compatVersion = new DoxygenVersion(version);
00181         if (compatVersion.upwards) {
00182             return (this.compareTo(compatVersion) >= 0);
00183         } else {
00184             return (this.compareTo(compatVersion) == 0);
00185         }
00186     }
00187     
00188 
00189     //----------------------------------------------------------------------
00196     public final String toString() {
00197         StringBuffer sb = new StringBuffer();
00198         for (int i = 0; (i < versions.length); i++) {
00199             sb.append(versions[i] + ".");
00200         }
00201         return sb.toString();
00202     }
00203 }

Generated on Sat Jan 31 02:17:29 2004 for Ant-Doxygen by doxygen 1.3.4