Following are some observations that I found in this code -
There is no need of taking
limit
as instance variable in this class. You are not using it and your code will work without it.Your
split()
method requiresCharSequence
as instance variable, but in code you are converting it intoString
e.g. -result.add(((String) toSplit).substring(start, i));
So, it will break your code, if input is other than String
like StringBuffer
and StringBuilder
Below method will break if input
separator
contains anydangling character
like "*" -public static Splitter on(final String separator)
This is because in below line, split()
method of String class
accepts a regex
string -
String[] result = ((String) toSplit).split(separator);
As per current logic,
String
separator is also usingregex
, so you can callPattern
separator method from this method -public static Splitter on(final String separator) { onreturn on(Pattern.compile(separator); }
Regarding
multi-threading
, code looks fine and it would be able to work inmulti-threaded
environment.