Version : Algorithms « Collections Data Structure « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java » Collections Data Structure » AlgorithmsScreenshots 
Version
Version
        
/*
 * Version.java
 *
 *  Version object for maintaining an application version. Used for version checking over the internet.
 *
 *   @author Guy Wittig
 *   @version 18-Jun-2006
 *
 *   This program is part of MV-Plan
 *   Copywrite 2006 Guy Wittig
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   The GNU General Public License can be read at http://www.gnu.org/licenses/licenses.html
 */

//package mvplan.util;

import java.util.HashMap;

public class Version implements Comparable<Version> {

  private int majorVersion;
  private int minorVersion;
  private int patchVersion;
  private String statusString;
  private String dateString;
  private HashMap lookupTable;

  public static final int UNDEFINED = 0;
  public static final int TEST = 10;
  public static final int ALPHA = 20;
  public static final int BETA = 30;
  public static final int RELEASED = 100;

  /** Creates a new instance of Version */
  public Version() {
    this(000"UNDEFINED""");
  }

  public Version(int major, int minor, int patch, String status, String date) {
    // Create hashmap
    lookupTable = new HashMap();
    lookupTable.put("UNDEFINED"new Integer(0));
    lookupTable.put("TEST"new Integer(1));
    lookupTable.put("ALPHA"new Integer(2));
    lookupTable.put("BETA"new Integer(3));
    lookupTable.put("RELEASED"new Integer(4));
    // Initialise fields
    majorVersion = major;
    minorVersion = minor;
    patchVersion = patch;
    setStatus(status);
    dateString = date;
  }

  public String toString() {
    String s = majorVersion + "." + minorVersion;
    if (patchVersion > 0)
      s = s + "." + patchVersion;
    if (!statusString.equals("RELEASED"))
      s = s + " " + statusString;
    // if(dateString.length()>0) s=s+" "+dateString;
    return s;
  }

  // * Compares two status strings based on their status numbers in the
  // hashtable */
  private int compareStatus(String s1, String s2) {
    Integer n1 = (IntegerlookupTable.get(s1);
    Integer n2 = (IntegerlookupTable.get(s2);
    if (n1 == null || n2 == null)
      return -1;
    return n1 - n2;
  }

  public int compareTo(Version v) {
    if (v.getMajorVersion() == majorVersion)
      if (v.getMinorVersion() == minorVersion)
        if (compareStatus(v.getStatus(), statusString== 0)
          // if(v.getPatchVersion()==patchVersion)
          return v.getPatchVersion() - patchVersion;
        // return compareStatus(v.getStatus(),statusString);
        else
          return compareStatus(v.getStatus(), statusString);
      // else return v.getPatchVersion()-patchVersion;
      else
        return v.getMinorVersion() - minorVersion;
    else
      return v.getMajorVersion() - majorVersion;
  }

  public int getMajorVersion() {
    return majorVersion;
  }

  public void setMajorVersion(int majorVersion) {
    this.majorVersion = (majorVersion >= 0? majorVersion : 0;
  }

  public int getMinorVersion() {
    return minorVersion;
  }

  public void setMinorVersion(int minorVersion) {
    this.minorVersion = (minorVersion >= 0? minorVersion : 0;
  }

  public int getPatchVersion() {
    return patchVersion;
  }

  public void setPatchVersion(int patchVersion) {
    this.patchVersion = (patchVersion >= 0? patchVersion : 0;
  }

  public Object[] getLookupTable() {
    return lookupTable.keySet().toArray();
  }

  public String getStatus() {
    return statusString;
  }

  public void setStatus(String status) {
    if (lookupTable.get(status.toUpperCase()) != null)
      statusString = status.toUpperCase();
    else
      statusString = "UNKNOWN";
  }

  public String getDateString() {
    return dateString;
  }

  public void setDateString(String dateString) {
    this.dateString = dateString;
  }

}

   
    
    
    
    
    
    
    
  
Related examples in the same category
1.AnagramsAnagrams
2.Hanoi puzzleHanoi puzzle
3.FibonacciFibonacci
4.Sieve Sieve
5.Find connections using a depth-first searchFind connections using a depth-first search
6.Find connections using hill climbing.
7.Find optimal solution using least-cost
8.Find the lost keysFind the lost keys
9.Compute the area of a triangle using Heron's FormulaCompute the area of a triangle using Heron's Formula
10.Compute prime numbers
11.Print a table of fahrenheit and celsius temperatures 1
12.Print a table of fahrenheit and celsius temperatures 2
13.Print a table of Fahrenheit and Celsius temperatures 3Print a table of Fahrenheit and Celsius temperatures 3
14.Soundex - the Soundex Algorithm, as described by KnuthSoundex - the Soundex Algorithm, as described by Knuth
15.A programmable Finite State Machine implementation.
16.An extendable Graph datastructure.
17.Utilities for flop (floating-point operation) counting.
18.LU Decomposition
19.Reverse Polish Notation
20.Permutator test
21.implements the LZF lossless data compression algorithm
22.Linear Interpolation
23.Utility class for generating the k-subsets of the numbers 0 to n
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.