01: /*
02: * Copyright (C) 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 26. June 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.benchmark.strings.targets;
12:
13: import com.thoughtworks.xstream.tools.benchmark.Target;
14:
15: import java.util.Arrays;
16:
17: /**
18: * A target with an array of java.lang.String objects.
19: *
20: * @author Jörg Schaible
21: * @see com.thoughtworks.xstream.tools.benchmark.Harness
22: * @see Target
23: */
24: public class StringArray implements Target {
25:
26: private final String[] strings;
27: private final int unique;
28:
29: public StringArray(int elements, int length, int unique) {
30: this .unique = unique;
31: char[] zero = new char[length];
32: Arrays.fill(zero, '0');
33:
34: strings = new String[elements];
35: for (int i = 0; i < strings.length; i++) {
36: String hex = Integer.toHexString(i % unique);
37: strings[i] = new String(zero, 0, zero.length - hex.length())
38: + hex;
39: }
40: }
41:
42: public String toString() {
43: return "String array with " + strings.length + " elements of "
44: + strings[0].length() + " chars and " + unique
45: + " unique entries";
46: }
47:
48: public Object target() {
49: return strings;
50: }
51:
52: public boolean isEqual(Object other) {
53: return Arrays.equals(strings, (Object[]) other);
54: }
55: }
|