[String] Review string factories
- Remove interning and compacting of String, it is no longer
appropriate for current JREs
diff --git a/jcommons/org.eclipse.statet.jcommons.util-tests/src/org/eclipse/statet/jcommons/string/StringUtilsTest.java b/jcommons/org.eclipse.statet.jcommons.util-tests/src/org/eclipse/statet/jcommons/util/StringUtilsTest.java
similarity index 96%
rename from jcommons/org.eclipse.statet.jcommons.util-tests/src/org/eclipse/statet/jcommons/string/StringUtilsTest.java
rename to jcommons/org.eclipse.statet.jcommons.util-tests/src/org/eclipse/statet/jcommons/util/StringUtilsTest.java
index f52352c..2f2d4ab 100644
--- a/jcommons/org.eclipse.statet.jcommons.util-tests/src/org/eclipse/statet/jcommons/string/StringUtilsTest.java
+++ b/jcommons/org.eclipse.statet.jcommons.util-tests/src/org/eclipse/statet/jcommons/util/StringUtilsTest.java
@@ -12,7 +12,7 @@
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
-package org.eclipse.statet.jcommons.string;
+package org.eclipse.statet.jcommons.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/BasicStringFactory.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/BasicStringFactory.java
index 5cf6c97..e09285c 100644
--- a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/BasicStringFactory.java
+++ b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/BasicStringFactory.java
@@ -14,7 +14,10 @@
package org.eclipse.statet.jcommons.string;
+import org.eclipse.statet.jcommons.lang.NonNullByDefault;
+
+@NonNullByDefault
public final class BasicStringFactory implements StringFactory {
@@ -36,8 +39,8 @@
}
@Override
- public String get(final String s, final boolean isCompact) {
- return (isCompact) ? s : new String(s);
+ public String get(final String s) {
+ return s;
}
}
diff --git a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/InternStringCache.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/CacheStringFactory.java
similarity index 90%
rename from jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/InternStringCache.java
rename to jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/CacheStringFactory.java
index 0fbff29..4138ca3 100644
--- a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/InternStringCache.java
+++ b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/CacheStringFactory.java
@@ -18,7 +18,7 @@
/**
* A cache of fixed size, interning string
*/
-public class InternStringCache implements StringFactory {
+public class CacheStringFactory implements StringFactory {
private static final int HASHSET_SIZE= 0x400;
@@ -39,7 +39,7 @@
private final int maxCachedLength;
- public InternStringCache(final int maxCachedLength) {
+ public CacheStringFactory(final int maxCachedLength) {
this.values= new String[HASHSET_MASK + 1];
this.maxCachedLength= maxCachedLength;
}
@@ -76,7 +76,7 @@
}
@Override
- public String get(final String s, final boolean isCompact) {
+ public String get(final String s) {
switch (s.length()) {
case 0:
return ""; //$NON-NLS-1$
@@ -84,7 +84,7 @@
return getChar(s.charAt(0), s);
default:
if (s.length() > this.maxCachedLength) {
- return (isCompact) ? s : new String(s);
+ return s;
}
return getDefault(s);
}
@@ -104,7 +104,7 @@
return s1;
}
// this.statSet++;
- return (this.values[i1]= String.valueOf(c).intern());
+ return (this.values[i1]= String.valueOf(c));
}
}
@@ -121,7 +121,7 @@
return s1;
}
// this.statSet++;
- return (this.values[i1]= s.intern());
+ return (this.values[i1]= s);
}
}
@@ -144,7 +144,7 @@
return s1;
}
// this.statSet++;
- return (this.values[i1]= s.toString().intern());
+ return (this.values[i1]= s.toString());
}
private String getDefault(final CharSequence s) {
@@ -156,7 +156,7 @@
return s1;
}
// this.statSet++;
- return (this.values[i1]= s.toString().intern());
+ return (this.values[i1]= s.toString());
}
private String getDefault(final String s) {
@@ -168,7 +168,7 @@
return s1;
}
// this.statSet++;
- return (this.values[i1]= s.intern());
+ return (this.values[i1]= s);
}
diff --git a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/CharArrayString.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/CharArrayString.java
index 826104d..250ed65 100644
--- a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/CharArrayString.java
+++ b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/CharArrayString.java
@@ -14,6 +14,9 @@
package org.eclipse.statet.jcommons.string;
+import org.eclipse.statet.jcommons.lang.NonNullByDefault;
+import org.eclipse.statet.jcommons.lang.Nullable;
+
/**
* Open string class based on char array.
@@ -22,6 +25,7 @@
*
* The class is not prepared for concurrent access.
*/
+@NonNullByDefault
public final class CharArrayString implements CharSequence {
@@ -39,10 +43,12 @@
this.array= EMPTY_ARRAY;
}
+ @SuppressWarnings("null")
public CharArrayString(final char[] array, final int offset, final int length) {
set(array, offset, length);
}
+ @SuppressWarnings("null")
public CharArrayString(final String s) {
set(s);
}
@@ -122,7 +128,7 @@
}
@Override
- public boolean equals(final Object obj) {
+ public boolean equals(final @Nullable Object obj) {
if (!(obj instanceof CharArrayString)) {
return false;
}
diff --git a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/InternStringFactory.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/InternStringFactory.java
deleted file mode 100644
index a07e64e..0000000
--- a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/InternStringFactory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*=============================================================================#
- # Copyright (c) 2012, 2021 Stephan Wahlbrink and others.
- #
- # This program and the accompanying materials are made available under the
- # terms of the Eclipse Public License 2.0 which is available at
- # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
- # which is available at https://www.apache.org/licenses/LICENSE-2.0.
- #
- # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
- #
- # Contributors:
- # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
- #=============================================================================*/
-
-package org.eclipse.statet.jcommons.string;
-
-
-public final class InternStringFactory implements StringFactory {
-
-
- public static final StringFactory INSTANCE= new InternStringFactory();
-
-
- public InternStringFactory() {
- }
-
-
- @Override
- public String get(final CharArrayString s) {
- return s.toString().intern();
- }
-
- @Override
- public String get(final CharSequence s) {
- return s.toString().intern();
- }
-
- @Override
- public String get(final String s, final boolean isCompact) {
- return s.intern();
- }
-
-}
diff --git a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/StringFactory.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/StringFactory.java
index 78463d1..4c72615 100644
--- a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/StringFactory.java
+++ b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/StringFactory.java
@@ -14,10 +14,13 @@
package org.eclipse.statet.jcommons.string;
+import org.eclipse.statet.jcommons.lang.NonNullByDefault;
+
/**
- * Implement to provide a strategy to create (intern, compact) or share string instances.
+ * Implement to provide a strategy to create or share string instances.
*/
+@NonNullByDefault
public interface StringFactory {
@@ -25,7 +28,6 @@
String get(CharSequence s);
- String get(String s, boolean isCompact);
-
+ String get(String s);
}
diff --git a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/StringUtils.java b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/util/StringUtils.java
similarity index 96%
rename from jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/StringUtils.java
rename to jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/util/StringUtils.java
index b4273c5..7986a9f 100644
--- a/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/string/StringUtils.java
+++ b/jcommons/org.eclipse.statet.jcommons.util/src/org/eclipse/statet/jcommons/util/StringUtils.java
@@ -12,7 +12,7 @@
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
-package org.eclipse.statet.jcommons.string;
+package org.eclipse.statet.jcommons.util;
import org.eclipse.statet.jcommons.lang.NonNullByDefault;