Fixes null captured parameters
[jpf-core.git] / src / main / gov / nasa / jpf / vm / BooleanArrayFields.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18
19
20 package gov.nasa.jpf.vm;
21
22 import gov.nasa.jpf.util.HashData;
23 import gov.nasa.jpf.util.IntVector;
24
25 import java.io.PrintStream;
26
27 /**
28  * element values for boolean[] objects
29  */
30 public class BooleanArrayFields extends ArrayFields {
31
32   boolean[] values;
33
34   public BooleanArrayFields (int length) {
35     values = new boolean[length];
36   }
37
38   @Override
39   public void copyElements (ArrayFields src, int srcPos, int dstPos, int len){
40     BooleanArrayFields a = (BooleanArrayFields) src;
41     System.arraycopy(a.values, srcPos, values, dstPos, len);
42   }
43   
44   @Override
45   protected void printValue(PrintStream ps, int idx){
46     ps.print(values[idx] ? 't' : 'f');
47   }
48
49   @Override
50   public boolean[] asBooleanArray() {
51     return values;
52   }
53
54   @Override
55   public Object getValues(){
56     return values;
57   }
58
59   @Override
60   public int arrayLength() {
61     return values.length;
62   }
63
64   @Override
65   public int getHeapSize() {
66     return values.length * 4;
67   }
68
69   /**
70    * we check for type and equal element values
71    */
72   @Override
73   public boolean equals (Object o) {
74     if (o instanceof BooleanArrayFields) {
75       BooleanArrayFields other = (BooleanArrayFields)o;
76
77       boolean[] v = values;
78       boolean[] vOther = other.values;
79       if (v.length != vOther.length) {
80         return false;
81       }
82
83       for (int i=0; i<v.length; i++) {
84         if (v[i] != vOther[i]) {
85           return false;
86         }
87       }
88
89       return compareAttrs(other);
90
91     } else {
92       return false;
93     }
94   }
95
96   @Override
97   public BooleanArrayFields clone(){
98     BooleanArrayFields f = (BooleanArrayFields)cloneFields();
99     f.values = values.clone();
100     return f;
101   }
102
103   // for serialization
104   @Override
105   public void appendTo(IntVector v) {
106     v.appendPacked(values);
107   }
108
109   @Override
110   public boolean getBooleanValue (int pos) {
111     return values[pos];
112   }
113
114   @Override
115   public void setBooleanValue (int pos, boolean v) {
116     values[pos] = v;
117   }
118
119   @Override
120   public void hash (HashData hd) {
121     boolean[] v = values;
122     for (int i=0; i < v.length; i++) {
123       hd.add(v[i]);
124     }
125   }
126
127 }