DoubleSummaryStatistics.sleela
lib/java/jdk-28/java.base/java/util/DoubleSummaryStatistics.sleela · 170 line(s) · sleela
<< lib/java/jdk-28/java.base/java/util/DoubleSummaryStatistics.sleela
SLeeLa file for the Java type java.util.DoubleSummaryStatistics (module java.base). One Java type, one SLeeLa file.
Java Source (JDK 28 API): https://download.java.net/java/early_access/jdk28/docs/api/java.base/java/util/DoubleSummaryStatistics.html
Java kind: class; extends java.lang.Object; implements java.util.function.DoubleConsumer
Status: members from the JDK 28 API (exact signatures).
The SLeeLa functions here are produced from that Java Source. No Java source text is copied. >>
#sleela 3.0
material;
import java.jdk-28;
class DoubleSummaryStatistics {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs. Values are faithful
to the real origin of the Java type: the Java SE / JDK 28 API by Oracle
and the OpenJDK community. >>
String metaVersion = "1.1.0";
int metaId = 3373;
String metaAuthor = "Oracle / OpenJDK";
String metaDate = "2026-11-12";
String metaCopyright = "GPLv2 with Classpath Exception (OpenJDK)";
String metaTrademark = "Java";
String metaCorporation = "Oracle Corporation";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-11-12";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 9;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "Java SE 28 API Specification (JDK 28 early access)";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
String javaType = "java.util.DoubleSummaryStatistics";
String javaModule = "java.base";
String javaSource = "https://download.java.net/java/early_access/jdk28/docs/api/java.base/java/util/DoubleSummaryStatistics.html";
String javaKind = "class";
String javaSuper = "java.lang.Object";
< ---- BEGIN java implementation (ported from the jdk-25 tier by lib/java/jdk-25/tools/jdk28_connect.py) ---- >
< ---- java.util.DoubleSummaryStatistics members (procedural implementation in SLeeLa) ---- >
<< count, sum, min, max and average of the accepted doubles. The sum uses
the same Kahan compensated summation as Java (plus the simple sum for the
infinite/NaN case), so getSum and getAverage match Java bit for bit. >>
long count;
double sum;
double sumCompensation;
double simpleSum;
double min;
double max;
DoubleSummaryStatistics() {
Double D = new Double(0.0);
this.count = 0;
this.sum = 0.0;
this.sumCompensation = 0.0;
this.simpleSum = 0.0;
this.min = D.positiveInfinity();
this.max = D.negativeInfinity();
}
void sumWithCompensation(double value) {
double tmp = value - this.sumCompensation;
double velvel = this.sum + tmp;
this.sumCompensation = (velvel - this.sum) - tmp;
this.sum = velvel;
}
void accept(double value) {
this.count = this.count + 1;
this.simpleSum = this.simpleSum + value;
sumWithCompensation(value);
this.min = Math.min(this.min, value);
this.max = Math.max(this.max, value);
}
void combine(DoubleSummaryStatistics other) {
this.count = this.count + other.count;
this.simpleSum = this.simpleSum + other.simpleSum;
sumWithCompensation(other.sum);
sumWithCompensation(0.0 - other.sumCompensation);
this.min = Math.min(this.min, other.min);
this.max = Math.max(this.max, other.max);
}
long getCount() { return this.count; }
double getSum() {
Double D = new Double(0.0);
double tmp = this.sum - this.sumCompensation;
if (tmp != tmp && D.isInfinite(this.simpleSum)) { return this.simpleSum; }
return tmp;
}
double getMin() { return this.min; }
double getMax() { return this.max; }
double getAverage() {
if (this.count == 0) { return 0.0; }
double c = this.count;
return getSum() / c;
}
String toString() {
return "DoubleSummaryStatistics{count=" + this.count + ", sum=" + fixed6(getSum()) + ", min=" + fixed6(this.min) + ", average=" + fixed6(getAverage()) + ", max=" + fixed6(this.max) + "}";
}
<< Java %f: fixed notation with six decimals, rounded half-up on the
exact binary value (via the Double decimal machinery). >>
String fixed6(double d) {
Double D = new Double(0.0);
if (d != d) { return "NaN"; }
if (D.isInfinite(d)) { if (d > 0.0) { return "Infinity"; } return "-Infinity"; }
String sign = "";
double a = d;
if (a < 0.0 || D.isNegativeZero(a)) { sign = "-"; a = 0.0 - a; }
if (a >= 1.0e12) { return sign + D.toStringOf(a); }
long m = D.scaledRound(a, 6);
long ip = m / 1000000;
long fp = m % 1000000;
String fs = "" + fp;
while (fs != "" && lengthOf(fs) < 6) { fs = "0" + fs; }
return sign + ip + "." + fs;
}
int lengthOf(String s) { return javaStringLength(javaStringFromUtf8(s)); }
< ---- END java implementation ---- >
< ---- generics (SLeeLa erasure, SLEELA.syntax 16.3 and 38.1) ---- >
<< The class is written without Java type parameters: every type variable and
every parameterized or package-qualified reference type erases to Any, and
java.lang.String erases to String. A value of a type parameter travels as
Any; test it with instanceof and cast it where it is used. The Java type
parameters are kept as data in JAVA_TYPE_PARAMETERS. An instance may record
the type arguments its caller means with bindGenericTypeArguments (for an
ArrayList of String, bind the single name java.lang.String). Nothing is
checked against them at run time. >>
static final String JAVA_TYPE_PARAMETERS = "";
String[] genericTypeArguments = new String[0];
public static String genericTypeParameters() { return JAVA_TYPE_PARAMETERS; }
public static int genericTypeParameterCount() { return 0; }
public static String genericTypeParameterName(int index) { return null; }
public DoubleSummaryStatistics bindGenericTypeArguments(String[] arguments) { if (arguments == null) { this.genericTypeArguments = new String[0]; } else { this.genericTypeArguments = arguments; } return this; }
public String genericTypeArgument(int index) { if (index < 0 || index >= arrayLength(genericTypeArguments)) { return null; } return genericTypeArguments[index]; }
public int genericTypeArgumentCount() { return arrayLength(genericTypeArguments); }
< ---- BEGIN java constructors (exact JDK 28 API signatures) ---- >
@throwable("java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException")
public DoubleSummaryStatistics(long count, double min, double max, double sum) { }
< ---- END java constructors ---- >
< ---- BEGIN java signatures (exact JDK 28 API signatures) ---- >
<< Not yet SLeeLa logic: each method returns the default value of its
Java return type. @throwable names what Java throws for it (abstract:
AbstractMethodError, else UnsupportedOperationException, plus the
declared throws). Write the logic from the Java Source above into the
java implementation block; the generator then drops the stub. >>
< ---- END java signatures ---- >
}