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

org.ow2.bonita.runtime.PackageVersion Maven / Gradle / Ivy

/**
 * Copyright (C) 2006  Bull S. A. S.
 * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
 * 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
 * version 2.1 of the License.
 * 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
 * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA  02110-1301, USA.
 **/
package org.ow2.bonita.runtime;

import java.util.Stack;


public class PackageVersion {

  private String packageId;
  private String packageVersion;
  private Stack previousVersions;

  @SuppressWarnings("unused")
  private PackageVersion() { }
  
  public PackageVersion(String packageId, String packageVersion) {
    super();
    this.packageId = packageId;
    this.packageVersion = packageVersion;
  }

  public String getPackageId() {
    return packageId;
  }

  public String getPackageVersion() {
    return packageVersion;
  }

  public void setPackageVersion(String version) {
    if (previousVersions == null)  {
      previousVersions = new Stack();
    }
    if (this.packageVersion != null) {
      previousVersions.add(this.packageVersion);
    }
    this.packageVersion = version;
  }
  
//returns false if no version exists anymore
  public boolean removeVersion(String version) {
    //2 cases
    //1) the given version is the last one
    //2) the given version is a previous one
    if (this.packageVersion != null && this.packageVersion.equals(version)) {
      this.packageVersion = null;
      if (previousVersions != null && !previousVersions.isEmpty()) {
        this.packageVersion = previousVersions.pop();
      }  
    } else if (this.previousVersions != null) {
      this.previousVersions.remove(version);
    }
    
    return packageVersion == null && (previousVersions == null || previousVersions.isEmpty()); 
  }
}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy