提交 027787d0 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use String.isEmpty() in some places

上级 46b7cd0f
...@@ -74,7 +74,7 @@ public class CreateUser extends DefineCommand { ...@@ -74,7 +74,7 @@ public class CreateUser extends DefineCommand {
char[] passwordChars = pwd == null ? new char[0] : pwd.toCharArray(); char[] passwordChars = pwd == null ? new char[0] : pwd.toCharArray();
byte[] userPasswordHash; byte[] userPasswordHash;
String userName = user.getName(); String userName = user.getName();
if (userName.length() == 0 && passwordChars.length == 0) { if (userName.isEmpty() && passwordChars.length == 0) {
userPasswordHash = new byte[0]; userPasswordHash = new byte[0];
} else { } else {
userPasswordHash = SHA256.getKeyPasswordHash(userName, passwordChars); userPasswordHash = SHA256.getKeyPasswordHash(userName, passwordChars);
......
...@@ -252,7 +252,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -252,7 +252,7 @@ public class ConnectionInfo implements Cloneable {
url = url.substring(0, idx); url = url.substring(0, idx);
String[] list = StringUtils.arraySplit(settings, ';', false); String[] list = StringUtils.arraySplit(settings, ';', false);
for (String setting : list) { for (String setting : list) {
if (setting.length() == 0) { if (setting.isEmpty()) {
continue; continue;
} }
int equal = setting.indexOf('='); int equal = setting.indexOf('=');
...@@ -326,7 +326,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -326,7 +326,7 @@ public class ConnectionInfo implements Cloneable {
if (passwordHash) { if (passwordHash) {
return StringUtils.convertHexToBytes(new String(password)); return StringUtils.convertHexToBytes(new String(password));
} }
if (userName.length() == 0 && password.length == 0) { if (userName.isEmpty() && password.length == 0) {
return new byte[0]; return new byte[0];
} }
return SHA256.getKeyPasswordHash(userName, password); return SHA256.getKeyPasswordHash(userName, password);
...@@ -643,7 +643,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -643,7 +643,7 @@ public class ConnectionInfo implements Cloneable {
private static String remapURL(String url) { private static String remapURL(String url) {
String urlMap = SysProperties.URL_MAP; String urlMap = SysProperties.URL_MAP;
if (urlMap != null && urlMap.length() > 0) { if (urlMap != null && !urlMap.isEmpty()) {
try { try {
SortedProperties prop; SortedProperties prop;
prop = SortedProperties.loadProperties(urlMap); prop = SortedProperties.loadProperties(urlMap);
...@@ -653,7 +653,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -653,7 +653,7 @@ public class ConnectionInfo implements Cloneable {
prop.store(urlMap); prop.store(urlMap);
} else { } else {
url2 = url2.trim(); url2 = url2.trim();
if (url2.length() > 0) { if (!url2.isEmpty()) {
return url2; return url2;
} }
} }
......
...@@ -642,7 +642,7 @@ public class Database implements DataHandler { ...@@ -642,7 +642,7 @@ public class Database implements DataHandler {
n = tokenizer.nextToken(); n = tokenizer.nextToken();
} }
} }
if (n == null || n.length() == 0) { if (n == null || n.isEmpty()) {
n = "unnamed"; n = "unnamed";
} }
return dbSettings.databaseToUpper ? StringUtils.toUpperEnglish(n) : n; return dbSettings.databaseToUpper ? StringUtils.toUpperEnglish(n) : n;
...@@ -2274,7 +2274,7 @@ public class Database implements DataHandler { ...@@ -2274,7 +2274,7 @@ public class Database implements DataHandler {
} }
public void setEventListenerClass(String className) { public void setEventListenerClass(String className) {
if (className == null || className.length() == 0) { if (className == null || className.isEmpty()) {
eventListener = null; eventListener = null;
} else { } else {
try { try {
......
...@@ -72,7 +72,7 @@ public class CompareLike extends Condition { ...@@ -72,7 +72,7 @@ public class CompareLike extends Condition {
} }
private static Character getEscapeChar(String s) { private static Character getEscapeChar(String s) {
return s == null || s.length() == 0 ? null : s.charAt(0); return s == null || s.isEmpty() ? null : s.charAt(0);
} }
@Override @Override
......
...@@ -681,7 +681,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -681,7 +681,7 @@ public class Function extends Expression implements FunctionCall {
// string // string
case ASCII: { case ASCII: {
String s = v0.getString(); String s = v0.getString();
if (s.length() == 0) { if (s.isEmpty()) {
result = ValueNull.INSTANCE; result = ValueNull.INSTANCE;
} else { } else {
result = ValueInt.get(s.charAt(0)); result = ValueInt.get(s.charAt(0));
...@@ -2710,19 +2710,17 @@ public class Function extends Expression implements FunctionCall { ...@@ -2710,19 +2710,17 @@ public class Function extends Expression implements FunctionCall {
String fieldDelimiter, String escapeCharacter) { String fieldDelimiter, String escapeCharacter) {
if (fieldSeparator != null) { if (fieldSeparator != null) {
csv.setFieldSeparatorWrite(fieldSeparator); csv.setFieldSeparatorWrite(fieldSeparator);
if (fieldSeparator.length() > 0) { if (!fieldSeparator.isEmpty()) {
char fs = fieldSeparator.charAt(0); char fs = fieldSeparator.charAt(0);
csv.setFieldSeparatorRead(fs); csv.setFieldSeparatorRead(fs);
} }
} }
if (fieldDelimiter != null) { if (fieldDelimiter != null) {
char fd = fieldDelimiter.length() == 0 ? char fd = fieldDelimiter.isEmpty() ? 0 : fieldDelimiter.charAt(0);
0 : fieldDelimiter.charAt(0);
csv.setFieldDelimiter(fd); csv.setFieldDelimiter(fd);
} }
if (escapeCharacter != null) { if (escapeCharacter != null) {
char ec = escapeCharacter.length() == 0 ? char ec = escapeCharacter.isEmpty() ? 0 : escapeCharacter.charAt(0);
0 : escapeCharacter.charAt(0);
csv.setEscapeCharacter(ec); csv.setEscapeCharacter(ec);
} }
} }
......
...@@ -3093,14 +3093,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -3093,14 +3093,14 @@ public class JdbcDatabaseMetaData extends TraceObject implements
} }
private static String getSchemaPattern(String pattern) { private static String getSchemaPattern(String pattern) {
return pattern == null ? "%" : pattern.length() == 0 ? return pattern == null ? "%" : pattern.isEmpty() ?
Constants.SCHEMA_MAIN : pattern; Constants.SCHEMA_MAIN : pattern;
} }
private static String getCatalogPattern(String catalogPattern) { private static String getCatalogPattern(String catalogPattern) {
// Workaround for OpenOffice: getColumns is called with "" as the // Workaround for OpenOffice: getColumns is called with "" as the
// catalog // catalog
return catalogPattern == null || catalogPattern.length() == 0 ? return catalogPattern == null || catalogPattern.isEmpty() ?
"%" : catalogPattern; "%" : catalogPattern;
} }
......
...@@ -180,7 +180,7 @@ public class PgServerThread implements Runnable { ...@@ -180,7 +180,7 @@ public class PgServerThread implements Runnable {
" (" + (version >> 16) + "." + (version & 0xff) + ")"); " (" + (version >> 16) + "." + (version & 0xff) + ")");
while (true) { while (true) {
String param = readString(); String param = readString();
if (param.length() == 0) { if (param.isEmpty()) {
break; break;
} }
String value = readString(); String value = readString();
......
...@@ -240,14 +240,15 @@ public class PageParser { ...@@ -240,14 +240,15 @@ public class PageParser {
if (s == null) { if (s == null) {
return null; return null;
} }
int length = s.length();
if (convertBreakAndSpace) { if (convertBreakAndSpace) {
if (s.length() == 0) { if (length == 0) {
return " "; return " ";
} }
} }
StringBuilder buff = new StringBuilder(s.length()); StringBuilder buff = new StringBuilder(length);
boolean convertSpace = true; boolean convertSpace = true;
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < length; i++) {
char c = s.charAt(i); char c = s.charAt(i);
if (c == ' ' || c == '\t') { if (c == ' ' || c == '\t') {
// convert tabs into spaces // convert tabs into spaces
...@@ -312,11 +313,12 @@ public class PageParser { ...@@ -312,11 +313,12 @@ public class PageParser {
if (s == null) { if (s == null) {
return null; return null;
} }
if (s.length() == 0) { int length = s.length();
if (length == 0) {
return ""; return "";
} }
StringBuilder buff = new StringBuilder(s.length()); StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < s.length(); i++) { for (int i = 0; i < length; i++) {
char c = s.charAt(i); char c = s.charAt(i);
switch (c) { switch (c) {
case '"': case '"':
......
...@@ -167,7 +167,7 @@ class WebSession { ...@@ -167,7 +167,7 @@ class WebSession {
return; return;
} }
sql = sql.trim(); sql = sql.trim();
if (sql.length() == 0) { if (sql.isEmpty()) {
return; return;
} }
if (commandHistory.size() > MAX_HISTORY) { if (commandHistory.size() > MAX_HISTORY) {
......
...@@ -51,7 +51,7 @@ public class FilePathZip extends FilePath { ...@@ -51,7 +51,7 @@ public class FilePathZip extends FilePath {
public boolean exists() { public boolean exists() {
try { try {
String entryName = getEntryName(); String entryName = getEntryName();
if (entryName.length() == 0) { if (entryName.isEmpty()) {
return true; return true;
} }
try (ZipFile file = openZipFile()) { try (ZipFile file = openZipFile()) {
...@@ -88,7 +88,7 @@ public class FilePathZip extends FilePath { ...@@ -88,7 +88,7 @@ public class FilePathZip extends FilePath {
public boolean isDirectory() { public boolean isDirectory() {
try { try {
String entryName = getEntryName(); String entryName = getEntryName();
if (entryName.length() == 0) { if (entryName.isEmpty()) {
return true; return true;
} }
try (ZipFile file = openZipFile()) { try (ZipFile file = openZipFile()) {
......
...@@ -108,7 +108,7 @@ public class Backup extends Tool { ...@@ -108,7 +108,7 @@ public class Backup extends Tool {
private void process(String zipFileName, String directory, String db, private void process(String zipFileName, String directory, String db,
boolean quiet) throws SQLException { boolean quiet) throws SQLException {
List<String> list; List<String> list;
boolean allFiles = db != null && db.length() == 0; boolean allFiles = db != null && db.isEmpty();
if (allFiles) { if (allFiles) {
list = FileUtils.newDirectoryStream(directory); list = FileUtils.newDirectoryStream(directory);
} else { } else {
......
...@@ -228,7 +228,7 @@ public class Csv implements SimpleRowSource { ...@@ -228,7 +228,7 @@ public class Csv implements SimpleRowSource {
for (int i = 0; i < columnNames.length; i++) { for (int i = 0; i < columnNames.length; i++) {
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
String n = columnNames[i]; String n = columnNames[i];
if (n == null || n.length() == 0) { if (n == null || n.isEmpty()) {
buff.append('C').append(i + 1); buff.append('C').append(i + 1);
} else { } else {
buff.append(n); buff.append(n);
...@@ -350,7 +350,7 @@ public class Csv implements SimpleRowSource { ...@@ -350,7 +350,7 @@ public class Csv implements SimpleRowSource {
list.add(v); list.add(v);
} }
} else { } else {
if (v.length() == 0) { if (v.isEmpty()) {
v = "COLUMN" + list.size(); v = "COLUMN" + list.size();
} else if (!caseSensitiveColumnNames && isSimpleColumnName(v)) { } else if (!caseSensitiveColumnNames && isSimpleColumnName(v)) {
v = StringUtils.toUpperEnglish(v); v = StringUtils.toUpperEnglish(v);
...@@ -827,13 +827,13 @@ public class Csv implements SimpleRowSource { ...@@ -827,13 +827,13 @@ public class Csv implements SimpleRowSource {
String charset = null; String charset = null;
String[] keyValuePairs = StringUtils.arraySplit(options, ' ', false); String[] keyValuePairs = StringUtils.arraySplit(options, ' ', false);
for (String pair : keyValuePairs) { for (String pair : keyValuePairs) {
if (pair.length() == 0) { if (pair.isEmpty()) {
continue; continue;
} }
int index = pair.indexOf('='); int index = pair.indexOf('=');
String key = StringUtils.trim(pair.substring(0, index), true, true, " "); String key = StringUtils.trim(pair.substring(0, index), true, true, " ");
String value = pair.substring(index + 1); String value = pair.substring(index + 1);
char ch = value.length() == 0 ? 0 : value.charAt(0); char ch = value.isEmpty() ? 0 : value.charAt(0);
if (isParam(key, "escape", "esc", "escapeCharacter")) { if (isParam(key, "escape", "esc", "escapeCharacter")) {
setEscapeCharacter(ch); setEscapeCharacter(ch);
} else if (isParam(key, "fieldDelimiter", "fieldDelim")) { } else if (isParam(key, "fieldDelimiter", "fieldDelim")) {
......
...@@ -205,7 +205,7 @@ public class RunScript extends Tool { ...@@ -205,7 +205,7 @@ public class RunScript extends Tool {
break; break;
} }
String trim = sql.trim(); String trim = sql.trim();
if (trim.length() == 0) { if (trim.isEmpty()) {
continue; continue;
} }
if (trim.startsWith("@") && StringUtils.toUpperEnglish(trim). if (trim.startsWith("@") && StringUtils.toUpperEnglish(trim).
......
...@@ -220,7 +220,7 @@ public class Shell extends Tool implements Runnable { ...@@ -220,7 +220,7 @@ public class Shell extends Tool implements Runnable {
break; break;
} }
String trimmed = line.trim(); String trimmed = line.trim();
if (trimmed.length() == 0) { if (trimmed.isEmpty()) {
continue; continue;
} }
boolean end = trimmed.endsWith(";"); boolean end = trimmed.endsWith(";");
...@@ -366,7 +366,7 @@ public class Shell extends Tool implements Runnable { ...@@ -366,7 +366,7 @@ public class Shell extends Tool implements Runnable {
println("[Enter] Hide"); println("[Enter] Hide");
print("Password "); print("Password ");
String password = readLine(); String password = readLine();
if (password.length() == 0) { if (password.isEmpty()) {
password = readPassword(); password = readPassword();
} }
conn = JdbcUtils.getConnection(driver, url, user, password); conn = JdbcUtils.getConnection(driver, url, user, password);
...@@ -433,7 +433,7 @@ public class Shell extends Tool implements Runnable { ...@@ -433,7 +433,7 @@ public class Shell extends Tool implements Runnable {
private String readLine(String defaultValue) throws IOException { private String readLine(String defaultValue) throws IOException {
String s = readLine(); String s = readLine();
return s.length() == 0 ? defaultValue : s; return s.isEmpty() ? defaultValue : s;
} }
private String readLine() throws IOException { private String readLine() throws IOException {
......
...@@ -155,7 +155,7 @@ public class NetUtils { ...@@ -155,7 +155,7 @@ public class NetUtils {
*/ */
private static InetAddress getBindAddress() throws UnknownHostException { private static InetAddress getBindAddress() throws UnknownHostException {
String host = SysProperties.BIND_ADDRESS; String host = SysProperties.BIND_ADDRESS;
if (host == null || host.length() == 0) { if (host == null || host.isEmpty()) {
return null; return null;
} }
synchronized (NetUtils.class) { synchronized (NetUtils.class) {
......
...@@ -238,10 +238,11 @@ public class ParserUtil { ...@@ -238,10 +238,11 @@ public class ParserUtil {
* @return true if it is a keyword * @return true if it is a keyword
*/ */
public static boolean isKeyword(String s) { public static boolean isKeyword(String s) {
if (s.length() == 0) { int length = s.length();
if (length == 0) {
return false; return false;
} }
return getSaveTokenType(s, false, 0, s.length(), false) != IDENTIFIER; return getSaveTokenType(s, false, 0, length, false) != IDENTIFIER;
} }
/** /**
...@@ -252,7 +253,8 @@ public class ParserUtil { ...@@ -252,7 +253,8 @@ public class ParserUtil {
* @throws NullPointerException if s is {@code null} * @throws NullPointerException if s is {@code null}
*/ */
public static boolean isSimpleIdentifier(String s) { public static boolean isSimpleIdentifier(String s) {
if (s.length() == 0) { int length = s.length();
if (length == 0) {
return false; return false;
} }
char c = s.charAt(0); char c = s.charAt(0);
...@@ -260,13 +262,13 @@ public class ParserUtil { ...@@ -260,13 +262,13 @@ public class ParserUtil {
if ((UPPER_OR_OTHER_LETTER >>> Character.getType(c) & 1) == 0 && c != '_') { if ((UPPER_OR_OTHER_LETTER >>> Character.getType(c) & 1) == 0 && c != '_') {
return false; return false;
} }
for (int i = 1, length = s.length(); i < length; i++) { for (int i = 1; i < length; i++) {
c = s.charAt(i); c = s.charAt(i);
if ((UPPER_OR_OTHER_LETTER_OR_DIGIT >>> Character.getType(c) & 1) == 0 && c != '_') { if ((UPPER_OR_OTHER_LETTER_OR_DIGIT >>> Character.getType(c) & 1) == 0 && c != '_') {
return false; return false;
} }
} }
return getSaveTokenType(s, false, 0, s.length(), true) == IDENTIFIER; return getSaveTokenType(s, false, 0, length, true) == IDENTIFIER;
} }
/** /**
......
...@@ -777,7 +777,7 @@ public class StringUtils { ...@@ -777,7 +777,7 @@ public class StringUtils {
* @return true if it is null or empty * @return true if it is null or empty
*/ */
public static boolean isNullOrEmpty(String s) { public static boolean isNullOrEmpty(String s) {
return s == null || s.length() == 0; return s == null || s.isEmpty();
} }
/** /**
...@@ -810,7 +810,7 @@ public class StringUtils { ...@@ -810,7 +810,7 @@ public class StringUtils {
return string; return string;
} }
char paddingChar; char paddingChar;
if (padding == null || padding.length() == 0) { if (padding == null || padding.isEmpty()) {
paddingChar = ' '; paddingChar = ' ';
} else { } else {
paddingChar = padding.charAt(0); paddingChar = padding.charAt(0);
...@@ -941,7 +941,7 @@ public class StringUtils { ...@@ -941,7 +941,7 @@ public class StringUtils {
} }
if (s == null) { if (s == null) {
return s; return s;
} else if (s.length() == 0) { } else if (s.isEmpty()) {
return ""; return "";
} }
int hash = s.hashCode(); int hash = s.hashCode();
...@@ -1151,7 +1151,7 @@ public class StringUtils { ...@@ -1151,7 +1151,7 @@ public class StringUtils {
* @return the escaped pattern * @return the escaped pattern
*/ */
public static String escapeMetaDataPattern(String pattern) { public static String escapeMetaDataPattern(String pattern) {
if (pattern == null || pattern.length() == 0) { if (pattern == null || pattern.isEmpty()) {
return pattern; return pattern;
} }
return replaceAll(pattern, "\\", "\\\\"); return replaceAll(pattern, "\\", "\\\\");
......
...@@ -362,13 +362,14 @@ public class ToChar { ...@@ -362,13 +362,14 @@ public class ToChar {
} }
int i = idx + 1; int i = idx + 1;
boolean allZeroes = true; boolean allZeroes = true;
for (; i < numberStr.length(); i++) { int length = numberStr.length();
for (; i < length; i++) {
if (numberStr.charAt(i) != '0') { if (numberStr.charAt(i) != '0') {
allZeroes = false; allZeroes = false;
break; break;
} }
} }
final char[] zeroes = new char[allZeroes ? numberStr.length() - idx - 1: i - 1 - idx]; final char[] zeroes = new char[allZeroes ? length - idx - 1: i - 1 - idx];
Arrays.fill(zeroes, '0'); Arrays.fill(zeroes, '0');
return String.valueOf(zeroes); return String.valueOf(zeroes);
} }
...@@ -688,7 +689,7 @@ public class ToChar { ...@@ -688,7 +689,7 @@ public class ToChar {
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
boolean fillMode = true; boolean fillMode = true;
for (int i = 0; i < format.length();) { for (int i = 0, length = format.length(); i < length;) {
Capitalization cap; Capitalization cap;
......
...@@ -249,7 +249,7 @@ public class ToDateParser { ...@@ -249,7 +249,7 @@ public class ToDateParser {
} }
private boolean hasToParseData() { private boolean hasToParseData() {
return formatStr.length() > 0; return !formatStr.isEmpty();
} }
private void removeFirstChar() { private void removeFirstChar() {
......
...@@ -651,7 +651,7 @@ class ToDateTokenizer { ...@@ -651,7 +651,7 @@ class ToDateTokenizer {
* @return the list of tokens, or {@code null} * @return the list of tokens, or {@code null}
*/ */
static List<FormatTokenEnum> getTokensInQuestion(String formatStr) { static List<FormatTokenEnum> getTokensInQuestion(String formatStr) {
if (formatStr != null && formatStr.length() > 0) { if (formatStr != null && !formatStr.isEmpty()) {
char key = Character.toUpperCase(formatStr.charAt(0)); char key = Character.toUpperCase(formatStr.charAt(0));
if (key >= 'A' && key <= 'Y') { if (key >= 'A' && key <= 'Y') {
List<FormatTokenEnum>[] tokens = TOKENS; List<FormatTokenEnum>[] tokens = TOKENS;
......
...@@ -222,12 +222,13 @@ public class CompareMode implements Comparator<Value> { ...@@ -222,12 +222,13 @@ public class CompareMode implements Comparator<Value> {
} else if (name.startsWith(CHARSET)) { } else if (name.startsWith(CHARSET)) {
return new CharsetCollator(Charset.forName(name.substring(CHARSET.length()))); return new CharsetCollator(Charset.forName(name.substring(CHARSET.length())));
} }
if (name.length() == 2) { int length = name.length();
if (length == 2) {
Locale locale = new Locale(StringUtils.toLowerEnglish(name), ""); Locale locale = new Locale(StringUtils.toLowerEnglish(name), "");
if (compareLocaleNames(locale, name)) { if (compareLocaleNames(locale, name)) {
result = Collator.getInstance(locale); result = Collator.getInstance(locale);
} }
} else if (name.length() == 5) { } else if (length == 5) {
// LL_CC (language_country) // LL_CC (language_country)
int idx = name.indexOf('_'); int idx = name.indexOf('_');
if (idx >= 0) { if (idx >= 0) {
......
...@@ -49,12 +49,13 @@ public class CompareModeIcu4J extends CompareMode { ...@@ -49,12 +49,13 @@ public class CompareModeIcu4J extends CompareMode {
"com.ibm.icu.text.Collator"); "com.ibm.icu.text.Collator");
Method getInstanceMethod = collatorClass.getMethod( Method getInstanceMethod = collatorClass.getMethod(
"getInstance", Locale.class); "getInstance", Locale.class);
if (name.length() == 2) { int length = name.length();
if (length == 2) {
Locale locale = new Locale(StringUtils.toLowerEnglish(name), ""); Locale locale = new Locale(StringUtils.toLowerEnglish(name), "");
if (compareLocaleNames(locale, name)) { if (compareLocaleNames(locale, name)) {
result = (Comparator<String>) getInstanceMethod.invoke(null, locale); result = (Comparator<String>) getInstanceMethod.invoke(null, locale);
} }
} else if (name.length() == 5) { } else if (length == 5) {
// LL_CC (language_country) // LL_CC (language_country)
int idx = name.indexOf('_'); int idx = name.indexOf('_');
if (idx >= 0) { if (idx >= 0) {
......
...@@ -52,7 +52,7 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo { ...@@ -52,7 +52,7 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
} }
result.append('\''); result.append('\'');
String s = enumerators[i]; String s = enumerators[i];
for (int j = 0; j < s.length(); j++) { for (int j = 0, length = s.length(); j < length; j++) {
char c = s.charAt(j); char c = s.charAt(j);
if (c == '\'') { if (c == '\'') {
result.append('\''); result.append('\'');
......
...@@ -275,7 +275,7 @@ public class ValueLob extends Value { ...@@ -275,7 +275,7 @@ public class ValueLob extends Value {
private static int getNewObjectId(DataHandler h) { private static int getNewObjectId(DataHandler h) {
String path = h.getDatabasePath(); String path = h.getDatabasePath();
if ((path != null) && (path.length() == 0)) { if (path != null && path.isEmpty()) {
path = new File(Utils.getProperty("java.io.tmpdir", "."), path = new File(Utils.getProperty("java.io.tmpdir", "."),
SysProperties.PREFIX_TEMP_FILE).getAbsolutePath(); SysProperties.PREFIX_TEMP_FILE).getAbsolutePath();
} }
......
...@@ -176,7 +176,7 @@ public class ValueLobDb extends Value { ...@@ -176,7 +176,7 @@ public class ValueLobDb extends Value {
private static String createTempLobFileName(DataHandler handler) private static String createTempLobFileName(DataHandler handler)
throws IOException { throws IOException {
String path = handler.getDatabasePath(); String path = handler.getDatabasePath();
if (path.length() == 0) { if (path.isEmpty()) {
path = SysProperties.PREFIX_TEMP_FILE; path = SysProperties.PREFIX_TEMP_FILE;
} }
return FileUtils.createTempFile(path, Constants.SUFFIX_TEMP_FILE, true, true); return FileUtils.createTempFile(path, Constants.SUFFIX_TEMP_FILE, true, true);
......
...@@ -47,13 +47,13 @@ public class ValueStringFixed extends ValueString { ...@@ -47,13 +47,13 @@ public class ValueStringFixed extends ValueString {
} }
private static String rightPadWithSpaces(String s, int length) { private static String rightPadWithSpaces(String s, int length) {
int pad = length - s.length(); int used = s.length();
if (pad <= 0) { if (length <= used) {
return s; return s;
} }
char[] res = new char[length]; char[] res = new char[length];
s.getChars(0, s.length(), res, 0); s.getChars(0, used, res, 0);
Arrays.fill(res, s.length(), length, ' '); Arrays.fill(res, used, length, ' ');
return new String(res); return new String(res);
} }
...@@ -109,11 +109,12 @@ public class ValueStringFixed extends ValueString { ...@@ -109,11 +109,12 @@ public class ValueStringFixed extends ValueString {
// Default behaviour of H2 // Default behaviour of H2
s = trimRight(s); s = trimRight(s);
} }
if (s.length() == 0) { int length = s.length();
if (length == 0) {
return EMPTY; return EMPTY;
} }
ValueStringFixed obj = new ValueStringFixed(StringUtils.cache(s)); ValueStringFixed obj = new ValueStringFixed(StringUtils.cache(s));
if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { if (length > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) {
return obj; return obj;
} }
return (ValueStringFixed) Value.cache(obj); return (ValueStringFixed) Value.cache(obj);
......
...@@ -60,11 +60,12 @@ public class ValueStringIgnoreCase extends ValueString { ...@@ -60,11 +60,12 @@ public class ValueStringIgnoreCase extends ValueString {
* @return the value * @return the value
*/ */
public static ValueStringIgnoreCase get(String s) { public static ValueStringIgnoreCase get(String s) {
if (s.length() == 0) { int length = s.length();
if (length == 0) {
return EMPTY; return EMPTY;
} }
ValueStringIgnoreCase obj = new ValueStringIgnoreCase(StringUtils.cache(s)); ValueStringIgnoreCase obj = new ValueStringIgnoreCase(StringUtils.cache(s));
if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { if (length > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) {
return obj; return obj;
} }
ValueStringIgnoreCase cache = (ValueStringIgnoreCase) Value.cache(obj); ValueStringIgnoreCase cache = (ValueStringIgnoreCase) Value.cache(obj);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论