universe@38: /* universe@38: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@38: * universe@38: * Copyright 2018 Mike Becker. All rights reserved. universe@38: * universe@38: * Redistribution and use in source and binary forms, with or without universe@38: * modification, are permitted provided that the following conditions are met: universe@38: * universe@38: * 1. Redistributions of source code must retain the above copyright universe@38: * notice, this list of conditions and the following disclaimer. universe@38: * universe@38: * 2. Redistributions in binary form must reproduce the above copyright universe@38: * notice, this list of conditions and the following disclaimer in the universe@38: * documentation and/or other materials provided with the distribution. universe@38: * universe@38: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@38: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@38: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@38: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@38: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@38: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@38: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@38: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@38: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@38: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@38: * POSSIBILITY OF SUCH DAMAGE. universe@38: * universe@38: */ universe@37: package de.uapcore.lightpit.entities; universe@37: universe@37: import java.util.Objects; universe@37: universe@62: public final class Version implements Comparable { universe@37: universe@37: private final int id; universe@75: private Project project; universe@37: private String name; universe@37: /** universe@37: * If we do not want versions to be ordered lexicographically we may specify an order. universe@37: */ universe@59: private int ordinal = 0; universe@59: private VersionStatus status = VersionStatus.Future; universe@37: universe@86: public Version(int id) { universe@37: this.id = id; universe@37: } universe@37: universe@37: public int getId() { universe@37: return id; universe@37: } universe@37: universe@75: public void setProject(Project project) { universe@75: this.project = project; universe@75: } universe@75: universe@59: public Project getProject() { universe@59: return project; universe@59: } universe@59: universe@37: public String getName() { universe@37: return name; universe@37: } universe@37: universe@37: public void setName(String name) { universe@37: this.name = name; universe@37: } universe@37: universe@37: public int getOrdinal() { universe@37: return ordinal; universe@37: } universe@37: universe@37: public void setOrdinal(int ordinal) { universe@37: this.ordinal = ordinal; universe@37: } universe@37: universe@37: public VersionStatus getStatus() { universe@37: return status; universe@37: } universe@37: universe@37: public void setStatus(VersionStatus status) { universe@37: this.status = status; universe@37: } universe@37: universe@37: @Override universe@37: public boolean equals(Object o) { universe@37: if (this == o) return true; universe@37: if (o == null || getClass() != o.getClass()) return false; universe@37: Version version = (Version) o; universe@37: return id == version.id; universe@37: } universe@37: universe@37: @Override universe@37: public int hashCode() { universe@37: return Objects.hash(id); universe@37: } universe@37: universe@37: @Override universe@37: public int compareTo(Version version) { universe@37: int ord = Integer.compare(this.ordinal, version.ordinal); universe@37: if (ord == 0) { universe@37: return this.name.compareToIgnoreCase(version.name); universe@37: } else { universe@37: return ord; universe@37: } universe@37: } universe@37: }