2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
20 package gov.nasa.jpf.vm;
22 import gov.nasa.jpf.util.HashData;
23 import gov.nasa.jpf.util.IntVector;
24 import gov.nasa.jpf.util.PrintUtils;
26 import java.io.PrintStream;
29 * element values for char[] objects
31 public class CharArrayFields extends ArrayFields {
35 public CharArrayFields (int length) {
36 values = new char[length];
40 public char[] asCharArray(){
45 public void copyElements (ArrayFields src, int srcPos, int dstPos, int len){
46 CharArrayFields a = (CharArrayFields) src;
47 System.arraycopy(a.values, srcPos, values, dstPos, len);
51 protected void printValue(PrintStream ps, int idx){
52 PrintUtils.printCharLiteral(ps, values[idx]);
56 public void printElements( PrintStream ps, int max){
57 PrintUtils.printStringLiteral(ps, values, max);
61 public char[] asCharArray (int offset, int length) {
62 char[] result = new char[length];
63 System.arraycopy(values, offset, result, 0, length);
69 public Object getValues(){
74 public int arrayLength() {
79 public int getHeapSize() { // in bytes
80 return values.length * 2;
84 public void appendTo (IntVector v) {
85 v.appendPacked(values);
89 public CharArrayFields clone(){
90 CharArrayFields f = (CharArrayFields)cloneFields();
91 f.values = values.clone();
97 public boolean equals (Object o) {
98 if (o instanceof CharArrayFields) {
99 CharArrayFields other = (CharArrayFields)o;
102 char[] vOther = other.values;
103 if (v.length != vOther.length) {
107 for (int i=0; i<v.length; i++) {
108 if (v[i] != vOther[i]) {
113 return compareAttrs(other);
121 public char getCharValue(int pos) {
126 public void setCharValue(int pos, char newValue) {
127 values[pos] = newValue;
130 public void setCharValues(char[] v){
131 System.arraycopy(v,0,values,0,v.length);
134 //--- some methods to ease native String operations
136 public String asString(int offset, int length) {
137 return new String(values, offset, length);
140 // a special string compare utility
141 public boolean equals (int offset, int length, String s) {
144 if (offset+length > v.length) {
148 for (int i=offset, j=0; j<length; i++, j++) {
149 if (v[i] != s.charAt(j)) {
158 public void hash(HashData hd) {
160 for (int i=0; i < v.length; i++) {