Last active
October 27, 2017 15:37
-
-
Save edm00se/8301433 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Converted to SSJS util function library. Invoked as util.asVec(java.util.Object:object).