Skip to content

modified isBlank function#122

Closed
zehuaiWANG wants to merge 4 commits intoTencent:masterfrom
zehuaiWANG:tubeMq-dev
Closed

modified isBlank function#122
zehuaiWANG wants to merge 4 commits intoTencent:masterfrom
zehuaiWANG:tubeMq-dev

Conversation

@zehuaiWANG
Copy link
Copy Markdown
Contributor

No description provided.

@gosonzhang
Copy link
Copy Markdown
Collaborator

isBlank() and isEmpty() are two meanings: isBlank() not only includes empty check and includes space, tab key and line feed check

@gosonzhang
Copy link
Copy Markdown
Collaborator

I‘ll reject this PR

@zehuaiWANG
Copy link
Copy Markdown
Contributor Author

hi~goson, plz take care that I use trim() here.

public String trim​()
Returns a string whose value is this string, with any leading and trailing whitespace removed.
If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u0020' (the space character), then a reference to this String object is returned.

Otherwise, if there is no character with a code greater than '\u0020' in the string, then a String object representing an empty string is returned.

Otherwise, let k be the index of the first character in the string whose code is greater than '\u0020', and let m be the index of the last character in the string whose code is greater than '\u0020'. A String object is returned, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m + 1).

This method may be used to trim whitespace (as defined above) from the beginning and end of a string.

Returns:
A string whose value is this string, with any leading and trailing white space removed, or this string if it has no leading or trailing white space.

Accoring to the jdk document, it seems that trim() can not only remove empty char but also space, tab key and line feed check in the leading and trailing of a string.
I have also wirte a test to comfirm it.

public class test {
    public static void main(String[] args) {
        String str = "\r\n\t";
        System.out.println("S"+str.trim()+"s");
    }
}

Or could you give me a unit test to show the differences?Thanks. @gosonzhang

@gosonzhang
Copy link
Copy Markdown
Collaborator

trim() : returns a string whose value is this string, with any leading and trailing whitespace removed.
isBlank() : checks the whole string content

Copy link
Copy Markdown
Contributor

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @zehuaiWANG . I second @gosonzhang that this pr might be invalid.

Basically TStringUtils comes from outside codebase that is verified quite a long time. And I don't think we gain too much by this refactor. We do neither improve performance nor readability. The original code is expressive IMO.

@gosonzhang
Copy link
Copy Markdown
Collaborator

After I think about it, this PR reminds me that if the content of a string has been checked by isBlank() and the string still exists in memory, the next step is to do null judgment processing, which should only be isEmpty(), so as to improve the overall processing performance.

isBlank () can solve the problem that the content of the external input system is not standardized. It is not appropriate to modify this method. I think it would be better to contribute other PRs to solve these problems


這個問題我想了下,@zehuaiWANG这个PR提醒了我: 如果一个字符串的内容已经被isBlank ()检查过,并且字符串仍然存在于内存中時,接下來的内容判断操作只需要用isEmpty()就可以了,這樣可以提高整个的处理性能。
isBlank()可以解决外部输入系统内容不规范的问题,兩個接口不等同,這裡不适合修改去掉此方法。性能問題我认为最好是通过其他PR来解决

@gosonzhang
Copy link
Copy Markdown
Collaborator

I'll close this PR, and trace this question by #123

Thanks for @zehuaiWANG

@gosonzhang gosonzhang closed this Nov 12, 2019
guangxuCheng pushed a commit to guangxuCheng/TubeMQ that referenced this pull request Jul 3, 2020
Change list:
* Migrate all bdb configs.
* Change to relative path in configs
* Modify config reading codes
* Add "deprecated" warning

Signed-off-by: pingyu <shui.yu@126.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants