Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[ -2147483649, "double" ],
[ 4294967295, "int" ],
[ 4294967296, "double" ],
[ 1.5, "double" ],
[ [ "an array" ], "java.lang.Object" ], // TODO: test/fix this
// java objects
[ java.newInstanceSync("java.lang.String", "other string"), "java.lang.String" ],
[ java.newInstanceSync("java.lang.Boolean", "false"), "boolean" ],
[ java.newInstanceSync("java.lang.Integer", "2"), "int" ],
[ java.newInstanceSync("java.lang.Long", "2"), "long" ],
[ java.newInstanceSync("java.lang.Float", "2"), "int" ],
[ java.newInstanceSync("java.lang.Float", "1.5"), "double" ],
[ java.newInstanceSync("java.lang.Double", "2"), "int" ],
[ java.newInstanceSync("java.lang.Double", "1.5"), "double" ],
[ java.newInstanceSync("javax.management.Attribute", "name", "value"), "javax.management.Attribute" ]
].forEach(function(value) {
var param = value[0];
var javaClass = value[1];
it("returns \"" + javaClass + "\" for argument value \"" + param + "\" and typeof \"" + typeof param + "\"", function() {
assert.strictEqual(conversions.v8ToJavaClass(param), javaClass);
});
});
it("throws an exception when the object cannot be converted", function() {
assert.throws(
function() {
conversions.v8ToJavaClass(undefined);
},
[ "some string", "java.lang.String" ],
[ false, "boolean" ],
[ 1, "int" ],
[ -2147483648, "int" ],
[ -2147483649, "double" ],
[ 4294967295, "int" ],
[ 4294967296, "double" ],
[ 1.5, "double" ],
[ [ "an array" ], "java.lang.Object" ], // TODO: test/fix this
// java objects
[ java.newInstanceSync("java.lang.String", "other string"), "java.lang.String" ],
[ java.newInstanceSync("java.lang.Boolean", "false"), "boolean" ],
[ java.newInstanceSync("java.lang.Integer", "2"), "int" ],
[ java.newInstanceSync("java.lang.Long", "2"), "long" ],
[ java.newInstanceSync("java.lang.Float", "2"), "int" ],
[ java.newInstanceSync("java.lang.Float", "1.5"), "double" ],
[ java.newInstanceSync("java.lang.Double", "2"), "int" ],
[ java.newInstanceSync("java.lang.Double", "1.5"), "double" ],
[ java.newInstanceSync("javax.management.Attribute", "name", "value"), "javax.management.Attribute" ]
].forEach(function(value) {
var param = value[0];
var javaClass = value[1];
it("returns \"" + javaClass + "\" for argument value \"" + param + "\" and typeof \"" + typeof param + "\"", function() {
assert.strictEqual(conversions.v8ToJavaClass(param), javaClass);
});
});
it("throws an exception when the object cannot be converted", function() {
it("emits an error when the object method does not exist", function(done) {
var obj1 = java.newInstanceSync("javax.management.Attribute", "attributeName1", "value1");
var paramsClass = [];
var params = [];
var methodName = "nonExistentMethod";
javaReflection.emit = function(ev, data) {
if (ev === "error" && data.toString().match(/java\.lang\.NoSuchMethodException/)) {
done();
}
};
javaReflection.invokeMethod(obj1, methodName, paramsClass, params, function() {
assert(false, "no exception thrown");
});
});
mbeanServerConnection.mbeanServerConnection.queryMBeans = function(objName, queryObject, callback) {
var instance = java.newInstanceSync("javax.management.ObjectInstance", "MBean1:type=MBean1", "java.lang.Object");
var instances = {
toArray: function(callback) {
callback(undefined, [instance]);
}
};
callback(undefined, instances);
};
}
});
child.on('close', function(code){
console.log('child process closed with code ' + code);
});
child.on('exit', function(code) {
console.log('child process exited with code ' + code);
self.columnDataClassifier = java.newInstanceSync('edu.stanford.nlp.classify.ColumnDataClassifier', self.properties);
});
}
}
self.useCDCClassifier = (self.properties.getPropertySync('loadClassifier', '') !== '' || self.properties.getPropertySync('trainFile', '') !== '') ? true : false;
self.dataSet = java.newInstanceSync("edu.stanford.nlp.classify.Dataset");
if (!hasSpawned)
self.columnDataClassifier = java.newInstanceSync('edu.stanford.nlp.classify.ColumnDataClassifier', self.properties);
};
stanfordClassifier.prototype.syncClassifier = function() {
var self = this;
if(!self.dataSet){
throw new Error('No dataset found');
}
self.classifier = self.columnDataClassifier.makeClassifierSync(self.dataSet);
if (self.properties.getPropertySync('serializeTo', '') !== ''){
var fos = java.newInstanceSync('java.io.FileOutputStream', self.properties.getPropertySync('serializeTo'));
var oos = java.newInstanceSync('java.io.ObjectOutputStream', fos);
oos.writeObject(self.classifier, function(){
oos.closeSync();
});
}
};
stanfordClassifier.prototype.classify = function(string) {
function createDocument(title, content) {
var fieldStoreYes = java.callStaticMethodSync("org.apache.lucene.document.Field$Store", "valueOf", "YES");
var doc = java.newInstanceSync("org.apache.lucene.document.Document");
doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "title", title, fieldStoreYes));
doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "content", content, fieldStoreYes));
return doc;
}
}
if (this.iteratorSync) {
return DB.arraySync(this);
}
if (this instanceof Array) {
/*
if (this.length == 0) { return DB.arraySync(); }
var r = DB.arraySync(this[0]);
for (var i = 1; i < this.length; i++) {
r = DB.arraySync(r, this[i]);
}
return r;
*/
return this;
}
var o = java.newInstanceSync("java.util.HashMap");
for (var f in this) {
if (typeof (this[f]) == 'function') { continue; }
o.putSync(f, this[f]);
}
return o;
}
function printObjectArray( list ){
stanfordClassifier.prototype.syncClassifier = function() {
var self = this;
if(!self.dataSet){
throw new Error('No dataset found');
}
self.classifier = self.columnDataClassifier.makeClassifierSync(self.dataSet);
if (self.properties.getPropertySync('serializeTo', '') !== ''){
var fos = java.newInstanceSync('java.io.FileOutputStream', self.properties.getPropertySync('serializeTo'));
var oos = java.newInstanceSync('java.io.ObjectOutputStream', fos);
oos.writeObject(self.classifier, function(){
oos.closeSync();
});
}
};
stanfordClassifier.prototype.classify = function(string) {
function createDocument(title, content) {
var fieldStoreYes = java.callStaticMethodSync("org.apache.lucene.document.Field$Store", "valueOf", "YES");
var doc = java.newInstanceSync("org.apache.lucene.document.Document");
doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "title", title, fieldStoreYes));
doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "content", content, fieldStoreYes));
return doc;
}