Convert Sentence to Kotlin
This commit is contained in:
parent
787c044da6
commit
3fe3cdec68
2 changed files with 36 additions and 48 deletions
|
@ -1,48 +0,0 @@
|
|||
package com.wbrawner.simplemarkdown.model;
|
||||
|
||||
import eu.crydee.syllablecounter.SyllableCounter;
|
||||
|
||||
public class Sentence {
|
||||
|
||||
private String sentence = "";
|
||||
private int start = 0;
|
||||
private int end = 0;
|
||||
|
||||
private final static SyllableCounter sc = new SyllableCounter();
|
||||
|
||||
public Sentence(String content, int start, int end){
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.sentence = content.substring(start, end);
|
||||
|
||||
trimStart();
|
||||
}
|
||||
|
||||
public Sentence(String sentence){
|
||||
this.sentence = sentence;
|
||||
}
|
||||
|
||||
private void trimStart() {
|
||||
while(sentence.startsWith(" ")){
|
||||
this.start++;
|
||||
sentence = sentence.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sentence;
|
||||
}
|
||||
|
||||
public int start(){
|
||||
return start;
|
||||
}
|
||||
|
||||
public int end(){
|
||||
return end;
|
||||
}
|
||||
|
||||
public int syllableCount(){
|
||||
return sc.count(sentence);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.wbrawner.simplemarkdown.model
|
||||
|
||||
import eu.crydee.syllablecounter.SyllableCounter
|
||||
|
||||
class Sentence(content: String, private var start: Int = 0, private val end: Int = 0) {
|
||||
|
||||
private var sentence = content.substring(start, end)
|
||||
private val sc = SyllableCounter()
|
||||
|
||||
init {
|
||||
trimStart()
|
||||
}
|
||||
|
||||
private fun trimStart() {
|
||||
while (sentence.startsWith(" ")) {
|
||||
this.start++
|
||||
sentence = sentence.substring(1)
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return sentence
|
||||
}
|
||||
|
||||
fun start(): Int {
|
||||
return start
|
||||
}
|
||||
|
||||
fun end(): Int {
|
||||
return end
|
||||
}
|
||||
|
||||
fun syllableCount(): Int {
|
||||
return sc.count(sentence)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue