diff --git a/src/main/java/io/ebean/dbmigration/ddlgeneration/platform/MySqlDdl.java b/src/main/java/io/ebean/dbmigration/ddlgeneration/platform/MySqlDdl.java index 7dfac3e8e..75372efd7 100644 --- a/src/main/java/io/ebean/dbmigration/ddlgeneration/platform/MySqlDdl.java +++ b/src/main/java/io/ebean/dbmigration/ddlgeneration/platform/MySqlDdl.java @@ -1,10 +1,10 @@ package io.ebean.dbmigration.ddlgeneration.platform; import io.ebean.config.dbplatform.DatabasePlatform; +import io.ebean.util.StringHelper; import io.ebean.dbmigration.ddlgeneration.DdlBuffer; import io.ebean.dbmigration.migration.AlterColumn; import io.ebean.dbmigration.migration.Column; -import io.ebeaninternal.server.lib.util.StringHelper; import java.io.IOException; diff --git a/src/main/java/io/ebeaninternal/api/LoadManyRequest.java b/src/main/java/io/ebeaninternal/api/LoadManyRequest.java index 4ce9f174c..f73af11aa 100644 --- a/src/main/java/io/ebeaninternal/api/LoadManyRequest.java +++ b/src/main/java/io/ebeaninternal/api/LoadManyRequest.java @@ -3,10 +3,10 @@ package io.ebeaninternal.api; import io.ebean.EbeanServer; import io.ebean.bean.BeanCollection; import io.ebean.bean.EntityBean; +import io.ebean.util.StringHelper; import io.ebeaninternal.server.core.OrmQueryRequest; import io.ebeaninternal.server.deploy.BeanDescriptor; import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; -import io.ebeaninternal.server.lib.util.StringHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java b/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java index 9165ce6f0..c5a4e0c88 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java @@ -8,6 +8,7 @@ import io.ebean.config.dbplatform.DbEncryptFunction; import io.ebean.config.dbplatform.DbPlatformType; import io.ebean.plugin.Property; import io.ebean.text.StringParser; +import io.ebean.util.StringHelper; import io.ebeaninternal.api.SpiExpressionRequest; import io.ebeaninternal.server.core.InternString; import io.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty; @@ -16,7 +17,6 @@ import io.ebeaninternal.server.deploy.generatedproperty.GeneratedWhenModified; import io.ebeaninternal.server.deploy.meta.DeployBeanProperty; import io.ebeaninternal.server.el.ElPropertyChainBuilder; import io.ebeaninternal.server.el.ElPropertyValue; -import io.ebeaninternal.server.lib.util.StringHelper; import io.ebeaninternal.server.properties.BeanPropertyGetter; import io.ebeaninternal.server.properties.BeanPropertySetter; import io.ebeaninternal.server.query.SplitName; diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyOverride.java b/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyOverride.java index a1905eb05..b8325ed24 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyOverride.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyOverride.java @@ -1,7 +1,7 @@ package io.ebeaninternal.server.deploy; +import io.ebean.util.StringHelper; import io.ebeaninternal.server.core.InternString; -import io.ebeaninternal.server.lib.util.StringHelper; /** * Used hold meta data when a bean property is overridden. diff --git a/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocManys.java b/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocManys.java index a1b4c0457..0332082ef 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocManys.java +++ b/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocManys.java @@ -6,6 +6,7 @@ import io.ebean.annotation.Where; import io.ebean.bean.BeanCollection.ModifyListenMode; import io.ebean.config.NamingConvention; import io.ebean.config.TableName; +import io.ebean.util.StringHelper; import io.ebeaninternal.server.deploy.BeanDescriptorManager; import io.ebeaninternal.server.deploy.BeanProperty; import io.ebeaninternal.server.deploy.BeanTable; @@ -13,7 +14,6 @@ import io.ebeaninternal.server.deploy.meta.DeployBeanProperty; import io.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocMany; import io.ebeaninternal.server.deploy.meta.DeployTableJoin; import io.ebeaninternal.server.deploy.meta.DeployTableJoinColumn; -import io.ebeaninternal.server.lib.util.StringHelper; import io.ebeaninternal.server.query.SqlJoinType; import javax.persistence.JoinColumn; diff --git a/src/main/java/io/ebeaninternal/server/el/ElPropertyChain.java b/src/main/java/io/ebeaninternal/server/el/ElPropertyChain.java index 6f6e86608..267fca5c4 100644 --- a/src/main/java/io/ebeaninternal/server/el/ElPropertyChain.java +++ b/src/main/java/io/ebeaninternal/server/el/ElPropertyChain.java @@ -2,9 +2,9 @@ package io.ebeaninternal.server.el; import io.ebean.bean.EntityBean; import io.ebean.text.StringParser; +import io.ebean.util.StringHelper; import io.ebeaninternal.api.SpiExpressionRequest; import io.ebeaninternal.server.deploy.BeanProperty; -import io.ebeaninternal.server.lib.util.StringHelper; import io.ebeaninternal.server.query.SplitName; import io.ebeaninternal.server.type.ScalarType; diff --git a/src/main/java/io/ebeaninternal/server/lib/util/StringHelper.java b/src/main/java/io/ebeaninternal/server/lib/util/StringHelper.java deleted file mode 100644 index e8aa44a37..000000000 --- a/src/main/java/io/ebeaninternal/server/lib/util/StringHelper.java +++ /dev/null @@ -1,292 +0,0 @@ -package io.ebeaninternal.server.lib.util; - -import java.util.HashMap; -import java.util.Map; - -/** - * Utility String class that supports String manipulation functions. - */ -public class StringHelper { - - /** - * Parses out a list of Name Value pairs that are delimited together. Will - * always return a StringMap. If allNameValuePairs is null, or no name - * values can be parsed out an empty StringMap is returned. - * - * @param allNameValuePairs the entire string to be parsed. - * @param listDelimiter (typically ';') the delimited between the list - * @param nameValueSeparator (typically '=') the separator between the name and value - */ - public static Map delimitedToMap(String allNameValuePairs, - String listDelimiter, String nameValueSeparator) { - - HashMap params = new HashMap<>(); - if ((allNameValuePairs == null) || (allNameValuePairs.isEmpty())) { - return params; - } - // trim off any leading listDelimiter... - allNameValuePairs = trimFront(allNameValuePairs, listDelimiter); - return getKeyValue(params, 0, allNameValuePairs, listDelimiter, nameValueSeparator); - } - - /** - * Trims off recurring strings from the front of a string. - * - * @param source the source string - * @param trim the string to trim off the front - */ - public static String trimFront(String source, String trim) { - if (source == null) { - return null; - } - if (source.indexOf(trim) == 0) { - // dp("trim ..."); - return trimFront(source.substring(trim.length()), trim); - } else { - return source; - } - } - - /** - * Return true if the value is null or an empty string. - */ - public static boolean isNull(String value) { - return value == null || value.trim().isEmpty(); - } - - /** - * Recursively pulls out the key value pairs from a raw string. - */ - private static HashMap getKeyValue(HashMap map, int pos, - String allNameValuePairs, String listDelimiter, String nameValueSeparator) { - - if (pos >= allNameValuePairs.length()) { - // dp("end as "+pos+" >= "+allNameValuePairs.length() ); - return map; - } - - int equalsPos = allNameValuePairs.indexOf(nameValueSeparator, pos); - int delimPos = allNameValuePairs.indexOf(listDelimiter, pos); - - if (delimPos == -1) { - delimPos = allNameValuePairs.length(); - } - if (equalsPos == -1) { - // dp("no more equals..."); - return map; - } - if (delimPos == (equalsPos + 1)) { - // dp("Ignoring as nothing between delim and equals... - // delim:"+delimPos+" eq:"+equalsPos); - return getKeyValue(map, delimPos + 1, allNameValuePairs, listDelimiter, - nameValueSeparator); - } - if (equalsPos > delimPos) { - // there is a key without a value? - String key = allNameValuePairs.substring(pos, delimPos); - key = key.trim(); - if (!key.isEmpty()) { - map.put(key, null); - } - return getKeyValue(map, delimPos + 1, allNameValuePairs, listDelimiter, - nameValueSeparator); - - } - String key = allNameValuePairs.substring(pos, equalsPos); - - if (delimPos > -1) { - String value = allNameValuePairs.substring(equalsPos + 1, delimPos); - // dp("cont "+key+","+value+" pos:"+pos+" - // len:"+allNameValuePairs.length()); - key = key.trim(); - - map.put(key, value); - pos = delimPos + 1; - - // recurse the rest of the values... - return getKeyValue(map, pos, allNameValuePairs, listDelimiter, nameValueSeparator); - } else { - // dp("ERROR: delimPos < 0 ???"); - return map; - } - } - - /** - * This method takes a String and will replace all occurrences of the match - * String with that of the replace String. - * - * @param source the source string - * @param match the string used to find a match - * @param replace the string used to replace match with - * @return the source string after the search and replace - */ - public static String replaceString(String source, String match, String replace) { - if (source == null) { - return null; - } - if (replace == null) { - return source; - } - if (match == null) { - throw new NullPointerException("match is null?"); - } - if (match.equals(replace)) { - return source; - } - return replaceString(source, match, replace, 30, 0, source.length()); - } - - /** - * Additionally specify the additionalSize to add to the buffer. This will - * make the buffer bigger so that it doesn't have to grow when replacement - * occurs. - */ - public static String replaceString(String source, String match, String replace, - int additionalSize, int startPos, int endPos) { - - if (source == null) { - return null; - } - - char match0 = match.charAt(0); - - int matchLength = match.length(); - - if (matchLength == 1 && replace.length() == 1) { - char replace0 = replace.charAt(0); - return source.replace(match0, replace0); - } - if (matchLength >= replace.length()) { - additionalSize = 0; - } - - - int sourceLength = source.length(); - int lastMatch = endPos - matchLength; - - StringBuilder sb = new StringBuilder(sourceLength + additionalSize); - - if (startPos > 0) { - sb.append(source.substring(0, startPos)); - } - - char sourceChar; - boolean isMatch; - int sourceMatchPos; - - for (int i = startPos; i < sourceLength; i++) { - sourceChar = source.charAt(i); - if (i > lastMatch || sourceChar != match0) { - sb.append(sourceChar); - - } else { - // check to see if this is a match - isMatch = true; - sourceMatchPos = i; - - // check each following character... - for (int j = 1; j < matchLength; j++) { - sourceMatchPos++; - if (source.charAt(sourceMatchPos) != match.charAt(j)) { - isMatch = false; - break; - } - } - if (isMatch) { - i = i + matchLength - 1; - sb.append(replace); - } else { - // was not a match - sb.append(sourceChar); - } - } - } - - return sb.toString(); - } - - /** - * A search and replace with multiple matching strings. - *

- * Useful when converting CRNL CR and NL all to a BR tag for example. - *

- *

- *


-   * String[] multi = { "\r\n", "\r", "\n" };
-   * content = StringHelper.replaceStringMulti(content, multi, "<br/>");
-   * 
- */ - public static String replaceStringMulti(String source, String[] match, String replace) { - return replaceStringMulti(source, match, replace, 30, 0, source.length()); - } - - /** - * Additionally specify an additional size estimate for the buffer plus - * start and end positions. - *

- * The start and end positions can limit the search and replace. Otherwise - * these default to startPos = 0 and endPos = source.length(). - *

- */ - public static String replaceStringMulti(String source, String[] match, String replace, - int additionalSize, int startPos, int endPos) { - - int shortestMatch = match[0].length(); - - char[] match0 = new char[match.length]; - for (int i = 0; i < match0.length; i++) { - match0[i] = match[i].charAt(0); - if (match[i].length() < shortestMatch) { - shortestMatch = match[i].length(); - } - } - - StringBuilder sb = new StringBuilder(source.length() + additionalSize); - - char sourceChar; - - int len = source.length(); - int lastMatch = endPos - shortestMatch; - - if (startPos > 0) { - sb.append(source.substring(0, startPos)); - } - - int matchCount; - - for (int i = startPos; i < len; i++) { - sourceChar = source.charAt(i); - if (i > lastMatch) { - sb.append(sourceChar); - } else { - matchCount = 0; - for (int k = 0; k < match0.length; k++) { - if (matchCount == 0 && sourceChar == match0[k]) { - if (match[k].length() + i <= len) { - - ++matchCount; - int j = 1; - for (; j < match[k].length(); j++) { - if (source.charAt(i + j) != match[k].charAt(j)) { - --matchCount; - break; - } - } - if (matchCount > 0) { - i = i + j - 1; - sb.append(replace); - break; - } - } - } - } - if (matchCount == 0) { - sb.append(sourceChar); - } - } - } - - return sb.toString(); - } - -} diff --git a/src/main/java/io/ebeaninternal/server/persist/dml/DmlBeanPersister.java b/src/main/java/io/ebeaninternal/server/persist/dml/DmlBeanPersister.java index 8f9851a10..86515483a 100644 --- a/src/main/java/io/ebeaninternal/server/persist/dml/DmlBeanPersister.java +++ b/src/main/java/io/ebeaninternal/server/persist/dml/DmlBeanPersister.java @@ -1,7 +1,7 @@ package io.ebeaninternal.server.persist.dml; +import io.ebean.util.StringHelper; import io.ebeaninternal.server.core.PersistRequestBean; -import io.ebeaninternal.server.lib.util.StringHelper; import io.ebeaninternal.server.persist.BeanPersister; import javax.persistence.PersistenceException; diff --git a/src/main/java/io/ebeaninternal/server/query/CQuery.java b/src/main/java/io/ebeaninternal/server/query/CQuery.java index b81b603a7..a9ac7a6c8 100644 --- a/src/main/java/io/ebeaninternal/server/query/CQuery.java +++ b/src/main/java/io/ebeaninternal/server/query/CQuery.java @@ -10,6 +10,7 @@ import io.ebean.bean.NodeUsageListener; import io.ebean.bean.ObjectGraphNode; import io.ebean.bean.PersistenceContext; import io.ebean.event.readaudit.ReadEvent; +import io.ebean.util.StringHelper; import io.ebeaninternal.api.SpiQuery; import io.ebeaninternal.api.SpiQuery.Mode; import io.ebeaninternal.api.SpiTransaction; @@ -22,7 +23,6 @@ import io.ebeaninternal.server.deploy.BeanCollectionHelpFactory; import io.ebeaninternal.server.deploy.BeanDescriptor; import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; import io.ebeaninternal.server.deploy.DbReadContext; -import io.ebeaninternal.server.lib.util.StringHelper; import io.ebeaninternal.server.type.DataBind; import io.ebeaninternal.server.type.DataReader; import org.slf4j.Logger; diff --git a/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java b/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java index 7b8c87a00..4600f70b4 100644 --- a/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java +++ b/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java @@ -1,9 +1,9 @@ package io.ebeaninternal.server.query; +import io.ebean.util.StringHelper; import io.ebeaninternal.server.deploy.BeanProperty; import io.ebeaninternal.server.deploy.DbSqlContext; import io.ebeaninternal.server.deploy.TableJoinColumn; -import io.ebeaninternal.server.lib.util.StringHelper; import io.ebeaninternal.server.util.ArrayStack; import java.util.ArrayList; diff --git a/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java b/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java index 0b128f432..3a95ab3a7 100644 --- a/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java +++ b/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java @@ -5,6 +5,7 @@ import io.ebean.bean.BeanCollection; import io.ebean.bean.EntityBean; import io.ebean.bean.EntityBeanIntercept; import io.ebean.bean.PersistenceContext; +import io.ebean.util.StringHelper; import io.ebeaninternal.api.SpiQuery; import io.ebeaninternal.api.SpiQuery.Mode; import io.ebeaninternal.server.deploy.BeanDescriptor; @@ -16,7 +17,6 @@ import io.ebeaninternal.server.deploy.DbSqlContext; import io.ebeaninternal.server.deploy.InheritInfo; import io.ebeaninternal.server.deploy.TableJoin; import io.ebeaninternal.server.deploy.id.IdBinder; -import io.ebeaninternal.server.lib.util.StringHelper; import java.sql.SQLException; import java.sql.Timestamp; diff --git a/src/main/java/io/ebeaninternal/server/querydefn/OrmQueryPropertiesParser.java b/src/main/java/io/ebeaninternal/server/querydefn/OrmQueryPropertiesParser.java index d4d70148d..9b774c9bc 100644 --- a/src/main/java/io/ebeaninternal/server/querydefn/OrmQueryPropertiesParser.java +++ b/src/main/java/io/ebeaninternal/server/querydefn/OrmQueryPropertiesParser.java @@ -1,7 +1,7 @@ package io.ebeaninternal.server.querydefn; import io.ebean.FetchConfig; -import io.ebeaninternal.server.lib.util.StringHelper; +import io.ebean.util.StringHelper; import java.util.LinkedHashSet; diff --git a/src/test/java/org/tests/text/json/TestTextJsonInsertUpdate.java b/src/test/java/org/tests/text/json/TestTextJsonInsertUpdate.java index 86ac5fca8..8f5b7de1f 100644 --- a/src/test/java/org/tests/text/json/TestTextJsonInsertUpdate.java +++ b/src/test/java/org/tests/text/json/TestTextJsonInsertUpdate.java @@ -3,7 +3,7 @@ package org.tests.text.json; import io.ebean.BaseTestCase; import io.ebean.Ebean; import io.ebean.text.json.JsonContext; -import io.ebeaninternal.server.lib.util.StringHelper; +import io.ebean.util.StringHelper; import org.tests.model.basic.Customer; import org.tests.model.basic.ResetBasicData; import org.junit.Test;