Adding the old tracker variable for debugging/testing purposes.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / ShortArrayFields.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 package gov.nasa.jpf.vm;
19
20 import gov.nasa.jpf.util.HashData;
21 import gov.nasa.jpf.util.IntVector;
22
23 import java.io.PrintStream;
24
25 /**
26  * element values for short[] objects
27  */
28 public class ShortArrayFields extends ArrayFields {
29
30   short[] values;
31
32   public ShortArrayFields (int length) {
33     values = new short[length];
34   }
35
36   @Override
37   public short[] asShortArray() {
38     return values;
39   }
40
41   @Override
42   public void copyElements (ArrayFields src, int srcPos, int dstPos, int len){
43     ShortArrayFields a = (ShortArrayFields) src;
44     System.arraycopy(a.values, srcPos, values, dstPos, len);
45   }
46   
47   @Override
48   protected void printValue(PrintStream ps, int idx){
49     ps.print(values[idx]);
50   }
51   
52   @Override
53   public Object getValues(){
54     return values;
55   }
56
57   @Override
58   public int arrayLength() {
59     return values.length;
60   }
61
62   @Override
63   public int getHeapSize() {  // in bytes
64     return values.length * 2;
65   }
66
67   @Override
68   public void appendTo (IntVector v) {
69     v.appendPacked(values);
70   }
71
72   @Override
73   public ShortArrayFields clone(){
74     ShortArrayFields f = (ShortArrayFields)cloneFields();
75     f.values = values.clone();
76     return f;
77   }
78
79   @Override
80   public boolean equals (Object o) {
81     if (o instanceof ShortArrayFields) {
82       ShortArrayFields other = (ShortArrayFields)o;
83       short[] v = values;
84       short[] vOther = other.values;
85       if (v.length != vOther.length) {
86         return false;
87       }
88
89       for (int i=0; i<v.length; i++) {
90         if (v[i] != vOther[i]) {
91           return false;
92         }
93       }
94
95       return compareAttrs(other);
96
97     } else {
98       return false;
99     }
100   }
101
102
103   @Override
104   public short getShortValue(int pos) {
105     return values[pos];
106   }
107
108   @Override
109   public void setShortValue (int pos, short newValue) {
110     values[pos] = newValue;
111   }
112
113   @Override
114   public void hash(HashData hd) {
115     short[] v = values;
116     for (int i=0; i < v.length; i++) {
117       hd.add(v[i]);
118     }
119   }
120
121 }