home *** CD-ROM | disk | FTP | other *** search
/ Print Shop Ensemble 3 / the-print-shop-ensemble-iii.iso / worldnet / disk2 / java.z / MOZ2_01.ZIP / java / lang / Long.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-08  |  4.0 KB  |  188 lines

  1. package java.lang;
  2.  
  3. public final class Long extends Number {
  4.    public static final long MIN_VALUE = -9223372036854775808L;
  5.    public static final long MAX_VALUE = 9223372036854775807L;
  6.    private long value;
  7.  
  8.    public static String toString(long i, int radix) {
  9.       int digitCount = 0;
  10.       boolean minval = false;
  11.       boolean negative = false;
  12.       if (i == MIN_VALUE) {
  13.          switch (radix) {
  14.             case 16:
  15.                return "-8000000000000000";
  16.             case 8:
  17.                return "-1000000000000000000000";
  18.             case 4:
  19.                return "-20000000000000000000000000000000";
  20.             case 2:
  21.                return "-1000000000000000000000000000000000000000000000000000000000000000";
  22.             default:
  23.                negative = true;
  24.                minval = true;
  25.                i = MAX_VALUE;
  26.          }
  27.       } else if (i < 0L) {
  28.          i = -i;
  29.          negative = true;
  30.       }
  31.  
  32.       StringBuffer buf;
  33.       for(buf = new StringBuffer(45); i > 0L; ++digitCount) {
  34.          if (i < (long)radix) {
  35.             buf.append(Character.forDigit((int)i, radix));
  36.             i = 0L;
  37.          } else {
  38.             int j = (int)(i % (long)radix);
  39.             i /= (long)radix;
  40.             buf.append(Character.forDigit(j, radix));
  41.          }
  42.       }
  43.  
  44.       if (digitCount <= 0) {
  45.          return "0";
  46.       } else {
  47.          int j = buf.length();
  48.          int k = 0;
  49.          char[] tmp;
  50.          if (negative) {
  51.             tmp = new char[j + 1];
  52.             tmp[0] = '-';
  53.             k = 1;
  54.          } else {
  55.             tmp = new char[j];
  56.          }
  57.  
  58.          for(int ii = 0; j-- > 0; tmp[j + k] = buf.charAt(ii++)) {
  59.          }
  60.  
  61.          if (minval) {
  62.             ++tmp[tmp.length - 1];
  63.          }
  64.  
  65.          return String.valueOf(tmp);
  66.       }
  67.    }
  68.  
  69.    public static String toString(long i) {
  70.       return toString(i, 10);
  71.    }
  72.  
  73.    public static long parseLong(String s, int radix) throws NumberFormatException {
  74.       if (s == null) {
  75.          throw new NumberFormatException("null");
  76.       } else {
  77.          long result = 0L;
  78.          boolean negative = false;
  79.          int i = 0;
  80.          int max = s.length();
  81.          if (max <= 0) {
  82.             throw new NumberFormatException(s);
  83.          } else {
  84.             if (s.charAt(0) == '-') {
  85.                negative = true;
  86.                ++i;
  87.             }
  88.  
  89.             while(i < max) {
  90.                int digit = Character.digit(s.charAt(i++), radix);
  91.                if (digit < 0) {
  92.                   throw new NumberFormatException(s);
  93.                }
  94.  
  95.                result = result * (long)radix + (long)digit;
  96.             }
  97.  
  98.             return negative ? -result : result;
  99.          }
  100.       }
  101.    }
  102.  
  103.    public static long parseLong(String s) throws NumberFormatException {
  104.       return parseLong(s, 10);
  105.    }
  106.  
  107.    public static Long valueOf(String s, int radix) throws NumberFormatException {
  108.       return new Long(parseLong(s, radix));
  109.    }
  110.  
  111.    public static Long valueOf(String s) throws NumberFormatException {
  112.       return new Long(parseLong(s, 10));
  113.    }
  114.  
  115.    public Long(long value) {
  116.       this.value = value;
  117.    }
  118.  
  119.    public Long(String s) throws NumberFormatException {
  120.       this.value = parseLong(s, 10);
  121.    }
  122.  
  123.    public int intValue() {
  124.       return (int)this.value;
  125.    }
  126.  
  127.    public long longValue() {
  128.       return this.value;
  129.    }
  130.  
  131.    public float floatValue() {
  132.       return (float)this.value;
  133.    }
  134.  
  135.    public double doubleValue() {
  136.       return (double)this.value;
  137.    }
  138.  
  139.    public String toString() {
  140.       return String.valueOf(this.value);
  141.    }
  142.  
  143.    public int hashCode() {
  144.       return (int)this.value;
  145.    }
  146.  
  147.    public boolean equals(Object obj) {
  148.       if (obj != null && obj instanceof Long) {
  149.          return this.value == (Long)obj;
  150.       } else {
  151.          return false;
  152.       }
  153.    }
  154.  
  155.    public static Long getLong(String nm) {
  156.       return getLong(nm, (Long)null);
  157.    }
  158.  
  159.    public static Long getLong(String nm, long val) {
  160.       Long result = getLong(nm, (Long)null);
  161.       return result == null ? new Long(val) : result;
  162.    }
  163.  
  164.    public static Long getLong(String nm, Long val) {
  165.       String v = System.getProperty(nm);
  166.       if (v != null) {
  167.          try {
  168.             if (v.startsWith("0x")) {
  169.                return valueOf(v.substring(2), 16);
  170.             }
  171.  
  172.             if (v.startsWith("#")) {
  173.                return valueOf(v.substring(1), 16);
  174.             }
  175.  
  176.             if (v.startsWith("0")) {
  177.                return valueOf(v.substring(1), 8);
  178.             }
  179.  
  180.             return valueOf(v);
  181.          } catch (NumberFormatException var3) {
  182.          }
  183.       }
  184.  
  185.       return val;
  186.    }
  187. }
  188.