本文整理汇总了Java中weka.core.Utils.padRight方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.padRight方法的具体用法?Java Utils.padRight怎么用?Java Utils.padRight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Utils
的用法示例。
在下文中一共展示了Utils.padRight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toString
import weka.core.Utils; //导入方法依赖的package包/类
/**
* Converts a matrix to a string. (FracPete: taken from old weka.core.Matrix
* class)
*
* @return the converted string
*/
@Override
public String toString() {
// Determine the width required for the maximum element,
// and check for fractional display requirement.
double maxval = 0;
boolean fractional = false;
Object element = null;
int widthNumber = 0;
int widthExpression = 0;
for (int i = 0; i < size(); i++) {
for (int j = 0; j < size(); j++) {
element = getCell(i, j);
if (element instanceof Double) {
double current = ((Double) element).doubleValue();
if (current < 0)
current *= -11;
if (current > maxval)
maxval = current;
double fract = Math.abs(current - Math.rint(current));
if (!fractional && ((Math.log(fract) / Math.log(10)) >= -2)) {
fractional = true;
}
} else {
if (element.toString().length() > widthExpression) {
widthExpression = element.toString().length();
}
}
}
}
if (maxval > 0) {
widthNumber =
(int) (Math.log(maxval) / Math.log(10) + (fractional ? 4 : 1));
}
int width = (widthNumber > widthExpression) ? widthNumber : widthExpression;
StringBuffer text = new StringBuffer();
for (int i = 0; i < size(); i++) {
for (int j = 0; j < size(); j++) {
element = getCell(i, j);
if (element instanceof Double) {
text.append(" ").append(
Utils.doubleToString(((Double) element).doubleValue(), width,
(fractional ? 2 : 0)));
} else {
int diff = width - element.toString().length();
if (diff > 0) {
int left = diff % 2;
left += diff / 2;
String temp =
Utils.padLeft(element.toString(), element.toString().length()
+ left);
temp = Utils.padRight(temp, width);
text.append(" ").append(temp);
} else {
text.append(" ").append(element.toString());
}
}
}
text.append("\n");
}
return text.toString();
}