<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic tjava handle multiple if-else in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/tjava-handle-multiple-if-else/m-p/2518486#M147586</link>
    <description>&lt;P&gt;we have files that we are reading and trying to rename in some scenarios and below code works..&lt;/P&gt;&lt;P&gt;files --&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;data/file1.csv --&amp;gt; after renaming&lt;BR /&gt;data/datefolder=2025-01-01/file.csv&lt;/LI&gt;&lt;LI&gt;data/file2_2025-01-01.csv --&amp;gt; after renaming renaming&lt;BR /&gt;data/datefolder=2025-01-01/file2_2025-01-01.csv&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;String&lt;/SPAN&gt; &lt;SPAN class=""&gt;regex&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;"[0-9]{4}[_-][0-9]{2}[_-][0-9]{2}"&lt;/SPAN&gt;;

java.util.regex.&lt;SPAN class=""&gt;Matcher&lt;/SPAN&gt; &lt;SPAN class=""&gt;m&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; java.util.regex.Pattern.compile(regex).matcher(context.CurrentFileName);

&lt;SPAN class=""&gt;if&lt;/SPAN&gt; (m.find()) {           
            context.CurrentFileDate = &lt;SPAN class=""&gt;"datefolder="&lt;/SPAN&gt;+(m.group(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;).trim().substring(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;,&lt;SPAN class=""&gt;4&lt;/SPAN&gt;))+&lt;SPAN class=""&gt;"-"&lt;/SPAN&gt;+(m.group(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;).trim().substring(&lt;SPAN class=""&gt;5&lt;/SPAN&gt;,&lt;SPAN class=""&gt;7&lt;/SPAN&gt;))+&lt;SPAN class=""&gt;"-"&lt;/SPAN&gt;+(m.group(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;).trim().substring(&lt;SPAN class=""&gt;8&lt;/SPAN&gt;,&lt;SPAN class=""&gt;10&lt;/SPAN&gt;));            
        } &lt;SPAN class=""&gt;else&lt;/SPAN&gt; {
            context.CurrentFileDate = &lt;SPAN class=""&gt;"datefolder="&lt;/SPAN&gt;+formattedDate;                    }

        
        &lt;/PRE&gt;&lt;P&gt;now we are getting interesting file-names and needed some help how i can modify above if-else statement so it can work.&lt;/P&gt;&lt;P&gt;files --&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;data/file1.csv --&amp;gt; after renaming data/datefolder=2025-01-01/file.csv&lt;/LI&gt;&lt;LI&gt;data/file2_2025-01-01.csv --&amp;gt; after renaming renaming data/datefolder=2025-01-01/file2_2025-01-01.csv&lt;/LI&gt;&lt;LI&gt;data/YYYY=2029/file3.csv --&amp;gt; after renaming data/datefolder=2029-01-01/file3.csv&lt;/LI&gt;&lt;LI&gt;&lt;UL&gt;&lt;LI&gt;(SO If there is a prefix of YYYY=2029, modify datefolder to get year from yyyy datefolder=2029-01-01 )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;data/YYYY=2029/MM=03/file4.csv --&amp;gt; after renaming data/datefolder=2029-03-01/file4.csv&lt;/LI&gt;&lt;LI&gt;&lt;UL&gt;&lt;LI&gt;(SO If there is a prefix of YYYY=2029 &amp;amp; MM=03, modify datefolder to get year from yyyy AND Month from mm, so datefolder=2029-03-01 )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;data/YYYY=2029/MM=04/DD=22/file5.csv --&amp;gt; after renaming data/datefolder=2029-04-22/file5.csv&lt;/LI&gt;&lt;LI&gt;&lt;UL&gt;&lt;LI&gt;(SO If there is a prefix of YYYY=2029 &amp;amp; MM=03, modify datefolder to get year from yyyy AND Month from mm and day from dd, so datefolder=2029-04-22 )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;any suggestion how to modify above if-else statement ? since matcher in java can only find based on regex, in what i tried so far .&lt;/P&gt;</description>
    <pubDate>Wed, 21 May 2025 12:53:22 GMT</pubDate>
    <dc:creator>talend777</dc:creator>
    <dc:date>2025-05-21T12:53:22Z</dc:date>
    <item>
      <title>tjava handle multiple if-else</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tjava-handle-multiple-if-else/m-p/2518486#M147586</link>
      <description>&lt;P&gt;we have files that we are reading and trying to rename in some scenarios and below code works..&lt;/P&gt;&lt;P&gt;files --&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;data/file1.csv --&amp;gt; after renaming&lt;BR /&gt;data/datefolder=2025-01-01/file.csv&lt;/LI&gt;&lt;LI&gt;data/file2_2025-01-01.csv --&amp;gt; after renaming renaming&lt;BR /&gt;data/datefolder=2025-01-01/file2_2025-01-01.csv&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;String&lt;/SPAN&gt; &lt;SPAN class=""&gt;regex&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;"[0-9]{4}[_-][0-9]{2}[_-][0-9]{2}"&lt;/SPAN&gt;;

