Fixing a few bugs in the statistics printout.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / FloatArrayFields.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 float[] objects
27  */
28 public class FloatArrayFields extends ArrayFields {
29
30   float[] values;
31
32   public FloatArrayFields (int length) {
33     values = new float[length];
34   }
35
36   @Override
37   public float[] asFloatArray() {
38     return values;
39   }
40   
41   @Override
42   public void copyElements (ArrayFields src, int srcPos, int dstPos, int len){
43     FloatArrayFields a = (FloatArrayFields) 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 * 4;
65   }
66
67   @Override
68   public void appendTo (IntVector v) {
69     v.appendRawBits(values);
70   }
71
72   @Override
73   public FloatArrayFields clone(){
74     FloatArrayFields f = (FloatArrayFields)cloneFields();
75     f.values = values.clone();
76     return f;
77   }
78
79   @Override
80   public boolean equals (Object o) {
81     if (o instanceof FloatArrayFields) {
82       FloatArrayFields other = (FloatArrayFields)o;
83
84       float[] v = values;
85       float[] vOther = other.values;
86       if (v.length != vOther.length) {
87         return false;
88       }
89
90       for (int i=0; i<v.length; i++) {
91         if (v[i] != vOther[i]) {
92           return false;
93         }
94       }
95
96       return compareAttrs(other);
97
98     } else {
99       return false;
100     }
101   }
102
103   @Override
104   public void setFloatValue (int pos, float newValue) {
105     values[pos] = newValue;
106   }
107
108   @Override
109   public float getFloatValue (int pos) {
110     return values[pos];
111   }
112
113
114   @Override
115   public void hash(HashData hd) {
116     float[] v = values;
117     for (int i=0; i < v.length; i++) {
118       hd.add(v[i]);
119     }
120   }
121
122 }