Skip to content

Commit

Permalink
Added formatter argument to 'StridedVector.toString'
Browse files Browse the repository at this point in the history
  • Loading branch information
superbobry committed Apr 22, 2016
1 parent 8bff24e commit d06c256
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/org/jetbrains/bio/viktor/StridedVector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.apache.commons.math3.util.FastMath
import org.apache.commons.math3.util.Precision
import org.jetbrains.bio.jni.DoubleStat
import org.jetbrains.bio.jni.SIMDMath
import java.text.DecimalFormat
import java.util.*

/**
Expand Down Expand Up @@ -515,14 +516,15 @@ open class StridedVector internal constructor(
override fun nextDouble() = unsafeGet(i++)
}

fun toString(maxDisplay: Int): String {
fun toString(maxDisplay: Int,
format: DecimalFormat = DecimalFormat("#.####")): String {
return if (size <= maxDisplay) {
Arrays.toString(toArray())
} else {
val sb = StringBuilder()
sb.append('[')
for (pos in 0..maxDisplay - 1) {
sb.append(this[pos])
sb.append(format.format(this[pos]))
if (pos < maxDisplay - 1) {
sb.append(", ")
}
Expand All @@ -532,7 +534,7 @@ open class StridedVector internal constructor(
}
}

override fun toString() = toString(8)
override fun toString() = toString(16)

override fun equals(other: Any?): Boolean {
if (this === other) {
Expand Down

0 comments on commit d06c256

Please sign in to comment.