com.celum.dbtool.step.Version Maven / Gradle / Ivy
/*****************************************************************************
* Copyright 2012 celum Slovakia s r.o.
*
* 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.
*
*****************************************************************************/
package com.celum.dbtool.step;
/**
* Class holds version information, how version is compared etc.
* Because version information could be number, composition of numbers,
* string etc. and could be compared differently, the version is abstract class.
* You will implement this abstract class for your own version behaviour.
*
* The version is mostly parsed via {@link VersionFactory factory} implementation
* which is singletoned here and used in Version.of() method. For registering
* another factory impl. use the registerFactory() method.
*
* As default version and factory is used {@link LongVersionFactory long}
* representation.
*
* @author Zdenko Vrabel ([email protected])
*/
public abstract class Version implements Comparable{
/** NULL pattern */
public static final Version NULL = new Version() {
@Override
public int hashCode() {
return 0;
}
@Override
public int compareTo(Version o) {
return 0;
}
@Override
public String toString() {
return "0";
}
};
/** holds the singletoned version factory */
private static VersionFactory factory = VersionFactory.DEFAULT;
/**
* register a new version factory which will parse the version.
*/
public static void registerVersionFactory(VersionFactory factory) {
Version.factory = factory;
}
/**
* parse text and convert it to version object. Parsing depends on
* version factory which one is registered.
*/
public static Version of(String text)
{
return factory.parse(text);
}
/**
* Equals gives these some results like compareTo()
*/
@Override
public final boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Version version = (Version) o;
if (version.compareTo(this) == 0) return true;
return false;
}
/**
* you have to implement this method with compareTo() as well.
*/
public abstract int hashCode();
/**
* You have to implement this method because it's needed for
* automatic version update.
*
* @return string form of version
*/
public abstract String toString();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy