Skip to content

Instantly share code, notes, and snippets.

@edm00se
Last active Oct 27, 2017
Embed
What would you like to do?
IBM/Lotus Domino SSJS for returning results as a Vector. Handy when expecting multiple values from a document field, when single (string object) is potentially returned.
/**
* @author Eric McCormick
* src: https://edm00se.io/xpages/consistent-multivalue-formatting/
* @param java.util.Object to examine
* @return java.util.Vector of values from originating Object
**/
var util = {
asVec: function(obj){
switch(typeof obj){
case "java.util.Vector": //it's already a Vector, just return it
return obj;
break;
case "java.util.ArrayList": //it's an ArrayList, return it as a Vector
case "Array": //it's an Array prototype, return it as a Vector
var x:java.util.Vector = new java.util.Vector();
var s = obj.size()||obj.length;
for(var i=0; i<s; i++){
x.add(obj[i]);
}
return x;
break;
case "java.lang.String":
default: //it's most likely a String, return it as a Vector
var x:java.util.Vector = new java.util.Vector();
x.add(obj);
return x;
break;
}
}
};
@edm00se

This comment has been minimized.

Copy link
Owner Author

@edm00se edm00se commented Nov 11, 2014

Converted to SSJS util function library. Invoked as util.asVec(java.util.Object:object).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment