Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Feb 26, 2021
1 parent 32c4952 commit e3c1852
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
8 changes: 6 additions & 2 deletions hutool-db/src/main/java/cn/hutool/db/sql/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ private void parseValue() {
final String firstPart = strs.get(0).trim().toUpperCase();
if (OPERATORS.contains(firstPart)) {
this.operator = firstPart;
// 比较符号后跟大部分为数字,此处做转换
this.value = tryToNumber(strs.get(1));
// 比较符号后跟大部分为数字,此处做转换(IN不做转换)
final String valuePart = strs.get(1);
this.value = isOperatorIn() ? valuePart : tryToNumber(valuePart);
return;
}

Expand Down Expand Up @@ -537,6 +538,9 @@ private static String unwrapQuote(String value) {
*/
private static Object tryToNumber(String value){
value = StrUtil.trim(value);
if(false == NumberUtil.isNumber(value)){
return value;
}
try{
return NumberUtil.parseNumber(value);
} catch (Exception ignore){
Expand Down
6 changes: 6 additions & 0 deletions hutool-db/src/test/java/cn/hutool/db/sql/ConditionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@ public void parseTest(){
// issue I38LTM
Assert.assertSame(Long.class, age.getValue().getClass());
}

@Test
public void parseInTest(){
final Condition age = Condition.parse("age", "in 1,2,3");
Assert.assertEquals("age IN (?,?,?)", age.toString());
}
}
44 changes: 23 additions & 21 deletions hutool-extra/src/main/java/cn/hutool/extra/ftp/Ftp.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ public Ftp(String host, int port, String user, String password, Charset charset,
/**
* 构造
*
* @param host 域名或IP
* @param port 端口
* @param user 用户名
* @param password 密码
* @param charset 编码
* @param mode 模式
* @param host 域名或IP
* @param port 端口
* @param user 用户名
* @param password 密码
* @param charset 编码
* @param serverLanguageCode 服务器语言
* @param systemKey 系统关键字
* @param mode 模式
*/
public Ftp(String host, int port, String user, String password, Charset charset, String serverLanguageCode, String systemKey, FtpMode mode) {
this(new FtpConfig(host, port, user, password, charset, serverLanguageCode, systemKey), mode);
Expand Down Expand Up @@ -338,14 +340,14 @@ public List<FTPFile> lsFiles(String path, Filter<FTPFile> filter) {
*
* @param path 目录,如果目录不存在,抛出异常
* @return 文件或目录列表
* @throws FtpException 路径不存在
* @throws FtpException 路径不存在
* @throws IORuntimeException IO异常
*/
public FTPFile[] lsFiles(String path) throws FtpException, IORuntimeException{
public FTPFile[] lsFiles(String path) throws FtpException, IORuntimeException {
String pwd = null;
if (StrUtil.isNotBlank(path)) {
pwd = pwd();
if(false == cd(path)){
if (false == cd(path)) {
throw new FtpException("Change dir to [{}] error, maybe path not exist!", path);
}
}
Expand All @@ -364,7 +366,7 @@ public FTPFile[] lsFiles(String path) throws FtpException, IORuntimeException{
}

@Override
public boolean mkdir(String dir) throws IORuntimeException{
public boolean mkdir(String dir) throws IORuntimeException {
try {
return this.client.makeDirectory(dir);
} catch (IOException e) {
Expand All @@ -379,7 +381,7 @@ public boolean mkdir(String dir) throws IORuntimeException{
* @return 状态int,服务端不同,返回不同
* @since 5.4.3
*/
public int stat(String path) throws IORuntimeException{
public int stat(String path) throws IORuntimeException {
try {
return this.client.stat(path);
} catch (IOException e) {
Expand All @@ -394,7 +396,7 @@ public int stat(String path) throws IORuntimeException{
* @return 是否存在
* @throws IORuntimeException IO异常
*/
public boolean existFile(String path) throws IORuntimeException{
public boolean existFile(String path) throws IORuntimeException {
FTPFile[] ftpFileArr;
try {
ftpFileArr = client.listFiles(path);
Expand All @@ -405,11 +407,11 @@ public boolean existFile(String path) throws IORuntimeException{
}

@Override
public boolean delFile(String path) throws IORuntimeException{
public boolean delFile(String path) throws IORuntimeException {
final String pwd = pwd();
final String fileName = FileUtil.getName(path);
final String dir = StrUtil.removeSuffix(path, fileName);
if(false == cd(dir)){
if (false == cd(dir)) {
throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path);
}

Expand All @@ -426,7 +428,7 @@ public boolean delFile(String path) throws IORuntimeException{
}

@Override
public boolean delDir(String dirPath) throws IORuntimeException{
public boolean delDir(String dirPath) throws IORuntimeException {
FTPFile[] dirs;
try {
dirs = client.listFiles(dirPath);
Expand Down Expand Up @@ -490,7 +492,7 @@ public boolean upload(String destPath, File file) {
* @return 是否上传成功
* @throws IORuntimeException IO异常
*/
public boolean upload(String path, String fileName, File file) throws IORuntimeException{
public boolean upload(String path, String fileName, File file) throws IORuntimeException {
try (InputStream in = FileUtil.getInputStream(file)) {
return upload(path, fileName, in);
} catch (IOException e) {
Expand All @@ -513,7 +515,7 @@ public boolean upload(String path, String fileName, File file) throws IORuntimeE
* @return 是否上传成功
* @throws IORuntimeException IO异常
*/
public boolean upload(String path, String fileName, InputStream fileStream) throws IORuntimeException{
public boolean upload(String path, String fileName, InputStream fileStream) throws IORuntimeException {
try {
client.setFileType(FTPClient.BINARY_FILE_TYPE);
} catch (IOException e) {
Expand Down Expand Up @@ -594,7 +596,7 @@ public void recursiveDownloadFolder(String sourcePath, File destDir) {
* @param outFile 输出文件或目录
* @throws IORuntimeException IO异常
*/
public void download(String path, String fileName, File outFile) throws IORuntimeException{
public void download(String path, String fileName, File outFile) throws IORuntimeException {
if (outFile.isDirectory()) {
outFile = new File(outFile, fileName);
}
Expand Down Expand Up @@ -626,16 +628,16 @@ public void download(String path, String fileName, OutputStream out) {
* @param fileName 文件名
* @param out 输出位置
* @param fileNameCharset 文件名编码
* @since 5.5.7
* @throws IORuntimeException IO异常
* @since 5.5.7
*/
public void download(String path, String fileName, OutputStream out, Charset fileNameCharset) throws IORuntimeException{
public void download(String path, String fileName, OutputStream out, Charset fileNameCharset) throws IORuntimeException {
String pwd = null;
if (this.backToPwd) {
pwd = pwd();
}

if(false == cd(path)){
if (false == cd(path)) {
throw new FtpException("Change dir to [{}] error, maybe dir not exist!", path);
}

Expand Down

0 comments on commit e3c1852

Please sign in to comment.