aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/internal/analysis
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2011-01-13 20:39:40 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2011-01-13 20:39:40 +0000
commitb05619921551903a81b242b41d196b41c70e770f (patch)
tree3c84708256693a9172f6eee4ecf5f8533b620178 /org.jacoco.core/src/org/jacoco/core/internal/analysis
parent69bf63b30dc6911c0f1a85e68da4eb9740edf26e (diff)
downloadjacoco-b05619921551903a81b242b41d196b41c70e770f.tar.gz
Trac #133: Hide internal implementation classes.
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/internal/analysis')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java1
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/StringPool.java76
2 files changed, 76 insertions, 1 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java
index 1b875fdb..a4259f78 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/ClassAnalyzer.java
@@ -11,7 +11,6 @@
*******************************************************************************/
package org.jacoco.core.internal.analysis;
-import org.jacoco.core.analysis.StringPool;
import org.jacoco.core.internal.flow.IClassProbesVisitor;
import org.jacoco.core.internal.flow.IMethodProbesVisitor;
import org.objectweb.asm.AnnotationVisitor;
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/StringPool.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/StringPool.java
new file mode 100644
index 00000000..c81e9832
--- /dev/null
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/StringPool.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2011 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Brock Janiczak - analysis and concept
+ * Marc R. Hoffmann - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.core.internal.analysis;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility to normalize {@link String} instances in a way that if
+ * <code>equals()</code> is <code>true</code> for two strings they will be
+ * represented the same instance. While this is exactly what
+ * {@link String#intern()} does, this implementation avoids VM specific side
+ * effects and is supposed to be faster, as neither native code is called nor
+ * synchronization is required for concurrent lookup.
+ *
+ * @author Marc R. Hoffmann
+ * @version $qualified.bundle.version$
+ */
+public final class StringPool {
+
+ private static final String[] EMPTY_ARRAY = new String[0];
+
+ private final Map<String, String> pool = new HashMap<String, String>(1024);
+
+ /**
+ * Returns a normalized instance that is equal to the given {@link String} .
+ *
+ * @param s
+ * any string or <code>null</code>
+ * @return normalized instance or <code>null</code>
+ */
+ public String get(final String s) {
+ if (s == null) {
+ return null;
+ }
+ final String norm = pool.get(s);
+ if (norm == null) {
+ pool.put(s, s);
+ return s;
+ }
+ return norm;
+ }
+
+ /**
+ * Returns a modified version of the array with all string slots normalized.
+ * It is up to the implementation to replace strings in the array instance
+ * or return a new array instance.
+ *
+ * @param arr
+ * String array or <code>null</code>
+ * @return normalized instance or <code>null</code>
+ */
+ public String[] get(final String[] arr) {
+ if (arr == null) {
+ return null;
+ }
+ if (arr.length == 0) {
+ return EMPTY_ARRAY;
+ }
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = get(arr[i]);
+ }
+ return arr;
+ }
+
+}