-
-
Save edm00se/0c0815cca705f190d819403b8ef75179 to your computer and use it in GitHub Desktop.
a Java alternative to my SSJS getValueAsVector helper function https://gist.github.com/edm00se/8301433
This file contains 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
/** | |
* Java method version of my getValueAsVector SSJS helper function. | |
* | |
* Primarily accounts for Vector, any List, or String values as | |
* input object. The newly created Vectors are Vector<Object> as | |
* it's generic enough to work. | |
* | |
* One day, IBM will upgrade the | |
* JVM to >=1.7, which will let us switch off a String value, letting | |
* me achieve the same thing as with the SSJS implementation. | |
* | |
* @param obj Object to examine. | |
* @return Vector of value(s) from originating Object. | |
*/ | |
public static Vector<?> getValueAsVector(Object obj) { | |
if(obj instanceof java.util.Vector){ | |
return (Vector<?>) obj; | |
}else if( obj instanceof ArrayList ) { | |
List<?> o = (List<?>) obj; | |
Vector<Object> tmpVec = new Vector<Object>(); | |
for(int i=0;i<o.size();i++){ | |
tmpVec.add(o.get(i)); | |
} | |
return tmpVec; | |
}else { | |
Vector<Object> tmpVec = new Vector<Object>(); | |
tmpVec.add(obj); | |
return tmpVec; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment