01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.test.server;
23:
24: /**
25: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
26: * @version $Revision: 8784 $
27: */
28: public class Utils {
29:
30: public static String RANGE_0_255 = computeFrom0To255();
31:
32: public static String RANGE_256_512 = computeFrom256To512();
33:
34: private static String computeFrom0To255() {
35: return compute(0, 256);
36: }
37:
38: private static String computeFrom256To512() {
39: return compute(256, 512);
40: }
41:
42: public static String compute(int from, int to) {
43: if (from < 0) {
44: throw new IllegalArgumentException();
45: }
46: if (from > to) {
47: throw new IllegalArgumentException();
48: }
49: StringBuffer tmp = new StringBuffer();
50: for (int i = from; i < to; i++) {
51: char c = (char) i;
52: tmp.append(c);
53: }
54: return tmp.toString();
55: }
56:
57: public static String compareString(String s1, String s2) {
58: if (s1 == null) {
59: return "s1 is null";
60: }
61: if (s2 == null) {
62: return "s2 is null";
63: }
64: if (s1.length() != s2.length()) {
65: return "lengths don't match " + s1.length() + "!="
66: + s2.length();
67: }
68: for (int i = s1.length() - 1; i >= 0; i--) {
69: char c1 = s1.charAt(i);
70: char c2 = s2.charAt(i);
71: if (c1 != c2) {
72: return "char at position " + i + " are diffrent "
73: + (int) c1 + "!=" + (int) c2;
74: }
75: }
76: return null;
77: }
78:
79: }
|