Skip to content

Commit

Permalink
refactor: Replace internal comparator class by a lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed Sep 7, 2023
1 parent 9b2dbe3 commit eabbf3d
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.sonar.plsqlopen.lexer

import com.felipebz.flr.api.Token
import com.felipebz.flr.api.TokenType
import com.felipebz.flr.channel.Channel
import com.felipebz.flr.channel.CodeReader
import com.felipebz.flr.impl.LexerException
Expand All @@ -32,20 +31,17 @@ import java.util.regex.Pattern
class RegexPunctuatorChannel(vararg punctuators: PlSqlPunctuator) : Channel<LexerOutput> {
private val tokenMatchers = LinkedHashMap<PlSqlPunctuator, Pattern>()

private class PunctuatorComparator : Comparator<TokenType> {

override fun compare(a: TokenType, b: TokenType): Int {
init {
Arrays.sort(punctuators) { a, b ->
if (a.value.length == b.value.length) {
return 0
0
} else if (a.value.length > b.value.length) {
-1
} else {
1
}
return if (a.value.length > b.value.length) -1 else 1
}

}

init {
Arrays.sort(punctuators, PunctuatorComparator())

for (punctuator in punctuators) {
tokenMatchers[punctuator] = Pattern.compile(punctuator.value)
}
Expand Down

0 comments on commit eabbf3d

Please sign in to comment.