001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc;
019
020import java.util.ResourceBundle;
021import java.util.regex.Pattern;
022
023import net.sf.hajdbc.util.Strings;
024
025/**
026 * @author Paul Ferraro
027 */
028public class Version
029{
030        public static final Version CURRENT = new Version(ResourceBundle.getBundle(Version.class.getName()).getString("version"));
031        
032        private final String version;
033        private final int major;
034        private final int minor;
035        private final int revision;
036        
037        Version(String version)
038        {
039                this.version = version;
040                this.major = parse(0);
041                this.minor = parse(1);
042                this.revision = parse(2);
043        }
044        
045        private int parse(int index)
046        {
047                return Integer.parseInt(this.version.split(Pattern.quote(Strings.DASH))[0].split(Pattern.quote(Strings.DOT))[index]);
048        }
049        
050        public int getMajor()
051        {
052                return this.major;
053        }
054        
055        public int getMinor()
056        {
057                return this.minor;
058        }
059        
060        public int getRevision()
061        {
062                return this.revision;
063        }
064        
065        @Override
066        public String toString()
067        {
068                return this.version;
069        }
070}