krysalis-version/src/java/org/krysalis/version/impl VersionFormatImpl.java,NONE,1.1 VersionSpecificationImpl.java,NONE,1.1 CompoundVersion.java,NONE,1.1 VersionImplementationConstants.java,NONE,1.1
Nick Chalko <[email protected]> Tue, 09 Nov 2004 06:40:32 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/impl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20857/src/java/org/krysalis/version/impl
Added Files:
VersionFormatImpl.java VersionSpecificationImpl.java
CompoundVersion.java VersionImplementationConstants.java
Log Message:
Mucho Refactoring.
--- NEW FILE: VersionSpecificationImpl.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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 org.krysalis.version.impl;
import java.io.PrintWriter;
import org.krysalis.version.VersionSpecification;
/**
*
* @author ajack
*/
public abstract class VersionSpecificationImpl
implements VersionSpecification {
public String getName() {
return org.krysalis.version.util.SystemUtils.getShortName(getClass());
}
public String toString() {
return getName() + ":" + getVersionFormat();
}
public void dump(PrintWriter out, int depth, boolean verbose) {
final String indent =" ";
out.print(indent);
out.println("Specification Name:" + getName());
out.print(indent);
out.println("Specification Id:" + getId());
out.print(indent);
out.println("Description:" + getDescription());
out.print(indent);
out.println("Mask:" + getElementMask());
out.print(indent);
out.println("Format:" + getVersionFormat());
}
public boolean equals(Object other) {
boolean equal = false;
if (other instanceof VersionSpecification) {
VersionSpecification otherSpecification = (VersionSpecification) other;
equal = getId().equals(otherSpecification.getId());
}
return equal;
}
public int hashCode() {
return getId().hashCode();
}
}
--- NEW FILE: VersionFormatImpl.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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 org.krysalis.version.impl;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.Date;
import org.apache.depot.version.impl.data.ReleaseLevel;
import org.apache.depot.version.impl.data.VersionData;
import org.apache.depot.version.impl.data.VersionDataElement;
import org.krysalis.version.VersionException;
import org.krysalis.version.VersionFormat;
import org.krysalis.version.VersionFormatException;
import org.krysalis.version.util.SystemUtils;
/**
*
* @author ajack
*/
public abstract class VersionFormatImpl implements VersionFormat {
public String getName() {
return SystemUtils.getShortName(getClass());
}
public String toString() {
// :TODO: return getName() + ":" + getVersionFormatMask();
return getName();
}
public int parseInt(String input, VersionDataElement element, String data)
throws VersionFormatException {
int value = -1;
try {
value = Integer.parseInt(data, 10);
} catch (NumberFormatException nfe) {
throw new VersionFormatException(this, "Bad Version Value [" + data
+ "] in [" + input + "] for [" + element + "]", nfe);
}
return value;
}
public ReleaseLevel parseReleaseLevel(String input, String data)
throws VersionFormatException {
ReleaseLevel releaseLevel = ReleaseLevel.UNSET;
try {
releaseLevel = ReleaseLevel.getFromString(data);
} catch (VersionException ve) {
throw new VersionFormatException(this, "Bad Release Level Value ["
+ data + "] in [" + input + "] for ["
+ VersionDataElement.RELEASE_LEVEL + "]", ve);
}
return releaseLevel;
}
public Date parseDate(String data) throws VersionFormatException {
Date value = null;
int len = data.length();
if ((len != VersionImplementationConstants.DATE_FORMAT_LEN)
&& (len != VersionImplementationConstants.DATETIME_FORMAT_LEN)
&& (len != VersionImplementationConstants.DATETIME_LONG_FORMAT_LEN))
throw new VersionFormatException(this, "Not a Datetime format ["
+ data + "] in [" + data + "] for ["
+ VersionDataElement.ELEMENT_BUILD_DATE + "]");
try {
if (len == VersionImplementationConstants.DATE_FORMAT_LEN)
value = VersionImplementationConstants.DATE_FORMAT.parse(data);
else if (len == VersionImplementationConstants.DATETIME_FORMAT_LEN)
value = VersionImplementationConstants.DATETIME_FORMAT.parse(data);
else if (len == VersionImplementationConstants.DATETIME_LONG_FORMAT_LEN)
value = VersionImplementationConstants.DATETIME_LONG_FORMAT.parse(data);
} catch (ParseException pe) {
throw new VersionFormatException(this, "Bad Datetime Value ["
+ data + "] in [" + data + "] for ["
+ VersionDataElement.ELEMENT_BUILD_DATE + "]", pe);
}
return value;
}
/**
* Finds the first digit character
*
* @param data
* @return The position of the digit, or -1
*/
public int findNextNumeric(String data) {
return findNextNumeric(data, 0);
}
/**
* Finds the first digit character, after start
*
* @param data
* @return The position of the digit, or -1
*/
public int findNextNumeric(String data, int start) {
int digitPosn = -1;
for (int i = start; (i < data.length()) && (-1 == digitPosn); ++i) {
char c = data.charAt(i);
if (Character.isDigit(c)) {
digitPosn = i;
}
}
return digitPosn;
}
/**
* Assumes that the start of data is a numeric, and finds first non-numeric
* (e.g. a dash or a letter or something) after that.
*
* @param data
* @return The position of the non-numeric character, or -1
*/
public int findEndOfNumericalArea(String data) {
return findEndOfNumericalArea(data, 0);
}
/**
* Assumes that @ start in data is a numeric, and finds first non-numeric
* (e.g. a dash or a letter or something) after that.
* @param data
* @return The position of the non-numeric character, or -1
*/
public int findEndOfNumericalArea(String data, int start) {
int nonNumericPos = -1;
for (int i = start; (i < data.length()) && (-1 == nonNumericPos); ++i) {
char ch = data.charAt(i);
if (!Character.isDigit(ch))
nonNumericPos = i;
}
return nonNumericPos;
}
public void dump(PrintWriter out, int depth, boolean verbose) {
final String indent = " ";
out.print(indent);
out.println("Format Name:" + getName());
if (verbose) {
out.print(indent);
out.println("Format Id:" + getFormatId());
//out.print(indent);
//out.println("Format Mask:" + getVersionFormatMask());
out.print(indent);
out.println("Description:" + getVersionFormatDescription());
//:TODO: More?
}
}
/**
* @return
*/
private String getVersionFormatDescription() {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
*
* @see org.apache.version.specification.formatting.VersionFormat#format(org.apache.version.impl.data.VersionData,
* java.lang.String)
*/
public String format(VersionData data, String styleName) {
// TODO
return data.toString();
}
}
--- NEW FILE: VersionImplementationConstants.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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 org.krysalis.version.impl;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
* @author ajack
*/
public class VersionImplementationConstants {
public static final String VERSION_FORMAT_FIELD = "VERSION_FORMAT";
public static final String VERSION_VERSION_FIELD = "VERSION_VERSION";
public static final String VERSION_FIELD = "VERSION";
// The version of the Apache Version Format
public static final String VERSION_FORMAT_VERSION = "1.0.0-alpha";
public static final String APACHE_PACKAGE = "org.apache";
public static final String VERSION_PACKAGE = APACHE_PACKAGE + ".depot.version";
// The Apache Format
public static final String APACHE_VERSION_FORMAT = VERSION_PACKAGE;
// The Default Version Format
public static final String VERSION_FORMAT = APACHE_VERSION_FORMAT;
// The location for finding Krysilis Version
public static final String VERSION_URL =
"http://www.apache.org/version/";
public static final String APACHE_VERSION_ID = VERSION_PACKAGE;
public static final String DATETIMESTAMPED_VERSION_ID = "org.apache.datetimestamped";
public static final String ECLIPSE_VERSION_ID = "org.eclipse";
public static final String JAVASOFT_VERSION_ID = "java";
public static final String JAKARTA_COMMONS_VERSION_ID =
"org.apache.jakarta.commons";
public final static String DATE_FORMAT_STRING = "yyyyMMdd";
public final static String DATETIME_FORMAT_STRING = "yyyyMMddhhmm";
public final static String DATETIME_LONG_FORMAT_STRING = "yyyyMMddhhmmss";
public final static int DATE_FORMAT_LEN = DATE_FORMAT_STRING.length();
public final static int DATETIME_FORMAT_LEN = DATETIME_FORMAT_STRING.length();
public final static int DATETIME_LONG_FORMAT_LEN = DATETIME_LONG_FORMAT_STRING.length();
public final static DateFormat DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT_STRING);
public final static DateFormat DATETIME_FORMAT = new SimpleDateFormat(DATETIME_FORMAT_STRING);
public final static DateFormat DATETIME_LONG_FORMAT = new SimpleDateFormat(DATETIME_LONG_FORMAT_STRING);
public final static DateFormat DEFAULT_DATETIME_FORMAT = new SimpleDateFormat();
}
--- NEW FILE: CompoundVersion.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* 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 org.krysalis.version.impl;
import java.util.Date;
/**
* @author $Author: chalko $
* @version $Revision: 1.1 $
*/
public interface CompoundVersion extends org.krysalis.version.Version {
int getMajor();
int getMinor();
int getPoint();
String getReleaseLevel();
int getReleaseQualifier();
int getBuildNumber();
Date getBuildDate();
}
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click