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 / Integer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-03-08  |  3.8 KB  |  188 lines

  1. package java.lang;
  2.  
  3. public final class Integer extends Number {
  4.    public static final int MIN_VALUE = -2147483648;
  5.    public static final int MAX_VALUE = 2147483647;
  6.    private int value;
  7.  
  8.    public static String toString(int 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 "-80000000";
  16.             case 8:
  17.                return "-20000000000";
  18.             case 4:
  19.                return "-2000000000000000";
  20.             case 2:
  21.                return "-10000000000000000000000000000000";
  22.             default:
  23.                negative = true;
  24.                minval = true;
  25.                i = MAX_VALUE;
  26.          }
  27.       } else if (i < 0) {
  28.          i = -i;
  29.          negative = true;
  30.       }
  31.  
  32.       StringBuffer buf;
  33.       for(buf = new StringBuffer(32); i > 0; ++digitCount) {
  34.          if (i < radix) {
  35.             buf.append(Character.forDigit(i, radix));
  36.             i = 0;
  37.          } else {
  38.             int j = i % radix;
  39.             i /= 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 var9 = 0; j-- > 0; tmp[j + k] = buf.charAt(var9++)) {
  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(int i) {
  70.       return toString(i, 10);
  71.    }
  72.  
  73.    public static int parseInt(String s, int radix) throws NumberFormatException {
  74.       if (s == null) {
  75.          throw new NumberFormatException("null");
  76.       } else {
  77.          int result = 0;
  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 * radix + digit;
  96.             }
  97.  
  98.             return negative ? -result : result;
  99.          }
  100.       }
  101.    }
  102.  
  103.    public static int parseInt(String s) throws NumberFormatException {
  104.       return parseInt(s, 10);
  105.    }
  106.  
  107.    public static Integer valueOf(String s, int radix) throws NumberFormatException {
  108.       return new Integer(parseInt(s, radix));
  109.    }
  110.  
  111.    public static Integer valueOf(String s) throws NumberFormatException {
  112.       return new Integer(parseInt(s, 10));
  113.    }
  114.  
  115.    public Integer(int value) {
  116.       this.value = value;
  117.    }
  118.  
  119.    public Integer(String s) throws NumberFormatException {
  120.       this.value = parseInt(s, 10);
  121.    }
  122.  
  123.    public int intValue() {
  124.       return this.value;
  125.    }
  126.  
  127.    public long longValue() {
  128.       return (long)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 this.value;
  145.    }
  146.  
  147.    public boolean equals(Object obj) {
  148.       if (obj != null && obj instanceof Integer) {
  149.          return this.value == (Integer)obj;
  150.       } else {
  151.          return false;
  152.       }
  153.    }
  154.  
  155.    public static Integer getInteger(String nm) {
  156.       return getInteger(nm, (Integer)null);
  157.    }
  158.  
  159.    public static Integer getInteger(String nm, int val) {
  160.       Integer result = getInteger(nm, (Integer)null);
  161.       return result == null ? new Integer(val) : result;
  162.    }
  163.  
  164.    public static Integer getInteger(String nm, Integer 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.