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