diff options
| author | Joshua Rahm <joshua.rahm@colorado.edu> | 2015-01-30 17:11:48 -0700 |
|---|---|---|
| committer | Joshua Rahm <joshua.rahm@colorado.edu> | 2015-01-30 17:11:48 -0700 |
| commit | 1c5e38fe69ac8a6decbdd8abe93112f4e3369315 (patch) | |
| tree | 926cef8cb76d46862ed2c4ec7028720611e47476 /src/utilities | |
| download | Modulus3D-1c5e38fe69ac8a6decbdd8abe93112f4e3369315.tar.gz Modulus3D-1c5e38fe69ac8a6decbdd8abe93112f4e3369315.tar.bz2 Modulus3D-1c5e38fe69ac8a6decbdd8abe93112f4e3369315.zip | |
added source
Diffstat (limited to 'src/utilities')
| -rw-r--r-- | src/utilities/BaseConverter.java | 72 | ||||
| -rw-r--r-- | src/utilities/DecimalFormatter.java | 109 | ||||
| -rw-r--r-- | src/utilities/EFormatter.java | 26 | ||||
| -rw-r--r-- | src/utilities/NoFormatter.java | 17 | ||||
| -rw-r--r-- | src/utilities/PublicFileClassLoader.java | 44 | ||||
| -rw-r--r-- | src/utilities/ScientificFormatter.java | 26 |
6 files changed, 294 insertions, 0 deletions
diff --git a/src/utilities/BaseConverter.java b/src/utilities/BaseConverter.java new file mode 100644 index 0000000..c4fb116 --- /dev/null +++ b/src/utilities/BaseConverter.java @@ -0,0 +1,72 @@ +/* */ package utilities; +/* */ +/* */ public class BaseConverter +/* */ { +/* */ public static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +/* */ +/* */ public static double convertToDecimal(String original, int base) +/* */ { +/* 12 */ int neg = 1; +/* 13 */ if (original.startsWith("-")) { +/* 14 */ original = original.substring(1); +/* 15 */ neg = -1; +/* */ } +/* 17 */ if (original.contains(".")) return neg * convertToDecimal(original, base, original.indexOf(".") - 1); +/* 18 */ return neg * convertToDecimal(original, base, original.length() - 1); +/* */ } +/* */ private static double convertToDecimal(String original, int base, int length) { +/* 21 */ if (base == 10) return Double.parseDouble(original); +/* 22 */ if (base == 1) return original.length(); +/* 23 */ if (original.length() == 0) return 0.0D; +/* 24 */ if (original.charAt(0) == '.') return convertToDecimal(original.substring(1), base, length); +/* 25 */ return Math.pow(base, length) * "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(original.charAt(0)) + convertToDecimal(original.substring(1), base, length - 1); +/* */ } +/* */ public static String convertFromDecimal(double original, int base) { +/* 28 */ if (original < 0.0D) return "-" + convertFromDecimal(-1.0D * original, base); +/* 29 */ if ((original < 1.0D) && (original > 0.0D)) return "0" + convertFromDecimal(1.0D + original, base).substring(1); +/* 30 */ if (base == 10) return original; +/* 31 */ if (base == 1) { +/* 32 */ String ret = ""; +/* 33 */ for (int i = 0; i < original; i++) ret = ret + "0"; +/* 34 */ return ret; +/* */ } +/* 36 */ double pwr = nearestLog(()original, base); +/* 37 */ String ret = ""; +/* 38 */ boolean lessThan = false; +/* 39 */ while ((original > 1.E-09D) || (pwr >= 1.0D)) { +/* 40 */ if ((!lessThan) && (pwr < 1.0D)) { +/* 41 */ ret = ret + "."; +/* 42 */ lessThan = true; +/* */ } +/* 44 */ if (original >= pwr) { +/* 45 */ ret = ret + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt((int)(original / pwr)); +/* 46 */ original %= pwr; +/* */ } +/* */ else { +/* 49 */ ret = ret + 0; +/* */ } +/* 51 */ pwr /= base; +/* */ } +/* 53 */ return ret; +/* */ } +/* */ public static String convertFromDecimal(long original, int base, long start, int digits) { +/* 56 */ if (original < base) { +/* 57 */ String ret = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt((int)original); +/* 58 */ while (digits != 0) { +/* 59 */ ret = ret + 0; +/* 60 */ digits--; +/* */ } +/* 62 */ return ret; +/* */ } +/* */ +/* 65 */ return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt((int)(original / start)) + convertFromDecimal(original % start, base, start / base, digits - 1); +/* */ } +/* */ public static long nearestLog(long start, int base) { +/* 68 */ return ()Math.pow(base, (int)(Math.log(start) / Math.log(base))); +/* */ } +/* */ } + +/* Location: Modulus.jar + * Qualified Name: utilities.BaseConverter + * JD-Core Version: 0.6.2 + */
\ No newline at end of file diff --git a/src/utilities/DecimalFormatter.java b/src/utilities/DecimalFormatter.java new file mode 100644 index 0000000..a6b084e --- /dev/null +++ b/src/utilities/DecimalFormatter.java @@ -0,0 +1,109 @@ +/* */ package utilities; +/* */ +/* */ import java.math.BigDecimal; +/* */ import java.math.MathContext; +/* */ +/* */ public abstract class DecimalFormatter +/* */ { +/* */ private int sigFigs; +/* */ private String sigstr; +/* */ private boolean flt; +/* */ +/* */ public DecimalFormatter(int sigFigs, boolean flt) +/* */ { +/* 17 */ this.sigFigs = sigFigs; +/* 18 */ this.flt = flt; +/* 19 */ this.sigstr = ""; +/* 20 */ for (int i = 0; i < sigFigs + 1; i++) this.sigstr += "0"; +/* */ } +/* */ +/* 23 */ public String scientificNotation(BigDecimal d) { int hold = 0; +/* 24 */ boolean negatory = d.compareTo(BigDecimal.ZERO) == -1; +/* 25 */ if (negatory) d = d.abs(); +/* 26 */ while (d.compareTo(BigDecimal.ONE) == -1) +/* */ { +/* 28 */ d = d.multiply(BigDecimal.TEN); +/* 29 */ hold--; +/* */ } +/* 31 */ while (d.compareTo(BigDecimal.TEN) == 1) +/* */ { +/* 33 */ d = d.divide(BigDecimal.TEN); +/* 34 */ hold++; +/* */ } +/* */ +/* 37 */ String dec = roundTo(d, this.sigFigs - 1).toString(); +/* 38 */ if (!this.flt) { +/* 39 */ dec = removeTrailingZeros(dec); +/* */ } +/* 41 */ return (negatory ? "-" : "") + dec.substring(0, this.sigFigs + 1) + "*10^" + hold; } +/* */ +/* */ public String scientificNotation(String num) { +/* 44 */ return scientificNotation(new BigDecimal(num)); +/* */ } +/* */ public String scientificNotation(double num) { +/* 47 */ return scientificNotation(new BigDecimal(num)); +/* */ } +/* */ public String eNotation(BigDecimal d) { +/* 50 */ int hold = 0; +/* 51 */ boolean negatory = d.compareTo(BigDecimal.ZERO) == -1; +/* 52 */ if (negatory) d = d.abs(); +/* 53 */ while (d.compareTo(BigDecimal.ONE) == -1) +/* */ { +/* 55 */ d = d.multiply(BigDecimal.TEN); +/* 56 */ hold--; +/* */ } +/* 58 */ while (d.compareTo(BigDecimal.TEN) == 1) +/* */ { +/* 60 */ d = d.divide(BigDecimal.TEN); +/* 61 */ hold++; +/* */ } +/* */ +/* 64 */ String dec = roundTo(d, this.sigFigs - 1).toString(); +/* 65 */ if (!this.flt) { +/* 66 */ dec = removeTrailingZeros(dec); +/* */ } +/* 68 */ return (negatory ? "-" : "") + dec + "e" + hold; +/* */ } +/* */ public static BigDecimal roundTo(BigDecimal b, int to) { +/* 71 */ b = b.movePointRight(to); +/* 72 */ b = b.round(MathContext.DECIMAL64); +/* 73 */ b = b.movePointLeft(to); +/* 74 */ return b; +/* */ } +/* */ public String eNotation(String num) { +/* 77 */ return eNotation(new BigDecimal(num)); +/* */ } +/* */ public String eNotation(double num) { +/* 80 */ return eNotation(new BigDecimal(num)); +/* */ } +/* */ public String getSigFigs(String num) { +/* 83 */ boolean rec = false; +/* 84 */ String ret = ""; +/* 85 */ int cnt = 0; +/* 86 */ for (int i = 0; (i < num.length()) && (cnt < this.sigFigs); i++) { +/* 87 */ ret = ret + num.charAt(i); +/* 88 */ if ((num.charAt(i) != '0') && (num.charAt(i) != '.') && (!rec)) rec = true; +/* 89 */ if (rec) cnt++; +/* */ } +/* 91 */ return ret; +/* */ } +/* */ private static String removeTrailingZeros(String str) { +/* 94 */ if (!str.contains(".")) return str; +/* 95 */ for (int i = str.length() - 1; i >= 0; i--) { +/* 96 */ if (str.charAt(i) != '0') +/* 97 */ return str.substring(0, i + 1); +/* */ } +/* 99 */ return str; +/* */ } +/* */ public abstract String format(String paramString); +/* */ +/* 103 */ public void setFigs(int sigFigs) { this.sigFigs = sigFigs; +/* 104 */ this.sigstr = ""; +/* 105 */ for (int i = 0; i < sigFigs + 1; i++) this.sigstr += "0"; +/* */ } +/* */ } + +/* Location: Modulus.jar + * Qualified Name: utilities.DecimalFormatter + * JD-Core Version: 0.6.2 + */
\ No newline at end of file diff --git a/src/utilities/EFormatter.java b/src/utilities/EFormatter.java new file mode 100644 index 0000000..d9a060b --- /dev/null +++ b/src/utilities/EFormatter.java @@ -0,0 +1,26 @@ +/* */ package utilities; +/* */ +/* */ public class EFormatter extends DecimalFormatter +/* */ { +/* */ private int base; +/* */ +/* */ public EFormatter(int radix, int base, boolean flt) +/* */ { +/* 14 */ super(radix, flt); +/* 15 */ this.base = base; +/* */ } +/* */ +/* */ public String format(String str) { +/* 19 */ if (Double.parseDouble(str) < this.base) return str; +/* 20 */ String temp = super.eNotation(str); +/* 21 */ String exp = temp.substring(temp.lastIndexOf("e") + 1); +/* 22 */ temp = temp.substring(0, temp.lastIndexOf("e") + 1); +/* 23 */ exp = BaseConverter.convertFromDecimal(Long.parseLong(exp), this.base); +/* 24 */ return temp + exp; +/* */ } +/* */ } + +/* Location: Modulus.jar + * Qualified Name: utilities.EFormatter + * JD-Core Version: 0.6.2 + */
\ No newline at end of file diff --git a/src/utilities/NoFormatter.java b/src/utilities/NoFormatter.java new file mode 100644 index 0000000..9130700 --- /dev/null +++ b/src/utilities/NoFormatter.java @@ -0,0 +1,17 @@ +/* */ package utilities; +/* */ +/* */ public class NoFormatter extends DecimalFormatter +/* */ { +/* */ public NoFormatter(int radix) +/* */ { +/* 13 */ super(radix, true); +/* */ } +/* */ public String format(String str) { +/* 16 */ return str; +/* */ } +/* */ } + +/* Location: Modulus.jar + * Qualified Name: utilities.NoFormatter + * JD-Core Version: 0.6.2 + */
\ No newline at end of file diff --git a/src/utilities/PublicFileClassLoader.java b/src/utilities/PublicFileClassLoader.java new file mode 100644 index 0000000..addf4f9 --- /dev/null +++ b/src/utilities/PublicFileClassLoader.java @@ -0,0 +1,44 @@ +/* */ package utilities; +/* */ +/* */ import java.io.File; +/* */ import java.net.MalformedURLException; +/* */ import java.net.URI; +/* */ import java.net.URL; +/* */ import java.net.URLClassLoader; +/* */ +/* */ public class PublicFileClassLoader extends URLClassLoader +/* */ { +/* */ public PublicFileClassLoader() +/* */ { +/* 15 */ super(new URL[0]); +/* */ } +/* */ public PublicFileClassLoader(String dir) throws MalformedURLException { +/* 18 */ this(new File(dir)); +/* */ } +/* */ public PublicFileClassLoader(File directory) throws MalformedURLException { +/* 21 */ super(new URL[] { directory.toURI().toURL() }); +/* */ } +/* */ public PublicFileClassLoader(File[] dirs) throws MalformedURLException { +/* 24 */ this(); +/* 25 */ for (File f : dirs) addURL(f.toURI().toURL()); +/* */ } +/* */ +/* 28 */ public void addURL(URL url) { super.addURL(url); } +/* */ +/* */ public boolean addDir(String dir) { +/* 31 */ return addDir(new File(dir)); +/* */ } +/* */ public boolean addDir(File dir) { +/* */ try { +/* 35 */ addURL(dir.toURI().toURL()); +/* 36 */ return true; +/* */ } catch (MalformedURLException e) { +/* */ } +/* 39 */ return false; +/* */ } +/* */ } + +/* Location: Modulus.jar + * Qualified Name: utilities.PublicFileClassLoader + * JD-Core Version: 0.6.2 + */
\ No newline at end of file diff --git a/src/utilities/ScientificFormatter.java b/src/utilities/ScientificFormatter.java new file mode 100644 index 0000000..65c8afe --- /dev/null +++ b/src/utilities/ScientificFormatter.java @@ -0,0 +1,26 @@ +/* */ package utilities; +/* */ +/* */ public class ScientificFormatter extends DecimalFormatter +/* */ { +/* */ private int base; +/* */ +/* */ public ScientificFormatter(int radix, int base, boolean flt) +/* */ { +/* 14 */ super(radix, flt); +/* 15 */ this.base = base; +/* */ } +/* */ public String format(String str) { +/* 18 */ if (Double.parseDouble(str) < this.base) return str; +/* 19 */ String temp = super.scientificNotation(str); +/* 20 */ String exp = temp.substring(temp.lastIndexOf("*10^") + 4); +/* 21 */ temp = temp.substring(0, temp.lastIndexOf("*10^") + 4); +/* 22 */ exp = BaseConverter.convertFromDecimal(Long.parseLong(exp), this.base); +/* */ +/* 24 */ return temp + exp; +/* */ } +/* */ } + +/* Location: Modulus.jar + * Qualified Name: utilities.ScientificFormatter + * JD-Core Version: 0.6.2 + */
\ No newline at end of file |