All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sitepark.versioning.version.AbstractVersion Maven / Gradle / Ivy

The newest version!
package com.sitepark.versioning.version;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import com.sitepark.versioning.Branch;

/**
 * A class containing the common fields of {@link ReleaseVersion},
 * {@link SnapshotVersion} and {@link ConcreteSnapshotVersion}.
 */
abstract class AbstractVersion implements Version, Serializable {
	private static final long serialVersionUID = 762173304150679702L;

	private final int major;
	private final int minor;
	private final int incremental;
	private final Branch branch;
	private final List qualifiers;

	AbstractVersion(final Version other) {
		this.major = other.getMajor();
		this.minor = other.getMinor();
		this.incremental = other.getIncremental();
		this.branch = other.getBranch();
		this.qualifiers = other.getQualifiers();
	}

	AbstractVersion(final VersionBuilder builder) {
		this.major = builder.getMajor();
		this.minor = builder.getMinor();
		this.incremental = builder.getIncremental();
		this.branch = builder.getBranch();
		this.qualifiers = List.copyOf(builder.getQualifiers());
	}

	@Override
	public int getMajor() {
		return this.major;
	}

	@Override
	public int getMinor() {
		return this.minor;
	}

	@Override
	public int getIncremental() {
		return this.incremental;
	}

	@Override
	public Branch getBranch() {
		return this.branch;
	}

	@Override
	public List getQualifiers() {
		return this.qualifiers;
	}

	/**
	 * Returns a String representation of this instance as formated by
	 * {@link VersionFormatter#DEFAULT_BASE_VERSION_FORMATTER}.
	 *
	 * @return a descriptive String of this instance
	 */
	@Override
	public String toString() {
		return VersionFormatter.DEFAULT_BASE_VERSION_FORMATTER.format(this);
	}

	@Override
	public int hashCode() {
		return Objects.hash(
				this.getMajor(),
				this.getMinor(),
				this.getIncremental(),
				this.getBranch(),
				this.getQualifiers());
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof AbstractVersion)) {
			return false;
		}
		final Version that = (AbstractVersion)other;
		return this.getMajor() == that.getMajor()
			&& this.getMinor() == that.getMinor()
			&& this.getIncremental() == that.getIncremental()
			&& this.getBranch().equals(that.getBranch())
			&& this.getQualifiers().size() == that.getQualifiers().size()
			&& this.getQualifiers().containsAll(that.getQualifiers());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy