GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — utPLSQL-java-api/src/main/java/org/utplsql/api/Version.java at v3.1.1 · utPLSQL/utPLSQL-java-api Expand file tree/ Copy pathVersion.javaMore file actions 188 lines (149 loc) · 4.88 KB / Copy pathVersion.javaFile metadata and controls188 lines (149 loc) · 4.88 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 package org.utplsql.api; import org.utplsql.api.exception.InvalidVersionException; import java.util.regex.Matcher; import java.util.regex.Pattern; /** Simple class to parse utPLSQL Version-information and provide the separate version-numbers * * @author pesse */ public class Version implements Comparable<Version> { private final String origString; private final Integer major; private final Integer minor; private final Integer bugfix; private final Integer build; private final boolean valid; public Version( String versionString ) { assert versionString != null; this.origString = versionString.trim(); Pattern p = Pattern.compile("([0-9]+)\\.?([0-9]+)?\\.?([0-9]+)?\\.?([0-9]+)?"); Matcher m = p.matcher(origString); Integer major = null; Integer minor = null; Integer bugfix = null; Integer build = null; boolean valid = false; try { if (m.find()) { if (m.group(1) != null ) major = Integer.valueOf(m.group(1)); if (m.group(2) != null ) minor = Integer.valueOf(m.group(2)); if (m.group(3) != null ) bugfix = Integer.valueOf(m.group(3)); if (m.group(4) != null ) build = Integer.valueOf(m.group(4)); // We need a valid major version as minimum requirement for a Version object to be valid valid = major != null; } } catch ( NumberFormatException e ) { valid = false; } this.major = major; this.minor = minor; this.bugfix = bugfix; this.build = build; this.valid = valid; } @Override public String toString() { return origString; } public Integer getMajor() { return major; } public Integer getMinor() { return minor; } public Integer getBugfix() { return bugfix; } public Integer getBuild() { return build; } public boolean isValid() { return valid; } /** Returns a normalized form of the parsed version information * * @return */ public String getNormalizedString() { if ( isValid() ) { StringBuilder sb = new StringBuilder(); sb.append(String.valueOf(major)); if ( minor != null ) sb.append(".").append(String.valueOf(minor)); if ( bugfix != null ) sb.append(".").append(String.valueOf(bugfix)); if ( build != null ) sb.append(".").append(String.valueOf(build)); return sb.toString(); } else return "invalid"; } private int compareToWithNulls( Integer i1, Integer i2 ) { if ( i1 == null && i2 == null ) return 0; else if ( i1 == null ) return -1; else if ( i2 == null ) return 1; else return i1.compareTo(i2); } @Override public int compareTo(Version o) { int curResult; if ( isValid() && o.isValid() ) { curResult = compareToWithNulls(getMajor(), o.getMajor()); if ( curResult != 0 ) return curResult; curResult = compareToWithNulls(getMinor(), o.getMinor()); if ( curResult != 0 ) return curResult; curResult = compareToWithNulls(getBugfix(), o.getBugfix()); if ( curResult != 0 ) return curResult; curResult = compareToWithNulls(getBuild(), o.getBuild()); if ( curResult != 0 ) return curResult; } return 0; } private void versionsAreValid( Version v ) throws InvalidVersionException { if ( !isValid() ) throw new InvalidVersionException(this); if ( !v.isValid() ) throw new InvalidVersionException(v); } /** Compares this version to a given version and returns true if this version is greater or equal than the given one * Throws an InvalidVersionException if either this or the given version are invalid * * @param v Version to compare with * @return * @throws InvalidVersionException */ public boolean isGreaterOrEqualThan( Version v ) throws InvalidVersionException { versionsAreValid(v); return compareTo(v) >= 0; } public boolean isGreaterThan( Version v) throws InvalidVersionException { versionsAreValid(v); return compareTo(v) > 0; } public boolean isLessOrEqualThan( Version v ) throws InvalidVersionException { versionsAreValid(v); return compareTo(v) <= 0; } public boolean isLessThan( Version v) throws InvalidVersionException { versionsAreValid(v); return compareTo(v) < 0; } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |