mirror of
https://github.com/apache/openjpa.git
synced 2025-02-21 09:35:40 +00:00
OPENJPA-2662 remove serp.util.Strings#split
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1759033 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0096a0ebd3
commit
66ad16fd85
@ -26,8 +26,8 @@ import org.apache.openjpa.jdbc.sql.SQLBuffer;
|
||||
import org.apache.openjpa.jdbc.sql.Select;
|
||||
import org.apache.openjpa.kernel.exps.ExpressionVisitor;
|
||||
import org.apache.openjpa.kernel.exps.Parameter;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Test if a string matches a regexp.
|
||||
@ -128,17 +128,19 @@ class MatchesExpression
|
||||
* @param escape the string to use to escape replacement
|
||||
* @return the replaced string
|
||||
*/
|
||||
private static String replaceEscape(String str, String from, String to,
|
||||
String escape) {
|
||||
String[] parts = Strings.split(str, from, Integer.MAX_VALUE);
|
||||
private static String replaceEscape(String str, String from, String to, String escape) {
|
||||
String[] parts = StringUtil.split(str, from, Integer.MAX_VALUE);
|
||||
StringBuilder repbuf = new StringBuilder();
|
||||
|
||||
boolean same = from.equals(to);
|
||||
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
if (i > 0) {
|
||||
// if the previous part ended with an escape character, then
|
||||
// escape the character and remove the previous escape;
|
||||
// this doesn't support any double-escaping or other more
|
||||
// sophisticated features
|
||||
if (!from.equals(to) && parts[i - 1].endsWith(escape)) {
|
||||
if (!same && parts[i - 1].endsWith(escape)) {
|
||||
repbuf.setLength(repbuf.length() - 1);
|
||||
repbuf.append(from);
|
||||
} else
|
||||
|
@ -32,12 +32,12 @@ import org.apache.openjpa.jdbc.schema.Column;
|
||||
import org.apache.openjpa.jdbc.sql.Joins;
|
||||
import org.apache.openjpa.lib.meta.SourceTracker;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.lib.xml.Commentable;
|
||||
import org.apache.openjpa.meta.JavaTypes;
|
||||
import org.apache.openjpa.meta.MetaDataContext;
|
||||
import org.apache.openjpa.meta.MetaDataModes;
|
||||
import org.apache.openjpa.util.MetaDataException;
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Mapping of a query result set to scalar and/or persistence-capable
|
||||
@ -409,7 +409,7 @@ public class QueryResultMapping
|
||||
*/
|
||||
private void resolveMapping(String path, Object id) {
|
||||
// build up path to second-to-last token
|
||||
String[] tokens = Strings.split(path, ".", 0);
|
||||
String[] tokens = StringUtil.split(path, ".", 0);
|
||||
List<MetaDataContext> rpath = new ArrayList<MetaDataContext>(tokens.length);
|
||||
ClassMapping candidate = getCandidateTypeMapping();
|
||||
FieldMapping fm = null;
|
||||
|
@ -85,6 +85,7 @@ import org.apache.openjpa.lib.util.Files;
|
||||
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.Options;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.meta.ClassMetaData;
|
||||
import org.apache.openjpa.meta.FieldMetaData;
|
||||
import org.apache.openjpa.meta.JavaTypes;
|
||||
@ -98,7 +99,6 @@ import org.apache.openjpa.util.MetaDataException;
|
||||
import serp.bytecode.BCClass;
|
||||
import serp.bytecode.BCClassLoader;
|
||||
import serp.bytecode.Project;
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Reverse-maps a schema into class mappings and the associated java
|
||||
@ -162,7 +162,7 @@ public class ReverseMappingTool
|
||||
InputStream in = ReverseMappingTool.class.getResourceAsStream
|
||||
("java-keywords.rsrc");
|
||||
try {
|
||||
String[] keywords = Strings.split(new BufferedReader
|
||||
String[] keywords = StringUtil.split(new BufferedReader
|
||||
(new InputStreamReader(in)).readLine(), ",", 0);
|
||||
|
||||
for (int i = 0; i < keywords.length; i += 2)
|
||||
@ -1507,7 +1507,7 @@ public class ReverseMappingTool
|
||||
if (_useSchema && name != null) {
|
||||
if (allUpperCase(name))
|
||||
name = name.toLowerCase();
|
||||
subs = Strings.split(name, "_", 0);
|
||||
subs = StringUtil.split(name, "_", 0);
|
||||
for (int i = 0; i < subs.length; i++)
|
||||
buf.append(StringUtils.capitalize(subs[i]));
|
||||
}
|
||||
@ -1515,7 +1515,7 @@ public class ReverseMappingTool
|
||||
name = replaceInvalidCharacters(table.getName());
|
||||
if (allUpperCase(name))
|
||||
name = name.toLowerCase();
|
||||
subs = Strings.split(name, "_", 0);
|
||||
subs = StringUtil.split(name, "_", 0);
|
||||
for (int i = 0; i < subs.length; i++) {
|
||||
// make sure the name can't conflict with generated id class names;
|
||||
// if the name would end in 'Id', make it end in 'Ident'
|
||||
@ -1539,7 +1539,7 @@ public class ReverseMappingTool
|
||||
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
String[] subs = Strings.split(name, "_", 0);
|
||||
String[] subs = StringUtil.split(name, "_", 0);
|
||||
for (int i = 0; i < subs.length; i++) {
|
||||
if (i > 0)
|
||||
subs[i] = StringUtils.capitalize(subs[i]);
|
||||
|
@ -49,11 +49,10 @@ import org.apache.openjpa.jdbc.schema.ForeignKey;
|
||||
import org.apache.openjpa.jdbc.schema.Table;
|
||||
import org.apache.openjpa.kernel.exps.Context;
|
||||
import org.apache.openjpa.lib.util.Closeable;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.meta.JavaTypes;
|
||||
import org.apache.openjpa.util.UnsupportedException;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* A {@link Result} implementation designed to be subclassed easily by
|
||||
* implementations. All <code>get<type></code> calls are delegated to
|
||||
@ -640,7 +639,7 @@ public abstract class AbstractResult
|
||||
return null;
|
||||
if (val instanceof Locale)
|
||||
return (Locale) val;
|
||||
String[] vals = Strings.split(val.toString(), "_", 0);
|
||||
String[] vals = StringUtil.split(val.toString(), "_", 0);
|
||||
if (vals.length < 2)
|
||||
throw new SQLException(val.toString());
|
||||
if (vals.length == 2)
|
||||
|
@ -109,6 +109,7 @@ import org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator;
|
||||
import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.Localizer.Message;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.meta.FieldMetaData;
|
||||
import org.apache.openjpa.meta.JavaTypes;
|
||||
import org.apache.openjpa.meta.ValueStrategies;
|
||||
@ -129,7 +130,6 @@ import org.apache.openjpa.util.StoreException;
|
||||
import org.apache.openjpa.util.UnsupportedException;
|
||||
import org.apache.openjpa.util.UserException;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Class which allows the creation of SQL dynamically, in a
|
||||
@ -894,7 +894,7 @@ public class DBDictionary
|
||||
if (StringUtils.isEmpty(str))
|
||||
return null;
|
||||
|
||||
String[] params = Strings.split(str, "_", 3);
|
||||
String[] params = StringUtil.split(str, "_", 3);
|
||||
if (params.length < 3)
|
||||
return null;
|
||||
return new Locale(params[0], params[1], params[2]);
|
||||
@ -4053,7 +4053,7 @@ public class DBDictionary
|
||||
schemaName = getSchemaNameForMetadata(sqlSchemaName);
|
||||
}
|
||||
|
||||
String[] types = Strings.split(tableTypes, ",", 0);
|
||||
String[] types = StringUtil.split(tableTypes, ",", 0);
|
||||
for (int i = 0; i < types.length; i++)
|
||||
types[i] = types[i].trim();
|
||||
|
||||
@ -4788,7 +4788,7 @@ public class DBDictionary
|
||||
try {
|
||||
String keywords = new BufferedReader(new InputStreamReader(in)).
|
||||
readLine();
|
||||
reservedWordSet.addAll(Arrays.asList(Strings.split
|
||||
reservedWordSet.addAll(Arrays.asList(StringUtil.split
|
||||
(keywords, ",", 0)));
|
||||
} catch (IOException ioe) {
|
||||
throw new GeneralException(ioe);
|
||||
@ -4798,31 +4798,26 @@ public class DBDictionary
|
||||
|
||||
// add additional reserved words set by user
|
||||
if (reservedWords != null)
|
||||
reservedWordSet.addAll(Arrays.asList(Strings.split
|
||||
(reservedWords.toUpperCase(), ",", 0)));
|
||||
reservedWordSet.addAll(Arrays.asList(StringUtil.split(reservedWords.toUpperCase(), ",", 0)));
|
||||
|
||||
// add system schemas set by user
|
||||
if (systemSchemas != null)
|
||||
systemSchemaSet.addAll(Arrays.asList(Strings.split
|
||||
(systemSchemas.toUpperCase(), ",", 0)));
|
||||
systemSchemaSet.addAll(Arrays.asList(StringUtil.split(systemSchemas.toUpperCase(), ",", 0)));
|
||||
|
||||
// add system tables set by user
|
||||
if (systemTables != null)
|
||||
systemTableSet.addAll(Arrays.asList(Strings.split
|
||||
(systemTables.toUpperCase(), ",", 0)));
|
||||
systemTableSet.addAll(Arrays.asList(StringUtil.split(systemTables.toUpperCase(), ",", 0)));
|
||||
|
||||
// add fixed size type names set by the user
|
||||
if (fixedSizeTypeNames != null)
|
||||
fixedSizeTypeNameSet.addAll(Arrays.asList(Strings.split
|
||||
(fixedSizeTypeNames.toUpperCase(), ",", 0)));
|
||||
fixedSizeTypeNameSet.addAll(Arrays.asList(StringUtil.split(fixedSizeTypeNames.toUpperCase(), ",", 0)));
|
||||
|
||||
// if user has unset sequence sql, null it out so we know sequences
|
||||
// aren't supported
|
||||
nextSequenceQuery = StringUtils.trimToNull(nextSequenceQuery);
|
||||
|
||||
if (selectWords != null)
|
||||
selectWordSet.addAll(Arrays.asList(Strings.split(selectWords
|
||||
.toUpperCase(), ",", 0)));
|
||||
selectWordSet.addAll(Arrays.asList(StringUtil.split(selectWords.toUpperCase(), ",", 0)));
|
||||
|
||||
// initialize the error codes
|
||||
SQLErrorCodeReader codeReader = new SQLErrorCodeReader();
|
||||
|
@ -39,10 +39,10 @@ import org.apache.openjpa.lib.conf.Configurable;
|
||||
import org.apache.openjpa.lib.conf.Configuration;
|
||||
import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
|
||||
import org.apache.openjpa.util.GeneralException;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Abstract {@link DataCache} implementation that provides various
|
||||
@ -55,7 +55,7 @@ import serp.util.Strings;
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class AbstractDataCache extends AbstractConcurrentEventManager
|
||||
implements DataCache, Configurable {
|
||||
|
||||
|
||||
protected CacheStatisticsSPI _stats = new CacheStatisticsImpl();
|
||||
|
||||
private static final BitSet EMPTY_BITSET = new BitSet(0);
|
||||
@ -522,31 +522,27 @@ public abstract class AbstractDataCache extends AbstractConcurrentEventManager
|
||||
public void setTypes(Set<String> types) {
|
||||
_includedTypes = types;
|
||||
if (log.isWarnEnabled())
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"Types",
|
||||
DataCacheMode.ENABLE_SELECTIVE.toString()}));
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"Types", DataCacheMode.ENABLE_SELECTIVE.toString()}));
|
||||
}
|
||||
|
||||
public void setTypes(String types) {
|
||||
_includedTypes =
|
||||
StringUtils.isEmpty(types) ? null : new HashSet<String>(Arrays.asList(Strings.split(types, ";", 0)));
|
||||
StringUtils.isEmpty(types) ? null : new HashSet<>(Arrays.asList(StringUtil.split(types, ";", 0)));
|
||||
if (log.isWarnEnabled())
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"Types",
|
||||
DataCacheMode.ENABLE_SELECTIVE.toString()}));
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"Types", DataCacheMode.ENABLE_SELECTIVE.toString()}));
|
||||
}
|
||||
|
||||
public void setExcludedTypes(Set<String> types) {
|
||||
_excludedTypes = types;
|
||||
if (log.isWarnEnabled())
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"ExcludeTypes",
|
||||
DataCacheMode.DISABLE_SELECTIVE.toString()}));
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"ExcludeTypes", DataCacheMode.DISABLE_SELECTIVE.toString()}));
|
||||
}
|
||||
|
||||
public void setExcludedTypes(String types) {
|
||||
_excludedTypes =
|
||||
StringUtils.isEmpty(types) ? null : new HashSet<String>(Arrays.asList(Strings.split(types, ";", 0)));
|
||||
StringUtils.isEmpty(types) ? null : new HashSet<>(Arrays.asList(StringUtil.split(types, ";", 0)));
|
||||
if (log.isWarnEnabled())
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"ExcludeTypes",
|
||||
DataCacheMode.DISABLE_SELECTIVE.toString()}));
|
||||
log.warn(s_loc.get("recommend_jpa2_caching", new Object[]{"ExcludeTypes", DataCacheMode.DISABLE_SELECTIVE.toString()}));
|
||||
}
|
||||
|
||||
public DataCache selectCache(OpenJPAStateManager sm) {
|
||||
|
@ -34,10 +34,10 @@ import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.util.Clearable;
|
||||
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.util.InvalidStateException;
|
||||
import org.apache.openjpa.util.UserException;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Cron-style clearable eviction. Understands schedules based on cron format:
|
||||
@ -223,7 +223,7 @@ public class ClearableScheduler implements Runnable {
|
||||
private int[] parse(String token, int min, int max) {
|
||||
if ("*".equals(token.trim()))
|
||||
return WILDCARD;
|
||||
String[] tokens = Strings.split(token, ",", 0);
|
||||
String[] tokens = StringUtil.split(token, ",", 0);
|
||||
int [] times = new int[tokens.length];
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
try {
|
||||
|
@ -23,9 +23,9 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.openjpa.kernel.OpenJPAStateManager;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.meta.ClassMetaData;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* A cache distribution policy based on the type of the managed objects.
|
||||
@ -78,7 +78,7 @@ public class TypeBasedCacheDistributionPolicy extends DefaultCacheDistributionPo
|
||||
private Set<String> parseNames(String types) {
|
||||
if (StringUtils.isEmpty(types))
|
||||
return Collections.emptySet();
|
||||
String[] names = Strings.split(types, ";", 0);
|
||||
String[] names = StringUtil.split(types, ";", 0);
|
||||
Set<String> set = new HashSet<String>();
|
||||
set.addAll(Arrays.asList(names));
|
||||
|
||||
|
@ -50,12 +50,12 @@ import org.apache.openjpa.lib.conf.Configurable;
|
||||
import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.util.GeneralException;
|
||||
import org.apache.openjpa.util.InternalException;
|
||||
import org.apache.openjpa.util.Serialization;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* TCP-based implementation of {@link RemoteCommitProvider} that
|
||||
@ -220,7 +220,7 @@ public class TCPRemoteCommitProvider
|
||||
for (Iterator iter = _addresses.iterator(); iter.hasNext();) {
|
||||
((HostAddress) iter.next()).close();
|
||||
}
|
||||
String[] toks = Strings.split(names, ";", 0);
|
||||
String[] toks = StringUtil.split(names, ";", 0);
|
||||
_addresses = new ArrayList(toks.length);
|
||||
|
||||
InetAddress localhost = InetAddress.getLocalHost();
|
||||
|
@ -37,6 +37,7 @@ import org.apache.openjpa.kernel.exps.AggregateListener;
|
||||
import org.apache.openjpa.kernel.exps.FilterListener;
|
||||
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.meta.ClassMetaData;
|
||||
import org.apache.openjpa.meta.JavaTypes;
|
||||
import org.apache.openjpa.util.InternalException;
|
||||
@ -839,7 +840,7 @@ public class Filters {
|
||||
|
||||
Exception cause = null;
|
||||
if (hint instanceof String) {
|
||||
String[] clss = Strings.split((String) hint, ",", 0);
|
||||
String[] clss = StringUtil.split((String) hint, ",", 0);
|
||||
AggregateListener[] aggs = new AggregateListener[clss.length];
|
||||
try {
|
||||
for (int i = 0; i < clss.length; i++)
|
||||
@ -902,7 +903,7 @@ public class Filters {
|
||||
|
||||
Exception cause = null;
|
||||
if (hint instanceof String) {
|
||||
String[] clss = Strings.split((String) hint, ",", 0);
|
||||
String[] clss = StringUtil.split((String) hint, ",", 0);
|
||||
FilterListener[] filts = new FilterListener[clss.length];
|
||||
try {
|
||||
for (int i = 0; i < clss.length; i++)
|
||||
@ -955,7 +956,7 @@ public class Filters {
|
||||
}
|
||||
}
|
||||
Reflection.set(target, setter, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given string assuming it is a JDBC key expression. Extracts the
|
||||
|
@ -60,6 +60,7 @@ import org.apache.openjpa.lib.meta.ZipStreamMetaDataIterator;
|
||||
import org.apache.openjpa.lib.util.Files;
|
||||
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.util.GeneralException;
|
||||
import org.apache.openjpa.util.UserException;
|
||||
import serp.util.Strings;
|
||||
@ -102,8 +103,8 @@ public abstract class AbstractCFMetaDataFactory
|
||||
if (StringUtils.isEmpty(files))
|
||||
this.files = null;
|
||||
else {
|
||||
String[] strs = Strings.split(files, ";", 0);
|
||||
this.files = new HashSet<File>((int) (strs.length * 1.33 + 1));
|
||||
String[] strs = StringUtil.split(files, ";", 0);
|
||||
this.files = new HashSet<>((int) (strs.length * 1.33 + 1));
|
||||
|
||||
File file;
|
||||
for (int i = 0; i < strs.length; i++) {
|
||||
@ -130,7 +131,7 @@ public abstract class AbstractCFMetaDataFactory
|
||||
if (StringUtils.isEmpty(urls))
|
||||
this.urls = null;
|
||||
else {
|
||||
String[] strs = Strings.split(urls, ";", 0);
|
||||
String[] strs = StringUtil.split(urls, ";", 0);
|
||||
this.urls = new HashSet<URL>((int) (strs.length * 1.33 + 1));
|
||||
try {
|
||||
for (int i = 0; i < strs.length; i++)
|
||||
@ -155,7 +156,7 @@ public abstract class AbstractCFMetaDataFactory
|
||||
public void setResources(String rsrcs) {
|
||||
// keep list mutable so subclasses can add implicit locations
|
||||
this.rsrcs = (StringUtils.isEmpty(rsrcs)) ? null
|
||||
: new ArrayList<String>(Arrays.asList(Strings.split(rsrcs, ";", 0)));
|
||||
: new ArrayList<String>(Arrays.asList(StringUtil.split(rsrcs, ";", 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +174,7 @@ public abstract class AbstractCFMetaDataFactory
|
||||
public void setClasspathScan(String cpath) {
|
||||
// keep list mutable so subclasses can add implicit locations
|
||||
this.cpath = (StringUtils.isEmpty(cpath)) ? null
|
||||
: new ArrayList<String>(Arrays.asList(Strings.split(cpath, ";", 0)));
|
||||
: new ArrayList<String>(Arrays.asList(StringUtil.split(cpath, ";", 0)));
|
||||
}
|
||||
|
||||
public boolean store(ClassMetaData[] metas, QueryMetaData[] queries,
|
||||
@ -942,7 +943,7 @@ public abstract class AbstractCFMetaDataFactory
|
||||
* Decodes a URL-encoded path string. For example, an encoded
|
||||
* space (%20) is decoded into a normal space (' ') character.
|
||||
* Added via OPENJPA-2102.
|
||||
* @param String encoded - the encoded URL string
|
||||
* @param s - the encoded URL string
|
||||
* @return String decoded - the decoded string.
|
||||
*/
|
||||
public static String decode(String s) {
|
||||
|
@ -29,7 +29,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.openjpa.conf.OpenJPAConfiguration;
|
||||
import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.meta.ClassArgParser;
|
||||
import serp.util.Strings;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Abstract {@link MetaDataFactory} that provides default implementations
|
||||
@ -61,7 +61,7 @@ public abstract class AbstractMetaDataFactory
|
||||
*/
|
||||
public void setTypes(String types) {
|
||||
this.types = (StringUtils.isEmpty(types)) ? null
|
||||
: new HashSet(Arrays.asList(Strings.split(types, ";", 0)));
|
||||
: new HashSet(Arrays.asList(StringUtil.split(types, ";", 0)));
|
||||
}
|
||||
|
||||
public void setRepository(MetaDataRepository repos) {
|
||||
|
@ -31,7 +31,8 @@ import org.apache.openjpa.conf.OpenJPAConfiguration;
|
||||
import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.StringDistance;
|
||||
import serp.util.Strings;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Vendor extensions. This class is thread safe for reads, but not for
|
||||
@ -328,7 +329,7 @@ public abstract class Extensions
|
||||
String prefixes = _loc.get("extension-datastore-prefix").getMessage();
|
||||
String[] allowedPrefixes = null;
|
||||
if (prefixes != null)
|
||||
allowedPrefixes = Strings.split(prefixes, ",", 0);
|
||||
allowedPrefixes = StringUtil.split(prefixes, ",", 0);
|
||||
|
||||
Object next;
|
||||
String key;
|
||||
|
@ -56,6 +56,7 @@ import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||
import org.apache.openjpa.lib.util.JavaVersions;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.Options;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.lib.xml.Commentable;
|
||||
import org.apache.openjpa.util.Exceptions;
|
||||
import org.apache.openjpa.util.InternalException;
|
||||
@ -1167,7 +1168,7 @@ public class FieldMetaData
|
||||
if (_orderDec == null)
|
||||
_orders = getRepository().EMPTY_ORDERS;
|
||||
else {
|
||||
String[] decs = Strings.split(_orderDec, ",", 0);
|
||||
String[] decs = StringUtil.split(_orderDec, ",", 0);
|
||||
Order[] orders = getRepository().newOrderArray(decs.length);
|
||||
int spc;
|
||||
boolean asc;
|
||||
|
@ -59,6 +59,7 @@ import org.apache.openjpa.lib.util.Options;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import serp.bytecode.BCClass;
|
||||
import serp.bytecode.BCField;
|
||||
import serp.bytecode.BCMethod;
|
||||
@ -172,7 +173,7 @@ public class ProxyManagerImpl
|
||||
*/
|
||||
public void setUnproxyable(String clsNames) {
|
||||
if (clsNames != null)
|
||||
_unproxyable.addAll(Arrays.asList(Strings.split(clsNames, ";", 0)));
|
||||
_unproxyable.addAll(Arrays.asList(StringUtil.split(clsNames, ";", 0)));
|
||||
}
|
||||
|
||||
public Object copyArray(Object orig) {
|
||||
|
@ -67,6 +67,7 @@ import org.apache.openjpa.lib.util.MultiClassLoader;
|
||||
import org.apache.openjpa.lib.util.ParseException;
|
||||
import org.apache.openjpa.lib.util.Services;
|
||||
import org.apache.openjpa.lib.util.StringDistance;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
@ -535,7 +536,7 @@ public class ConfigurationImpl
|
||||
for (int i = 0; i < aliases.size(); i += 2)
|
||||
allowed.add(aliases.get(i));
|
||||
}
|
||||
String[] vals = Strings.split(findLocalized(prop
|
||||
String[] vals = StringUtil.split(findLocalized(prop
|
||||
+ "-values", false, val.getScope()), ",", 0);
|
||||
for (int i = 0; i < vals.length; i++)
|
||||
if (!aliases.contains(vals[i]))
|
||||
|
@ -43,9 +43,9 @@ import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.Options;
|
||||
import org.apache.openjpa.lib.util.ParseException;
|
||||
import org.apache.openjpa.lib.util.StringDistance;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
|
||||
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Utility methods dealing with configuration.
|
||||
@ -581,7 +581,7 @@ public class Configurations {
|
||||
return opts;
|
||||
|
||||
try {
|
||||
String[] props = Strings.split(properties, ",", 0);
|
||||
String[] props = StringUtil.split(properties, ",", 0);
|
||||
int idx;
|
||||
char quote;
|
||||
String prop;
|
||||
|
@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.lib.util.ParseException;
|
||||
|
||||
import serp.util.Strings;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
|
||||
/**
|
||||
* A comma-separated list of string values.
|
||||
@ -120,11 +120,11 @@ public class StringListValue extends Value {
|
||||
}
|
||||
|
||||
protected String getInternalString() {
|
||||
return Strings.join(_values, ", ");
|
||||
return StringUtils.join(_values, ", ");
|
||||
}
|
||||
|
||||
protected void setInternalString(String val) {
|
||||
String[] vals = Strings.split(val, ",", 0);
|
||||
String[] vals = StringUtil.split(val, ",", 0);
|
||||
if (vals != null) {
|
||||
for (int i = 0; i < vals.length; i++)
|
||||
vals[i] = vals[i].trim();
|
||||
|
@ -27,7 +27,7 @@ import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||
|
||||
import serp.util.Strings;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Iterator over directories in the classpath.
|
||||
@ -53,7 +53,7 @@ public class ClasspathMetaDataIterator extends MetaDataIteratorChain {
|
||||
Properties props = AccessController.doPrivileged(
|
||||
J2DoPrivHelper.getPropertiesAction());
|
||||
String path = props.getProperty("java.class.path");
|
||||
String[] tokens = Strings.split(path,
|
||||
String[] tokens = StringUtil.split(path,
|
||||
props.getProperty("path.separator"), 0);
|
||||
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
|
@ -222,7 +222,7 @@ public class Options extends TypedProperties {
|
||||
else if (values.length == 1)
|
||||
strValues = new String[]{ entry.getValue().toString() };
|
||||
else
|
||||
strValues = Strings.split(entry.getValue().toString(), ",", 0);
|
||||
strValues = StringUtil.split(entry.getValue().toString(), ",", 0);
|
||||
|
||||
// convert the string values into parameter values, if not
|
||||
// enough string values repeat last one for rest
|
||||
@ -303,7 +303,7 @@ public class Options extends TypedProperties {
|
||||
// unfortunately we can't use bean properties for setters; any
|
||||
// setter with more than 1 argument is ignored; calculate setter and getter
|
||||
// name to look for
|
||||
String[] find = Strings.split(key, ".", 2);
|
||||
String[] find = StringUtil.split(key, ".", 2);
|
||||
String base = StringUtils.capitalize(find[0]);
|
||||
String set = "set" + base;
|
||||
String get = "get" + base;
|
||||
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.openjpa.lib.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class StringUtil {
|
||||
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
private StringUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the given string on the given token. Follows the semantics
|
||||
* of the Java 1.4 {@link String#split(String,int)} method, but does
|
||||
* not treat the given token as a regular expression.
|
||||
*/
|
||||
public static String[] split(String str, String token, int max) {
|
||||
if (str == null || str.length() == 0) {
|
||||
return EMPTY_STRING_ARRAY;
|
||||
}
|
||||
if (token == null || token.length() == 0) {
|
||||
throw new IllegalArgumentException("token: [" + token + "]");
|
||||
}
|
||||
|
||||
// split on token
|
||||
List<String> ret = new ArrayList<>();
|
||||
int start = 0;
|
||||
int len = str.length();
|
||||
int tlen = token.length();
|
||||
|
||||
int pos = 0;
|
||||
while (pos != -1) {
|
||||
pos = str.indexOf(token, start);
|
||||
if (pos != -1) {
|
||||
ret.add(str.substring(start, pos));
|
||||
start = pos + tlen;
|
||||
}
|
||||
}
|
||||
if (start < len) {
|
||||
ret.add(str.substring(start));
|
||||
} else if (start == len) {
|
||||
ret.add("");
|
||||
}
|
||||
|
||||
|
||||
// now take max into account; this isn't the most efficient way
|
||||
// of doing things since we split the maximum number of times
|
||||
// regardless of the given parameters, but it makes things easy
|
||||
if (max == 0) {
|
||||
int size = ret.size();
|
||||
// discard any trailing empty splits
|
||||
while (ret.get(--size).isEmpty()) {
|
||||
ret.remove(size);
|
||||
}
|
||||
} else if (max > 0 && ret.size() > max) {
|
||||
// move all splits over max into the last split
|
||||
StringBuilder sb = new StringBuilder(256);
|
||||
sb.append(ret.get(max-1));
|
||||
ret.remove(max-1);
|
||||
while (ret.size() >= max) {
|
||||
sb.append(token).append(ret.get(max-1));
|
||||
ret.remove(max-1);
|
||||
}
|
||||
ret.add(sb.toString());
|
||||
}
|
||||
return ret.toArray(new String[ret.size()]);
|
||||
}
|
||||
|
||||
}
|
@ -19,9 +19,6 @@ package org.apache.openjpa.lib.util;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* TODO remove again. Just to test serp.ClassUtil.toClass
|
||||
*/
|
||||
public class ClassUtilTest {
|
||||
|
||||
@Test
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.openjpa.lib.util;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringUtilTest {
|
||||
|
||||
@Test
|
||||
public void testStringSplit() {
|
||||
String val = " a b c \n d \n \n";
|
||||
String[] jsplit = val.split(" ");
|
||||
String[] split1 = StringUtil.split(val, " ", 0);
|
||||
String[] split2 = StringUtil.split(val, " ", 30);
|
||||
|
||||
String[] split3 = StringUtil.split(val, " ", 3);
|
||||
Assert.assertEquals(3, split3.length);
|
||||
Assert.assertEquals("", split3[0]);
|
||||
Assert.assertEquals("a", split3[1]);
|
||||
Assert.assertEquals("b c \n d \n \n", split3[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringSplitEnding() {
|
||||
String val = "a%B%C%";
|
||||
String[] jsplit = val.split("%");
|
||||
String[] ssplit = StringUtil.split(val, "%", Integer.MAX_VALUE);
|
||||
Assert.assertEquals(4, ssplit.length);
|
||||
Assert.assertArrayEquals(ssplit, new String[]{"a", "B", "C", ""});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringSplitFatTokenEnding() {
|
||||
String val = "a-.-B-.-C-.-";
|
||||
String[] jsplit = val.split("-.-");
|
||||
String[] ssplit = StringUtil.split(val, "-.-", Integer.MAX_VALUE);
|
||||
Assert.assertEquals(4, ssplit.length);
|
||||
Assert.assertArrayEquals(ssplit, new String[]{"a", "B", "C", ""});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("only needed for manual performance tests")
|
||||
public void stringSplitPerformanceTest() {
|
||||
String val = " asdfsfsfsfafasdf basdfasf cs d efdfdfdfdfdfdfdf ghai asdf " +
|
||||
"asdflkj lökajdf lkölkasdflk jklö adfk \n adslsfl \t adsfsfd";
|
||||
|
||||
long start = System.nanoTime();
|
||||
for (int i = 1; i < 10000000; i++) {
|
||||
StringUtil.split(val, "sd", 0);
|
||||
//X val.split("sd");
|
||||
//X serp.util.Strings.split(val, "sd", 0);
|
||||
}
|
||||
|
||||
long stop = System.nanoTime();
|
||||
System.out.println("took: " + TimeUnit.NANOSECONDS.toMillis(stop - start));
|
||||
}
|
||||
}
|
@ -29,6 +29,8 @@ import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Tests the {@link XMLWriter} by comparing the results of passing the
|
||||
@ -70,7 +72,7 @@ public class TestXMLWriter extends TestCase {
|
||||
}
|
||||
|
||||
private String fixNewline(String str) {
|
||||
return serp.util.Strings.join(serp.util.Strings.split
|
||||
return StringUtils.join(StringUtil.split
|
||||
(str, "\r\n", -1), "\n");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user