comparison src/main/gov/nasa/jpf/vm/ByteArrayFields.java @ 0:61d41facf527

initial v8 import (history reset)
author Peter Mehlitz <Peter.C.Mehlitz@nasa.gov>
date Fri, 23 Jan 2015 10:14:01 -0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:61d41facf527
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 package gov.nasa.jpf.vm;
20
21 import gov.nasa.jpf.util.HashData;
22 import gov.nasa.jpf.util.IntVector;
23
24 import java.io.PrintStream;
25
26 /**
27 * element values for byte[] objects
28 */
29 public class ByteArrayFields extends ArrayFields {
30
31 byte[] values;
32
33 public ByteArrayFields (int length) {
34 values = new byte[length];
35 }
36
37 @Override
38 public byte[] asByteArray() {
39 return values;
40 }
41
42 @Override
43 public void copyElements (ArrayFields src, int srcPos, int dstPos, int len){
44 ByteArrayFields a = (ByteArrayFields) src;
45 System.arraycopy(a.values, srcPos, values, dstPos, len);
46 }
47
48 @Override
49 protected void printValue(PrintStream ps, int idx){
50 ps.print(values[idx]);
51 }
52
53 @Override
54 public Object getValues(){
55 return values;
56 }
57
58 @Override
59 public int arrayLength() {
60 return values.length;
61 }
62
63 @Override
64 public int getHeapSize() {
65 return values.length;
66 }
67
68 @Override
69 public boolean equals (Object o) {
70 if (o instanceof ByteArrayFields) {
71 ByteArrayFields other = (ByteArrayFields)o;
72
73 byte[] v = values;
74 byte[] vOther = other.values;
75 if (v.length != vOther.length) {
76 return false;
77 }
78
79 for (int i=0; i<v.length; i++) {
80 if (v[i] != vOther[i]) {
81 return false;
82 }
83 }
84
85 return compareAttrs(other);
86
87 } else {
88 return false;
89 }
90 }
91
92 @Override
93 public ByteArrayFields clone(){
94 ByteArrayFields f = (ByteArrayFields)cloneFields();
95 f.values = values.clone();
96 return f;
97 }
98
99 @Override
100 public void setByteValue (int pos, byte b) {
101 values[pos] = b;
102 }
103
104 @Override
105 public byte getByteValue (int pos) {
106 return values[pos];
107 }
108
109 @Override
110 public void appendTo (IntVector v) {
111 v.appendPacked(values);
112 }
113
114 @Override
115 public void hash(HashData hd) {
116 byte[] v = values;
117 for (int i=0; i < v.length; i++) {
118 hd.add(v[i]);
119 }
120 }
121
122 }