1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*******************************************************************************
* Copyright (c) 2009 Cloudsmith Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Cloudsmith Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.p2.tests.core;
import java.util.Arrays;
import junit.framework.TestCase;
import org.eclipse.equinox.internal.p2.core.helpers.StringHelper;
import org.eclipse.equinox.p2.publisher.AbstractPublisherAction;
public class StringHelperTest extends TestCase {
public void testSimilarBehavior() {
String[] a1 = AbstractPublisherAction.getArrayFromString("foo, bar, baz ,,, zaz", ",");
String[] a2 = StringHelper.getArrayFromString("foo, bar, baz ,,, zaz", ',');
assertTrue("1.0", Arrays.equals(a1, a2));
a1 = AbstractPublisherAction.getArrayFromString("foo bar baz, ,, zaz", " ");
a2 = StringHelper.getArrayFromString("foo bar baz, ,, zaz", ' ');
assertTrue("1.1", Arrays.equals(a1, a2));
a1 = AbstractPublisherAction.getArrayFromString(" ", " ");
a2 = StringHelper.getArrayFromString(" ", ' ');
assertTrue("1.2", Arrays.equals(a1, a2));
a1 = AbstractPublisherAction.getArrayFromString("", ",");
a2 = StringHelper.getArrayFromString("", ',');
assertTrue("1.3", Arrays.equals(a1, a2));
a1 = AbstractPublisherAction.getArrayFromString(null, ",");
a2 = StringHelper.getArrayFromString(null, ',');
assertTrue("1.4", Arrays.equals(a1, a2));
}
public void testPerformance() throws Exception {
String[] strings = new String[5];
StringBuffer inputBld = new StringBuffer();
for (int idx = 0; idx < 5; ++idx) {
if (idx > 0)
inputBld.append(',');
for (int c = 11; c > idx * 2; --c)
inputBld.append((char) ('a' + c));
strings[idx] = inputBld.toString();
}
long ts = System.currentTimeMillis();
for (int cnt = 0; cnt < 1000000; ++cnt)
for (int idx = 0; idx < 5; ++idx)
AbstractPublisherAction.getArrayFromString(strings[idx], ",");
long apaTime = System.currentTimeMillis() - ts;
ts = System.currentTimeMillis();
for (int cnt = 0; cnt < 1000000; ++cnt)
for (int idx = 0; idx < 5; ++idx)
StringHelper.getArrayFromString(strings[idx], ',');
long shTime = System.currentTimeMillis() - ts;
System.out.println("Ratio: " + (double) shTime / (double) apaTime);
}
}
|