java.util.regex.&lt;SPAN class=""&gt;Matcher&lt;/SPAN&gt; &lt;SPAN class=""&gt;m&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; java.util.regex.Pattern.compile(regex).matcher(context.CurrentFileName);

&lt;SPAN class=""&gt;if&lt;/SPAN&gt; (m.find()) {           
            context.CurrentFileDate = &lt;SPAN class=""&gt;"datefolder="&lt;/SPAN&gt;+(m.group(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;).trim().substring(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;,&lt;SPAN class=""&gt;4&lt;/SPAN&gt;))+&lt;SPAN class=""&gt;"-"&lt;/SPAN&gt;+(m.group(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;).trim().substring(&lt;SPAN class=""&gt;5&lt;/SPAN&gt;,&lt;SPAN class=""&gt;7&lt;/SPAN&gt;))+&lt;SPAN class=""&gt;"-"&lt;/SPAN&gt;+(m.group(&lt;SPAN class=""&gt;0&lt;/SPAN&gt;).trim().substring(&lt;SPAN class=""&gt;8&lt;/SPAN&gt;,&lt;SPAN class=""&gt;10&lt;/SPAN&gt;));            
        } &lt;SPAN class=""&gt;else&lt;/SPAN&gt; {
            context.CurrentFileDate = &lt;SPAN class=""&gt;"datefolder="&lt;/SPAN&gt;+formattedDate;                    }

        
        &lt;/PRE&gt;&lt;P&gt;now we are getting interesting file-names and needed some help how i can modify above if-else statement so it can work.&lt;/P&gt;&lt;P&gt;files --&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;data/file1.csv --&amp;gt; after renaming data/datefolder=2025-01-01/file.csv&lt;/LI&gt;&lt;LI&gt;data/file2_2025-01-01.csv --&amp;gt; after renaming renaming data/datefolder=2025-01-01/file2_2025-01-01.csv&lt;/LI&gt;&lt;LI&gt;data/YYYY=2029/file3.csv --&amp;gt; after renaming data/datefolder=2029-01-01/file3.csv&lt;/LI&gt;&lt;LI&gt;&lt;UL&gt;&lt;LI&gt;(SO If there is a prefix of YYYY=2029, modify datefolder to get year from yyyy datefolder=2029-01-01 )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;data/YYYY=2029/MM=03/file4.csv --&amp;gt; after renaming data/datefolder=2029-03-01/file4.csv&lt;/LI&gt;&lt;LI&gt;&lt;UL&gt;&lt;LI&gt;(SO If there is a prefix of YYYY=2029 &amp;amp; MM=03, modify datefolder to get year from yyyy AND Month from mm, so datefolder=2029-03-01 )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;data/YYYY=2029/MM=04/DD=22/file5.csv --&amp;gt; after renaming data/datefolder=2029-04-22/file5.csv&lt;/LI&gt;&lt;LI&gt;&lt;UL&gt;&lt;LI&gt;(SO If there is a prefix of YYYY=2029 &amp;amp; MM=03, modify datefolder to get year from yyyy AND Month from mm and day from dd, so datefolder=2029-04-22 )&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;any suggestion how to modify above if-else statement ? since matcher in java can only find based on regex, in what i tried so far .&lt;/P&gt;</description>
      <pubDate>Wed, 21 May 2025 12:53:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tjava-handle-multiple-if-else/m-p/2518486#M147586</guid>
      <dc:creator>talend777</dc:creator>
      <dc:date>2025-05-21T12:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: tjava handle multiple if-else</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tjava-handle-multiple-if-else/m-p/2541387#M149332</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Instead of extending multiple if-else blocks, the recommended approach is to extract YYYY / MM / DD independently using regex, then build the date based on what is present. This keeps the logic simple and scalable.&lt;/P&gt;&lt;P&gt;Example (tJava-compatible):&lt;/P&gt;&lt;P&gt;String filePath = context.CurrentFileName;&lt;/P&gt;&lt;P&gt;String year = null;&lt;BR /&gt;String month = "01";&lt;BR /&gt;String day = "01";&lt;/P&gt;&lt;P&gt;// Match YYYY=2029&lt;BR /&gt;java.util.regex.Matcher y =&lt;BR /&gt;java.util.regex.Pattern.compile("YYYY=(\\d{4})").matcher(filePath);&lt;BR /&gt;if (y.find()) {&lt;BR /&gt;year = y.group(1);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Match MM=03&lt;BR /&gt;java.util.regex.Matcher m =&lt;BR /&gt;java.util.regex.Pattern.compile("MM=(\\d{2})").matcher(filePath);&lt;BR /&gt;if (m.find()) {&lt;BR /&gt;month = m.group(1);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Match DD=22&lt;BR /&gt;java.util.regex.Matcher d =&lt;BR /&gt;java.util.regex.Pattern.compile("DD=(\\d{2})").matcher(filePath);&lt;BR /&gt;if (d.find()) {&lt;BR /&gt;day = d.group(1);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Fallback: date inside filename (2025-01-01 or 2025_01_01)&lt;BR /&gt;if (year == null) {&lt;BR /&gt;java.util.regex.Matcher f =&lt;BR /&gt;java.util.regex.Pattern.compile("(\\d{4})[_-](\\d{2})[_-](\\d{2})")&lt;BR /&gt;.matcher(filePath);&lt;BR /&gt;if (f.find()) {&lt;BR /&gt;year = f.group(1);&lt;BR /&gt;month = f.group(2);&lt;BR /&gt;day = f.group(3);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Final fallback&lt;BR /&gt;if (year == null) {&lt;BR /&gt;context.CurrentFileDate = "datefolder=" + formattedDate;&lt;BR /&gt;} else {&lt;BR /&gt;context.CurrentFileDate =&lt;BR /&gt;"datefolder=" + year + "-" + month + "-" + day;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Why this works well:&lt;/P&gt;&lt;P&gt;Avoids deep if-else chains&lt;/P&gt;&lt;P&gt;Handles partial paths (YYYY, YYYY/MM, YYYY/MM/DD)&lt;/P&gt;&lt;P&gt;Safely defaults missing month/day to 01&lt;/P&gt;&lt;P&gt;Still supports dates embedded in filenames&lt;/P&gt;&lt;P&gt;Best practice:&lt;BR /&gt;When filename patterns evolve, extract each date component independently and compose the final value, rather than trying to match all cases in a single regex.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Gourav&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jan 2026 09:33:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tjava-handle-multiple-if-else/m-p/2541387#M149332</guid>
      <dc:creator>gouravdubey5</dc:creator>
      <dc:date>2026-01-23T09:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: tjava handle multiple if-else</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tjava-handle-multiple-if-else/m-p/2541593#M149339</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This approach also makes it easy to support future filename or folder variations, since each date component is handled independently. Missing values safely default to 01, avoiding additional conditional logic.&lt;/P&gt;&lt;P&gt;If this solution addresses the requirement, please mark it as Accepted Solution.&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Gourav&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jan 2026 06:33:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tjava-handle-multiple-if-else/m-p/2541593#M149339</guid>
      <dc:creator>gouravdubey5</dc:creator>
      <dc:date>2026-01-27T06:33:03Z</dc:date>
    </item>
  </channel>
</rss>

