本文整理汇总了Java中org.apache.commons.math3.util.CompositeFormat类的典型用法代码示例。如果您正苦于以下问题:Java CompositeFormat类的具体用法?Java CompositeFormat怎么用?Java CompositeFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompositeFormat类属于org.apache.commons.math3.util包,在下文中一共展示了CompositeFormat类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: format
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Formats the coordinates of a {@link Vector} to produce a string.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
* offsets of the alignment field
* @param coordinates coordinates of the object to format.
* @return the value passed in as toAppendTo.
*/
protected StringBuffer format(StringBuffer toAppendTo, FieldPosition pos,
double ... coordinates) {
pos.setBeginIndex(0);
pos.setEndIndex(0);
// format prefix
toAppendTo.append(prefix);
// format components
for (int i = 0; i < coordinates.length; ++i) {
if (i > 0) {
toAppendTo.append(separator);
}
CompositeFormat.formatDouble(coordinates[i], format, toAppendTo, pos);
}
// format suffix
toAppendTo.append(suffix);
return toAppendTo;
}
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:VectorFormat.java
示例2: format
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Formats a {@link RealVector} object to produce a string.
* @param vector the object to format.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
* offsets of the alignment field
* @return the value passed in as toAppendTo.
*/
public StringBuffer format(RealVector vector, StringBuffer toAppendTo,
FieldPosition pos) {
pos.setBeginIndex(0);
pos.setEndIndex(0);
// format prefix
toAppendTo.append(prefix);
// format components
for (int i = 0; i < vector.getDimension(); ++i) {
if (i > 0) {
toAppendTo.append(separator);
}
CompositeFormat.formatDouble(vector.getEntry(i), format, toAppendTo, pos);
}
// format suffix
toAppendTo.append(suffix);
return toAppendTo;
}
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:RealVectorFormat.java
示例3: format
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Formats a {@link Complex} object to produce a string.
*
* @param complex the object to format.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
* offsets of the alignment field
* @return the value passed in as toAppendTo.
*/
public StringBuffer format(Complex complex, StringBuffer toAppendTo,
FieldPosition pos) {
pos.setBeginIndex(0);
pos.setEndIndex(0);
// format real
double re = complex.getReal();
CompositeFormat.formatDouble(re, getRealFormat(), toAppendTo, pos);
// format sign and imaginary
double im = complex.getImaginary();
StringBuffer imAppendTo;
if (im < 0.0) {
toAppendTo.append(" - ");
imAppendTo = formatImaginary(-im, new StringBuffer(), pos);
toAppendTo.append(imAppendTo);
toAppendTo.append(getImaginaryCharacter());
} else if (im > 0.0 || Double.isNaN(im)) {
toAppendTo.append(" + ");
imAppendTo = formatImaginary(im, new StringBuffer(), pos);
toAppendTo.append(imAppendTo);
toAppendTo.append(getImaginaryCharacter());
}
return toAppendTo;
}
开发者ID:biocompibens,项目名称:SME,代码行数:36,代码来源:ComplexFormat.java
示例4: formatImaginary
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Format the absolute value of the imaginary part.
*
* @param absIm Absolute value of the imaginary part of a complex number.
* @param toAppendTo where the text is to be appended.
* @param pos On input: an alignment field, if desired. On output: the
* offsets of the alignment field.
* @return the value passed in as toAppendTo.
*/
private StringBuffer formatImaginary(double absIm,
StringBuffer toAppendTo,
FieldPosition pos) {
pos.setBeginIndex(0);
pos.setEndIndex(0);
CompositeFormat.formatDouble(absIm, getImaginaryFormat(), toAppendTo, pos);
if (toAppendTo.toString().equals("1")) {
// Remove the character "1" if it is the only one.
toAppendTo.setLength(0);
}
return toAppendTo;
}
开发者ID:biocompibens,项目名称:SME,代码行数:24,代码来源:ComplexFormat.java
示例5: format
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Formats a {@link RealMatrix} object to produce a string.
* @param matrix the object to format.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
* offsets of the alignment field
* @return the value passed in as toAppendTo.
*/
public StringBuffer format(RealMatrix matrix, StringBuffer toAppendTo,
FieldPosition pos) {
pos.setBeginIndex(0);
pos.setEndIndex(0);
// format prefix
toAppendTo.append(prefix);
// format rows
final int rows = matrix.getRowDimension();
for (int i = 0; i < rows; ++i) {
toAppendTo.append(rowPrefix);
for (int j = 0; j < matrix.getColumnDimension(); ++j) {
if (j > 0) {
toAppendTo.append(columnSeparator);
}
CompositeFormat.formatDouble(matrix.getEntry(i, j), format, toAppendTo, pos);
}
toAppendTo.append(rowSuffix);
if (i < rows - 1) {
toAppendTo.append(rowSeparator);
}
}
// format suffix
toAppendTo.append(suffix);
return toAppendTo;
}
开发者ID:biocompibens,项目名称:SME,代码行数:39,代码来源:RealMatrixFormat.java
示例6: parseCoordinates
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Parses a string to produce an array of coordinates.
* @param dimension dimension of the space
* @param source the string to parse
* @param pos input/output parsing parameter.
* @return coordinates array.
*/
protected double[] parseCoordinates(int dimension, String source, ParsePosition pos) {
int initialIndex = pos.getIndex();
double[] coordinates = new double[dimension];
// parse prefix
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
if (!CompositeFormat.parseFixedstring(source, trimmedPrefix, pos)) {
return null;
}
for (int i = 0; i < dimension; ++i) {
// skip whitespace
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
// parse separator
if (i > 0 && !CompositeFormat.parseFixedstring(source, trimmedSeparator, pos)) {
return null;
}
// skip whitespace
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
// parse coordinate
Number c = CompositeFormat.parseNumber(source, format, pos);
if (c == null) {
// invalid coordinate
// set index back to initial, error index should already be set
pos.setIndex(initialIndex);
return null;
}
// store coordinate
coordinates[i] = c.doubleValue();
}
// parse suffix
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
if (!CompositeFormat.parseFixedstring(source, trimmedSuffix, pos)) {
return null;
}
return coordinates;
}
开发者ID:biocompibens,项目名称:SME,代码行数:55,代码来源:VectorFormat.java
示例7: ComplexFormat
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Create an instance with the default imaginary character, 'i', and the
* default number format for both real and imaginary parts.
*/
public ComplexFormat() {
this.imaginaryCharacter = DEFAULT_IMAGINARY_CHARACTER;
this.imaginaryFormat = CompositeFormat.getDefaultNumberFormat();
this.realFormat = imaginaryFormat;
}
开发者ID:biocompibens,项目名称:SME,代码行数:10,代码来源:ComplexFormat.java
示例8: parse
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Parses a string to produce a {@link Complex} object.
*
* @param source the string to parse
* @param pos input/ouput parsing parameter.
* @return the parsed {@link Complex} object.
*/
public Complex parse(String source, ParsePosition pos) {
int initialIndex = pos.getIndex();
// parse whitespace
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
// parse real
Number re = CompositeFormat.parseNumber(source, getRealFormat(), pos);
if (re == null) {
// invalid real number
// set index back to initial, error index should already be set
pos.setIndex(initialIndex);
return null;
}
// parse sign
int startIndex = pos.getIndex();
char c = CompositeFormat.parseNextCharacter(source, pos);
int sign = 0;
switch (c) {
case 0 :
// no sign
// return real only complex number
return new Complex(re.doubleValue(), 0.0);
case '-' :
sign = -1;
break;
case '+' :
sign = 1;
break;
default :
// invalid sign
// set index back to initial, error index should be the last
// character examined.
pos.setIndex(initialIndex);
pos.setErrorIndex(startIndex);
return null;
}
// parse whitespace
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
// parse imaginary
Number im = CompositeFormat.parseNumber(source, getRealFormat(), pos);
if (im == null) {
// invalid imaginary number
// set index back to initial, error index should already be set
pos.setIndex(initialIndex);
return null;
}
// parse imaginary character
if (!CompositeFormat.parseFixedstring(source, getImaginaryCharacter(), pos)) {
return null;
}
return new Complex(re.doubleValue(), im.doubleValue() * sign);
}
开发者ID:biocompibens,项目名称:SME,代码行数:67,代码来源:ComplexFormat.java
示例9: parse
import org.apache.commons.math3.util.CompositeFormat; //导入依赖的package包/类
/**
* Parse a string to produce a {@link RealVector} object.
*
* @param source String to parse.
* @param pos input/ouput parsing parameter.
* @return the parsed {@link RealVector} object.
*/
public ArrayRealVector parse(String source, ParsePosition pos) {
int initialIndex = pos.getIndex();
// parse prefix
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
if (!CompositeFormat.parseFixedstring(source, trimmedPrefix, pos)) {
return null;
}
// parse components
List<Number> components = new ArrayList<Number>();
for (boolean loop = true; loop;){
if (!components.isEmpty()) {
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
if (!CompositeFormat.parseFixedstring(source, trimmedSeparator, pos)) {
loop = false;
}
}
if (loop) {
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
Number component = CompositeFormat.parseNumber(source, format, pos);
if (component != null) {
components.add(component);
} else {
// invalid component
// set index back to initial, error index should already be set
pos.setIndex(initialIndex);
return null;
}
}
}
// parse suffix
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
if (!CompositeFormat.parseFixedstring(source, trimmedSuffix, pos)) {
return null;
}
// build vector
double[] data = new double[components.size()];
for (int i = 0; i < data.length; ++i) {
data[i] = components.get(i).doubleValue();
}
return new ArrayRealVector(data, false);
}
开发者ID:biocompibens,项目名称:SME,代码行数:56,代码来源:RealVectorFormat.java
注:本文中的org.apache.commons.math3.util.CompositeFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论