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

io.knowledgelinks.cicd.semantic.versioning.versions.VersionInfo Maven / Gradle / Ivy

package io.knowledgelinks.cicd.semantic.versioning.versions;

/*-
 * #%L
 * Semantic Versioning
 * %%
 * Copyright (C) 2022 - 2023 Knowledgelinks
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.Comparator;
import io.knowledgelinks.cicd.semantic.versioning.enums.BranchTypes;
import io.knowledgelinks.cicd.semantic.versioning.enums.VersionTypes;

/**
 * A DTO object for storing a version information
 * 
 * @author mstabile75
 *
 */
public class VersionInfo implements Comparable {
  String branchName;

  BranchTypes branchType = BranchTypes.NONE;

  VersionTypes versionType = VersionTypes.NONE;

  int major = -1;

  int minor = -1;

  int patch = -1;

  int buildNumber = -1;

  public VersionInfo() {}

  public VersionInfo(VersionInfo versionInfo) {
    branchName = versionInfo.getBranchName();
    branchType = versionInfo.getBranchType();
    versionType = versionInfo.getVersionType();
    major = versionInfo.getMajor();
    minor = versionInfo.getMinor();
    patch = versionInfo.getPatch();
    buildNumber = versionInfo.getBuildNumber();
  }


  @Override
  public int compareTo(VersionInfo versionInfo) {
    return Comparator.comparing(VersionInfo::getMajor).thenComparing(VersionInfo::getMinor)
        .thenComparing(VersionInfo::getPatch).thenComparing(VersionInfo::getVersionType)
        .thenComparing(VersionInfo::getBranchType)
        .thenComparing(VersionInfo::getBranchName, Comparator.nullsLast(Comparator.naturalOrder()))
        .thenComparing(VersionInfo::getBuildNumber).compare(this, versionInfo);

  }


  public String getBranchName() {
    return branchName;
  }

  public void setBranchName(String branchName) {
    // convert empty string branchNames to null
    this.branchName = (branchName != null && !branchName.isBlank()) ? branchName : null;
  }

  public BranchTypes getBranchType() {
    return branchType;
  }

  public void setBranchType(BranchTypes branchType) {
    this.branchType = (branchType == null) ? BranchTypes.NONE : branchType;
  }


  public VersionTypes getVersionType() {
    return versionType;
  }

  public void setVersionType(VersionTypes versionType) {
    this.versionType = (versionType == null) ? VersionTypes.NONE : versionType;
  }

  public int getMajor() {
    return major;
  }

  public void setMajor(int major) {
    this.major = major;
  }

  public int getMinor() {
    return minor;
  }

  public void setMinor(int minor) {
    this.minor = minor;
  }

  public int getPatch() {
    return patch;
  }

  public void setPatch(int patch) {
    this.patch = patch;
  }

  public int getBuildNumber() {
    return buildNumber;
  }

  public void setBuildNumber(int buildNumber) {
    this.buildNumber = buildNumber;
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy