01: // plik 07_TryCatch_2/WhatIsIt.java
02:
03: public class WhatIsIt {
04:
05: private TYP typ;
06:
07: private int argint;
08: private double argdouble;
09: private String argstring;
10:
11: public WhatIsIt(String s) {
12:
13: if (s == null) {
14: typ = TYP.N;
15: return;
16: }
17:
18: s = s.trim();
19:
20: if (s.equals("")) {
21: typ = TYP.E;
22: return;
23: }
24:
25: try {
26: argint = Integer.parseInt(s);
27: typ = TYP.I;
28: return;
29: } catch (NumberFormatException ignore) { };
30:
31: try {
32: argdouble = Double.parseDouble(s);
33: typ = TYP.R;
34: return;
35: } catch (NumberFormatException ignore) { };
36:
37: argstring = s;
38: typ = TYP.S;
39: }
40:
41: public TYP getTyp() { return typ; }
42: public int getInt() { return argint; }
43: public double getDouble() { return argdouble; }
44: public String getString() { return argstring; }
45: }