/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 *
 */
package org.jenetics.gradle;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.regex.Pattern.quote;


/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @since 1.4
 * @version 1.4 &mdash; <em>$Date: 2013-08-28 $</em>
 */
public final class Version implements Comparable<Version> {

	private final int _major;
	private final int _minor;
	private final int _micro;

	public Version(final int major, final int minor, final int micro) {
		// Check the version numbers.
		if ( major < 0 || minor < 0 || micro < 0 ) {
			throw new IllegalArgumentException(format(
				"Invalid range of the version numbers (%d, %d, %d)",
				major, minor, micro
			));
		}

		_major = major;
		_minor = minor;
		_micro = micro;
	}

	public Version(final int major, final int minor) {
		this(major, minor, 0);
	}

	public Version(final int major) {
		this(major, 0, 0);
	}

	public int getMajor() {
		return _major;
	}

	public int getMinor() {
		return _minor;
	}

	public int getMicro() {
		return _micro;
	}

	@Override
	public int compareTo(final Version version) {
		int comp = 0;

		if (_major > version._major) {
			comp = 1;
		} else if (_major < version._major) {
			comp = -1;
		}
		if (comp == 0) {
			if (_minor > version._minor) {
				comp = 1;
			} else if (_minor < version._minor) {
				comp = -1;
			}
		}
		if (comp == 0) {
			if (_micro > version._micro) {
				comp = 1;
			} else if (_micro < version._micro) {
				comp = -1;
			}
		}

		return comp;
	}

	@Override
	public int hashCode() {
		int hash = getClass().hashCode();
		hash = 31*hash + _major;
		hash = 31*hash + _minor;
		hash = 31*hash + _micro;
		return hash;
	}

	@Override
	public boolean equals(final Object obj) {
		if (obj == this) {
			return true;
		}
		if (!(obj instanceof Version)) {
			return false;
		}

		final Version version = (Version)obj;
		return _major == version._major &&
				_minor == version._minor &&
				_micro == version._micro;
	}

	@Override
	public String toString() {
		return format("%d.%d.%d", _major, _minor, _micro);
	}

	public static Version parse(final String versionString) {
		requireNonNull(versionString, "Version string must not be null.");
		final String[] parts = versionString.split(quote("."));

		Version version = null;
		try {
			if (parts.length == 1) {
				version = new Version(Integer.parseInt(parts[0]));
			} else if (parts.length == 2) {
				version = new Version(
					Integer.parseInt(parts[0]),
					Integer.parseInt(parts[1])
				);
			} else if (parts.length == 3) {
				version = new Version(
					Integer.parseInt(parts[0]),
					Integer.parseInt(parts[1]),
					Integer.parseInt(parts[2])
				);
			} else {
				throw new IllegalArgumentException(format(
					"'%s' is not a valid version string.", versionString
				));
			}
		} catch (NumberFormatException e) {
			throw new IllegalArgumentException(format(
				"'%s' is not a valid version string.", versionString
			));
		}

		return version;
	}

}





@@ -1087,16 +1087,51 @@
 ;%0A%0A%0A/**%0A
+ * Represent a library version.%0A *%0A
  * @auth
@@ -1262,17 +1262,17 @@
 013-08-2
-8
+9
  $%3C/em%3E%0A

Add javadoc.