From c647362ad3a615d515f4bc7d24a0884d74471fef Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 21 Mar 2011 07:10:44 +0100 Subject: VersionNumber: Add cstr with version number string and delimeter --- src/java/com/jogamp/common/util/VersionNumber.java | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/java/com/jogamp/common/util/VersionNumber.java b/src/java/com/jogamp/common/util/VersionNumber.java index 7e86e72..57c83da 100644 --- a/src/java/com/jogamp/common/util/VersionNumber.java +++ b/src/java/com/jogamp/common/util/VersionNumber.java @@ -28,6 +28,8 @@ package com.jogamp.common.util; +import java.util.StringTokenizer; + public class VersionNumber implements Comparable { protected int major; @@ -40,6 +42,33 @@ public class VersionNumber implements Comparable { sub = subMinorRev; } + /** + * @param versionString should be given as [MAJOR[.MINOR[.SUB]]] + * @param delim the delimiter, e.g. "." + */ + public VersionNumber(String versionString, String delim) { + try { + StringTokenizer tok = new StringTokenizer(versionString, delim); + if (!tok.hasMoreTokens()) { + major = 0; + return; + } + major = Integer.valueOf(tok.nextToken()).intValue(); + if (!tok.hasMoreTokens()) { + minor = 0; + return; + } + minor = Integer.valueOf(tok.nextToken()).intValue(); + if (!tok.hasMoreTokens()) { + sub = 0; + return; + } + sub = Integer.valueOf(tok.nextToken()).intValue(); + } catch (Exception e) { + throw new IllegalArgumentException("version <"+versionString+">, delim <"+delim+">", e); + } + } + protected VersionNumber() { } @Override -- cgit v1.2.3