Skip to content

Commit d0368b8

Browse files
hansonrhansonr
authored andcommitted
SwingJS-site.zip; preliminary javax.xml work
1 parent de1797f commit d0368b8

File tree

13 files changed

+641
-26
lines changed

13 files changed

+641
-26
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181001183306
1+
20181007153006
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181001183306
1+
20181007153006
27.3 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/math/BigDecimal.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
224224
* @serial
225225
* @see #unscaledValue
226226
*/
227-
private final BigInteger intVal;
227+
private BigInteger intVal;
228228

229229
/**
230230
* The scale of this BigDecimal, as returned by {@link #scale}.
231231
*
232232
* @serial
233233
* @see #scale
234234
*/
235-
private final int scale; // Note: this may have any value, so
235+
private int scale; // Note: this may have any value, so
236236
// calculations must be done in longs
237237

238238
/**
@@ -264,7 +264,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
264264
* less than or equal to {@code Long.MAX_VALUE}, the value can be
265265
* compactly stored in this field and used in computations.
266266
*/
267-
private final transient long intCompact;
267+
private transient long intCompact;
268268

269269
private static StringBuilderHelper myStringBuilder;
270270

@@ -349,12 +349,25 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
349349

350350
// Constructors
351351

352+
public BigDecimal() {
353+
354+
/**
355+
* because we are subclassing Number
356+
*
357+
* @j2sNative
358+
*
359+
* this.valueOf = this.toString;
360+
*
361+
*/
362+
}
363+
352364
/**
353365
* Trusted package private constructor.
354366
* Trusted simply means if val is INFLATED, intVal could not be null and
355367
* if intVal is null, val could not be INFLATED.
356368
*/
357369
BigDecimal(BigInteger intVal, long val, int scale, int prec) {
370+
this();
358371
this.scale = scale;
359372
this.precision = prec;
360373
this.intCompact = val;
@@ -408,6 +421,7 @@ public BigDecimal(char[] in, int offset, int len) {
408421
* @since 1.5
409422
*/
410423
public BigDecimal(char[] in, int offset, int len, MathContext mc) {
424+
this();
411425
// protect against huge length.
412426
if (offset + len > in.length || offset < 0)
413427
throw new NumberFormatException("Bad offset or len arguments for char[] input.");
@@ -892,6 +906,7 @@ public BigDecimal(double val) {
892906
* @since 1.5
893907
*/
894908
public BigDecimal(double val, MathContext mc) {
909+
this();
895910
if (Double.isInfinite(val) || Double.isNaN(val))
896911
throw new NumberFormatException("Infinite or NaN");
897912
// Translate the double into sign, exponent and significand, according
@@ -981,6 +996,7 @@ public BigDecimal(double val, MathContext mc) {
981996
* {@code BigDecimal}.
982997
*/
983998
public BigDecimal(BigInteger val) {
999+
this();
9841000
scale = 0;
9851001
intVal = val;
9861002
intCompact = compactValFor(val);
@@ -1012,6 +1028,7 @@ public BigDecimal(BigInteger val, MathContext mc) {
10121028
* @param scale scale of the {@code BigDecimal}.
10131029
*/
10141030
public BigDecimal(BigInteger unscaledVal, int scale) {
1031+
this();
10151032
// Negative scales are now allowed
10161033
this.intVal = unscaledVal;
10171034
this.intCompact = compactValFor(unscaledVal);
@@ -1034,6 +1051,7 @@ public BigDecimal(BigInteger unscaledVal, int scale) {
10341051
* @since 1.5
10351052
*/
10361053
public BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) {
1054+
this();
10371055
long compactVal = compactValFor(unscaledVal);
10381056
int mcp = mc.precision;
10391057
int prec = 0;
@@ -1080,6 +1098,7 @@ public BigDecimal(BigInteger unscaledVal, int scale, MathContext mc) {
10801098
* @since 1.5
10811099
*/
10821100
public BigDecimal(int val) {
1101+
this();
10831102
this.intCompact = val;
10841103
this.scale = 0;
10851104
this.intVal = null;
@@ -1097,6 +1116,7 @@ public BigDecimal(int val) {
10971116
* @since 1.5
10981117
*/
10991118
public BigDecimal(int val, MathContext mc) {
1119+
this();
11001120
int mcp = mc.precision;
11011121
long compactVal = val;
11021122
int scale = 0;
@@ -1125,6 +1145,7 @@ public BigDecimal(int val, MathContext mc) {
11251145
* @since 1.5
11261146
*/
11271147
public BigDecimal(long val) {
1148+
this();
11281149
this.intCompact = val;
11291150
this.intVal = (val == INFLATED) ? INFLATED_BIGINT : null;
11301151
this.scale = 0;
@@ -1142,6 +1163,7 @@ public BigDecimal(long val) {
11421163
* @since 1.5
11431164
*/
11441165
public BigDecimal(long val, MathContext mc) {
1166+
this();
11451167
int mcp = mc.precision;
11461168
int mode = mc.roundingMode.oldMode;
11471169
int prec = 0;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package javax.xml.datatype;
2+
3+
/**
4+
* minimal; hand written based on API documentation
5+
*
6+
* @author hansonr
7+
*
8+
*/
9+
public class DatatypeConfigurationException extends Exception {
10+
public DatatypeConfigurationException() {
11+
super();
12+
}
13+
14+
15+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package javax.xml.datatype;
2+
3+
import javax.xml.XMLConstants;
4+
import javax.xml.namespace.QName;
5+
6+
public final class DatatypeConstants {
7+
8+
private DatatypeConstants() {
9+
}
10+
11+
public static final Field YEARS = new Field("YEARS", 0);
12+
public static final Field MONTHS = new Field("MONTHS", 1);
13+
public static final Field DAYS = new Field("DAYS", 2);
14+
public static final Field HOURS = new Field("HOURS", 3);
15+
public static final Field MINUTES = new Field("MINUTES", 4);
16+
public static final Field SECONDS = new Field("SECONDS", 5);
17+
18+
public static final class Field {
19+
private final String str;
20+
private final int id;
21+
22+
private Field(final String str, final int id) {
23+
this.str = str;
24+
this.id = id;
25+
}
26+
27+
public String toString() {
28+
return str;
29+
}
30+
31+
public int getId() {
32+
return id;
33+
}
34+
}
35+
36+
public static final QName DATETIME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "dateTime");
37+
public static final QName TIME = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "time");
38+
public static final QName DATE = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "date");
39+
public static final QName GYEARMONTH = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gYearMonth");
40+
public static final QName GMONTHDAY = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gMonthDay");
41+
public static final QName GYEAR = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gYear");
42+
public static final QName GMONTH = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gMonth");
43+
public static final QName GDAY = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "gDay");
44+
public static final QName DURATION = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "duration");
45+
public static final QName DURATION_DAYTIME = new QName(XMLConstants.W3C_XPATH_DATATYPE_NS_URI, "dayTimeDuration");
46+
public static final QName DURATION_YEARMONTH = new QName(XMLConstants.W3C_XPATH_DATATYPE_NS_URI,
47+
"yearMonthDuration");
48+
49+
public static final int MAX_TIMEZONE_OFFSET = -840;
50+
public static final int MIN_TIMEZONE_OFFSET = 840;
51+
52+
public static final int LESSER = -1;
53+
public static final int EQUAL = 0;
54+
public static final int GREATER = 1;
55+
public static final int INDETERMINATE = 2;
56+
public static final int FIELD_UNDEFINED = Integer.MIN_VALUE;
57+
58+
public static final int JANUARY = 1;
59+
public static final int FEBRUARY = 2;
60+
public static final int MARCH = 3;
61+
public static final int APRIL = 4;
62+
public static final int MAY = 5;
63+
public static final int JUNE = 6;
64+
public static final int JULY = 7;
65+
public static final int AUGUST = 8;
66+
public static final int SEPTEMBER = 9;
67+
public static final int OCTOBER = 10;
68+
public static final int NOVEMBER = 11;
69+
public static final int DECEMBER = 12;
70+
71+
72+
73+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package javax.xml.datatype;
2+
3+
import java.math.BigDecimal;
4+
import java.math.BigInteger;
5+
import java.util.GregorianCalendar;
6+
import java.util.regex.Matcher;
7+
import java.util.regex.Pattern;
8+
9+
import swingjs.api.Interface;
10+
11+
/**
12+
* hand written based on API documentation
13+
*
14+
* Does not use BigDecimal
15+
*
16+
* @author hansonr
17+
*
18+
*/
19+
20+
public abstract class DatatypeFactory {
21+
22+
private BigInteger bigI(int x) {
23+
return (x == DatatypeConstants.FIELD_UNDEFINED ? null : BigInteger.valueOf(x));
24+
}
25+
26+
private BigDecimal bigD(int x) {
27+
return (x == DatatypeConstants.FIELD_UNDEFINED ? null : BigDecimal.valueOf(x));
28+
}
29+
30+
protected DatatypeFactory() {
31+
}
32+
33+
public static DatatypeFactory newInstance() throws DatatypeConfigurationException {
34+
return (DatatypeFactory) Interface.getInstance("org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl", false);
35+
}
36+
37+
public abstract Duration newDuration(String s);
38+
39+
public abstract Duration newDuration(long ms);
40+
41+
public abstract Duration newDuration(boolean isPositive, BigInteger years, BigInteger months, BigInteger days,
42+
BigInteger hours, BigInteger minutes, BigDecimal seconds);
43+
44+
public Duration newDuration(boolean isPositive, int years, int months, int days, int hours, int minutes,
45+
int seconds) {
46+
return newDuration(isPositive, bigI(years), bigI(months), bigI(days), bigI(hours), bigI(minutes), bigD(seconds));
47+
}
48+
49+
public Duration newDurationDayTime(String s) {
50+
if (s == null) {
51+
throw new NullPointerException("DatatypeFactory.newDurationDayTime null parameter");
52+
}
53+
return newDuration(s);
54+
}
55+
56+
public Duration newDurationDayTime(long ms) {
57+
return newDuration(ms);
58+
}
59+
60+
public Duration newDurationDayTime(boolean isPositive, BigInteger day, BigInteger hour, BigInteger minute,
61+
BigInteger second) {
62+
return newDuration(isPositive, null, null, day, hour, minute,
63+
(second == null ? null : new BigDecimal(second)));
64+
}
65+
66+
public Duration newDurationDayTime(boolean isPositive, int day, int hour, int minute, int second) {
67+
return newDurationDayTime(isPositive, bigI(day), bigI(hour),
68+
bigI(minute), bigI(second));
69+
}
70+
71+
public Duration newDurationYearMonth(String s) {
72+
if (s == null) {
73+
throw new NullPointerException("DatatypeFactory.newDerationYearMonth null value");
74+
}
75+
return newDuration(s);
76+
}
77+
78+
public Duration newDurationYearMonth(long ms) {
79+
Duration d = newDuration(ms);
80+
BigInteger years = (BigInteger) d.getField(DatatypeConstants.YEARS);
81+
BigInteger months = (BigInteger) d.getField(DatatypeConstants.MONTHS);
82+
return newDurationYearMonth((d.getSign() == -1), years, months);
83+
}
84+
85+
public Duration newDurationYearMonth(boolean isPositive, BigInteger year, BigInteger month) {
86+
return newDuration(isPositive, year == null ? BigInteger.ZERO : year, month == null ? BigInteger.ZERO : month,
87+
null, null, null, null);
88+
}
89+
90+
public Duration newDurationYearMonth(boolean isPositive, int year, int month) {
91+
return newDurationYearMonth(isPositive, bigI(year), bigI(month));
92+
}
93+
94+
public abstract XMLGregorianCalendar newXMLGregorianCalendar();
95+
public abstract XMLGregorianCalendar newXMLGregorianCalendar(String s);
96+
public abstract XMLGregorianCalendar newXMLGregorianCalendar(GregorianCalendar cal);
97+
public abstract XMLGregorianCalendar newXMLGregorianCalendar(BigInteger year, int month, int day, int hour,
98+
int minute, int second, BigDecimal fractionalSecond, int timezone);
99+
100+
public abstract XMLGregorianCalendar newXMLGregorianCalendar(int year, int month, int day, int hour, int minute, int second,
101+
int millisecond, int timezone);
102+
103+
public XMLGregorianCalendar newXMLGregorianCalendarDate(int year, int month, int day, int timezone) {
104+
105+
return newXMLGregorianCalendar(year, month, day, DatatypeConstants.FIELD_UNDEFINED,
106+
DatatypeConstants.FIELD_UNDEFINED,
107+
DatatypeConstants.FIELD_UNDEFINED,
108+
DatatypeConstants.FIELD_UNDEFINED,
109+
timezone);
110+
}
111+
112+
public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours, int minutes, int seconds, int timezone) {
113+
114+
return newXMLGregorianCalendar(DatatypeConstants.FIELD_UNDEFINED, // Year
115+
DatatypeConstants.FIELD_UNDEFINED, // Month
116+
DatatypeConstants.FIELD_UNDEFINED, // Day
117+
hours, minutes, seconds,
118+
DatatypeConstants.FIELD_UNDEFINED, // Millisecond
119+
timezone);
120+
}
121+
122+
public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours, int minutes, int seconds,
123+
BigDecimal fractionalSeconds, int timezone) {
124+
125+
return newXMLGregorianCalendar(null,
126+
DatatypeConstants.FIELD_UNDEFINED,
127+
DatatypeConstants.FIELD_UNDEFINED,
128+
hours, minutes, seconds, fractionalSeconds, timezone);
129+
}
130+
131+
public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours, int minutes, int seconds, int milliseconds,
132+
int timezone) {
133+
BigDecimal bdMS = null; // undefined value
134+
if (milliseconds != DatatypeConstants.FIELD_UNDEFINED) {
135+
if (milliseconds < 0 || milliseconds > 1000) {
136+
throw new IllegalArgumentException("milliseconds must be between 0 and 1000");
137+
}
138+
bdMS = bigD(milliseconds);
139+
}
140+
return newXMLGregorianCalendarTime(hours, minutes, seconds, bdMS, timezone);
141+
}
142+
}

0 commit comments

Comments
 (0)