KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > annotation > arraycheck > IntValueContainer


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2000 Feng Qian
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26 package soot.jimple.toolkits.annotation.arraycheck;
27
28 class IntValueContainer
29 {
30     private static final int BOT = 0;
31     private static final int TOP = 1;
32     private static final int INT = 2;
33
34     private int type;
35     private int value;
36
37     public IntValueContainer()
38     {
39     this.type = BOT;
40     }
41
42     public IntValueContainer(int v)
43     {
44     this.type = INT;
45     this.value = v;
46     }
47
48     public boolean isBottom()
49     {
50     return (this.type == BOT);
51     }
52
53     public boolean isTop()
54     {
55     return (this.type == TOP);
56     }
57
58     public boolean isInteger()
59     {
60     return this.type == INT;
61     }
62
63     public int getValue()
64     {
65     if (this.type != INT)
66         throw new RuntimeException JavaDoc("IntValueContainer: not integer type");
67
68     return this.value;
69     }
70
71     public void setTop()
72     {
73     this.type = TOP;
74     }
75
76     public void setValue(int v)
77     {
78     this.type = INT;
79     this.value = v;
80     }
81
82     public void setBottom()
83     {
84     this.type = BOT;
85     }
86
87     public String JavaDoc toString()
88     {
89     if (type == BOT)
90         return "[B]";
91     else
92         if (type == TOP)
93         return "[T]";
94     else
95         return "["+value+"]";
96     }
97
98     public boolean equals(Object JavaDoc other)
99     {
100     if (!(other instanceof IntValueContainer))
101         return false;
102
103     IntValueContainer otherv = (IntValueContainer)other;
104
105     if ((this.type == INT) && (otherv.type == INT))
106         return (this.value == otherv.value);
107     else
108         return (this.type == otherv.type) ;
109     }
110
111     public IntValueContainer dup()
112     {
113     IntValueContainer other = new IntValueContainer();
114     other.type = this.type;
115     other.value = this.value;
116     
117     return other;
118     }
119 }
120  
121
Popular Tags