TalendStringUtil Routines - Cloud

Talend Cloud Data Management Platform Studio User Guide

Version
Cloud
Language
English (United States)
Product
Talend Cloud
Module
Talend Management Console
Talend Studio
Content
Design and Development

The TalendStringUtil class contains only one routine DECODE that allows you to search a value in a port. You can access the routine by double-clicking the TalendStringUtil node under the system routines folder in the Repository tree view.

Routine

Description

Syntax

DECODE

Searches a port for a value you specify. If the function finds the value, it returns a result value, which you define. You can build an unlimited number of searches within a DECODE function.

TalendStringUtil.DECODE(value, defaultValue, search1, result1[, search2, result2]...

  • value: the value you want to search.

  • defaultValue: the value you want to return if the search does not find a matching value. The default value can be set to null.

  • search: the value for which you want to search. The search value must have the same datatype as the value argument.

  • result: the value you want to return if the search finds a matching value.

Below is an example of how to use the DECODE routine with a tJava component. You need to add a tJava component to a new Job, then enter the following code, which will search the value for 10, in the Code field on the Basic settings view of the tJava component.

TalendStringUtil<Integer,String> example = new TalendStringUtil<Integer,String>();
System.out.println(example.DECODE(10, "error", 5, "five", 10, "ten", 15, "fifteen", 20, "twenty"));

Note that you need to create a new object of the TalendStringUtil type, and better to use generic type to constrain the input data, then use the object to call the DECODE routine.

Press F6 to run the Job. It will return ten, which is the result of the value 10.