1
0
mirror of https://github.com/quinton-ashley/java2js synced 2024-12-29 10:11:54 +01:00
java2js/jdk/java/lang/String.js
Quinton Ashley 99bf6d6296 1.0.12
2022-01-14 12:41:43 -05:00

38 lines
954 B
JavaScript
Executable File

jdk.imports['java.lang.String'].load = async () => {
const Formatter = await jdk.import('java.util.Formatter');
// String is special, I just extended js String prototype
String.prototype.hashCode = function () {
var hash = 0,
i,
chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
String.prototype.isEmpty = function () {
return this.length == 0;
};
String.prototype.contains = function (substr) {
return this.includes(substr);
};
String.prototype.equals = function (o) {
return this == o;
};
String.prototype.toCharArray = function (o) {
return this.split('');
};
// static methods
String.valueOf = (c) => {
return c.toString();
};
String.format = (format, ...args) => {
return new Formatter().format(format, ...args);
};
jdk.java.lang.String = String;
};