Skip to content

Commit

Permalink
UPDATE: Interim Commit
Browse files Browse the repository at this point in the history
Does not build successfully.
  • Loading branch information
HankG committed Apr 30, 2012
1 parent 9fb3074 commit 82d3183
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
66 changes: 36 additions & 30 deletions Apache.Commons.Math/Util/CompositeFormat.cs
@@ -1,5 +1,11 @@
using System;
using System.Text;
using System.Globalization;

using JavaDotNet.Text;

using Apache.Commons.Math.Exceptions;
using Apache.Commons.Math.Exceptions.Util;
/**
* Base class for formatters of composite objects (complex numbers, vectors ...).
*
Expand All @@ -21,8 +27,8 @@ public class CompositeFormat {
* maximum number of fraction digits is set to 2.
* @return the default number format.
*/
public static NumberFormat getDefaultNumberFormat() {
return getDefaultNumberFormat(Locale.getDefault());
public static NumberFormatInfo getDefaultNumberFormat() {
return getDefaultNumberFormat(CultureInfo.CurrentCulture);
}

/**
Expand All @@ -32,8 +38,8 @@ public class CompositeFormat {
* @param locale the specific locale used by the format.
* @return the default number format specific to the given locale.
*/
public static NumberFormat getDefaultNumberFormat(final Locale locale) {
final NumberFormat nf = NumberFormat.getInstance(locale);
public static NumberFormatInfo getDefaultNumberFormat(CultureInfo locale) {
NumberFormat nf = NumberFormat.getInstance(locale);
nf.setMaximumFractionDigits(2);
return nf;
}
Expand All @@ -45,8 +51,8 @@ public class CompositeFormat {
* @param pos input/ouput parsing parameter. On output, <code>pos</code>
* holds the index of the next non-whitespace character.
*/
public static void parseAndIgnoreWhitespace(final String source,
final ParsePosition pos) {
public static void parseAndIgnoreWhitespace(String source,
ParsePosition pos) {
parseNextCharacter(source, pos);
pos.setIndex(pos.getIndex() - 1);
}
Expand All @@ -58,10 +64,10 @@ public class CompositeFormat {
* @param pos input/ouput parsing parameter.
* @return the first non-whitespace character.
*/
public static char parseNextCharacter(final String source,
final ParsePosition pos) {
public static char parseNextCharacter(String source,
ParsePosition pos) {
int index = pos.getIndex();
final int n = source.length();
int n = source.length();
char ret = 0;

if (index < n) {
Expand All @@ -88,18 +94,18 @@ public class CompositeFormat {
* @param pos input/ouput parsing parameter.
* @return the special number.
*/
private static Number parseNumber(final String source, final double value,
final ParsePosition pos) {
private static Number parseNumber(String source, double value,
ParsePosition pos) {
Number ret = null;

StringBuilder sb = new StringBuilder();
sb.append('(');
sb.append(value);
sb.append(')');

final int n = sb.length();
final int startIndex = pos.getIndex();
final int endIndex = startIndex + n;
int n = sb.length();
int startIndex = pos.getIndex();
int endIndex = startIndex + n;
if (endIndex < source.length()) {
if (source.substring(startIndex, endIndex).compareTo(sb.toString()) == 0) {
ret = Double.valueOf(value);
Expand All @@ -120,16 +126,16 @@ public class CompositeFormat {
* @param pos input/ouput parsing parameter.
* @return the parsed number.
*/
public static Number parseNumber(final String source, final NumberFormat format,
final ParsePosition pos) {
final int startIndex = pos.getIndex();
public static Number parseNumber(String source, NumberFormat format,
ParsePosition pos) {
int startIndex = pos.getIndex();
Number number = format.parse(source, pos);
final int endIndex = pos.getIndex();
int endIndex = pos.getIndex();

// check for error parsing number
if (startIndex == endIndex) {
// try parsing special numbers
final double[] special = {
double[] special = {
Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY
};
for (int i = 0; i < special.length; ++i) {
Expand All @@ -150,12 +156,12 @@ public class CompositeFormat {
* @param pos input/ouput parsing parameter.
* @return true if the expected string was there
*/
public static boolean parseFixedstring(final String source,
final String expected,
final ParsePosition pos) {
public static bool parseFixedstring(String source,
String expected,
ParsePosition pos) {

final int startIndex = pos.getIndex();
final int endIndex = startIndex + expected.length();
int startIndex = pos.getIndex();
int endIndex = startIndex + expected.length();
if ((startIndex >= source.length()) ||
(endIndex > source.length()) ||
(source.substring(startIndex, endIndex).compareTo(expected) != 0)) {
Expand Down Expand Up @@ -187,13 +193,13 @@ public class CompositeFormat {
* offsets of the alignment field
* @return the value passed in as toAppendTo.
*/
public static StringBuffer formatDouble(final double value, final NumberFormat format,
final StringBuffer toAppendTo,
final FieldPosition pos) {
public static StringBuilder formatDouble(double value, NumberFormat format,
StringBuilder toAppendTo,
FieldPosition pos) {
if( Double.isNaN(value) || Double.isInfinite(value) ) {
toAppendTo.append('(');
toAppendTo.append(value);
toAppendTo.append(')');
toAppendTo.Append('(');
toAppendTo.Append(value);
toAppendTo.Append(')');
} else {
format.format(value, toAppendTo, pos);
}
Expand Down
6 changes: 3 additions & 3 deletions Apache.Commons.Math/Util/ContinuedFraction.cs
Expand Up @@ -19,7 +19,7 @@ namespace Apache.Commons.Math
{
public abstract class ContinuedFraction {
/** Maximum allowed numerical error. */
private static final double DEFAULT_EPSILON = 10e-9;
private static readonly double DEFAULT_EPSILON = 10e-9;

/**
* Default constructor.
Expand Down Expand Up @@ -127,8 +127,8 @@ public abstract class ContinuedFraction {
*/
double scaleFactor = 1d;
double lastScaleFactor = 1d;
final int maxPower = 5;
final double scale = FastMath.max(a,b);
int maxPower = 5;
double scale = FastMath.max(a,b);
if (scale <= 0) { // Can't scale
throw new ConvergenceException(LocalizedFormats.CONTINUED_FRACTION_INFINITY_DIVERGENCE,
x);
Expand Down
6 changes: 3 additions & 3 deletions JavaDotNet/Text/ParsePosition.cs
Expand Up @@ -130,9 +130,9 @@ public void setErrorIndex (int error_index)
* @return <code>true</code> if the specified object is equal to
* this object, <code>false</code> otherwise.
*/
public boolean equals (Object obj)
public bool equals (Object obj)
{
if (! (obj instanceof ParsePosition))
if (! (obj is ParsePosition))
return false;

ParsePosition other = (ParsePosition) obj;
Expand All @@ -156,7 +156,7 @@ public int hashCode()
*/
public String toString ()
{
return (getClass ().getName () + "[index=" + getIndex ()
return (this.GetType().Name + "[index=" + getIndex ()
+ ",errorIndex=" + getErrorIndex () + "]");
}
}
Expand Down

0 comments on commit 82d3183

Please sign in to comment.