Convert StringUtils to Kotlin

bzip2
Graham 5 years ago
parent 485a784b53
commit 879e3152fc
  1. 4
      .editorconfig
  2. 6
      .idea/codeStyles/Project.xml
  3. 4
      util/pom.xml
  4. 29
      util/src/main/java/dev/openrs2/util/StringUtils.java
  5. 20
      util/src/main/java/dev/openrs2/util/StringUtils.kt

@ -7,6 +7,10 @@ trim_trailing_whitespace = true
max_line_length = 120 max_line_length = 120
indent_style = tab indent_style = tab
[*.kt]
indent_style = space
indent_size = 4
[*.xml] [*.xml]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2

@ -36,6 +36,9 @@
<option name="JD_ADD_BLANK_AFTER_DESCRIPTION" value="false" /> <option name="JD_ADD_BLANK_AFTER_DESCRIPTION" value="false" />
<option name="JD_INDENT_ON_CONTINUATION" value="true" /> <option name="JD_INDENT_ON_CONTINUATION" value="true" />
</JavaCodeStyleSettings> </JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<XML> <XML>
<option name="XML_ATTRIBUTE_WRAP" value="0" /> <option name="XML_ATTRIBUTE_WRAP" value="0" />
<option name="XML_ALIGN_ATTRIBUTES" value="false" /> <option name="XML_ALIGN_ATTRIBUTES" value="false" />
@ -75,5 +78,8 @@
<option name="TAB_SIZE" value="2" /> <option name="TAB_SIZE" value="2" />
</indentOptions> </indentOptions>
</codeStyleSettings> </codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme> </code_scheme>
</component> </component>

@ -23,6 +23,10 @@
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId> <artifactId>junit-jupiter</artifactId>

@ -1,29 +0,0 @@
package dev.openrs2.util;
import com.google.common.base.Preconditions;
public final class StringUtils {
public static String indefiniteArticle(String str) {
Preconditions.checkArgument(!str.isEmpty());
var first = Character.toLowerCase(str.charAt(0));
if (first == 'a' || first == 'e' || first == 'i' || first == 'o' || first == 'u') {
return "an";
} else {
return "a";
}
}
public static String capitalize(String str) {
if (str.isEmpty()) {
return str;
}
var first = Character.toUpperCase(str.charAt(0));
return first + str.substring(1);
}
private StringUtils() {
/* empty */
}
}

@ -0,0 +1,20 @@
package dev.openrs2.util
object StringUtils {
// TODO(gpe): convert to an extension function
@JvmStatic
fun indefiniteArticle(str: String): String {
require(str.isNotEmpty())
val first = str.first().toLowerCase()
return when (first) {
'a', 'e', 'i', 'o', 'u' -> "an"
else -> "a"
}
}
@JvmStatic
fun capitalize(str: String): String {
return str.capitalize()
}
}
Loading…
Cancel
Save