Java Expression for tMap

One Star

Java Expression for tMap

Hi, I am still new to Talend and have been looking over the documentation and forum posts for an answer to this problem.
I have created a new Routine in Code.
Code : Routines : resolveName 0.1
package routines;
public class resolveName {
public static String helloExample(String name) {
String str = "fish";
return str;
}
}

The code simply returns fish for what ever the input. I am now trying to use this in a tMap expression builder, I look at the list of categories and it's not listed. What do I have to do to get it to show up? I have restarted Talend after saving.
The other question I've got is for more complex Expressions entered directly into the tMap expression builder, how do I use something like a switch?
switch(row1.name) {
case 1: output X; break;
case 2: output Y: break;
default: output Z;
}

I'm not sure what to code for the 'Output X/Y/Z' bit.
Thanks for any help you can offer.
Seventeen Stars

Re: Java Expression for tMap

hi ncooper and welcome
when you create a new routine and you want that appear in the menu(list) follow the default example :
/*
* user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
* it must be before the "{talendTypes}" key.
*
* 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
* long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
* Short
*
* 3. {Category} define a category for the Function. it is required. its value is user-defined .
*
* 4. {param} 's format is: {param} <type> <name>
*
* <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
* Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
* added. you can have many parameters for the Function.
*
* 5. {example} gives a example for the Function. it is optional.
*/

anyway you can call your static function like that :
yourRoutine.yourStaticFunction(param)

for the second issue you can wrap your switch code in a routine and return the expected value.
ps : in your case do nothing except return default value !
hope it helps you
regards
laurent
One Star

Re: Java Expression for tMap

Thank you for replying, I now have it working.
I will include the comment below.
    /**
* String() Converts a string to junk
*
* {talendTypes} string | String
*
* {Category} importResolver
*
* {param} string() name: string value
*
* {example} String('Cat'):string
*
*/