[resolved] string comparison

Highlighted

[resolved] string comparison

I have the below code :
================================================================================================================
String fileName;
String delim = "-";
globalMap.put("basename",input_row.basename); //system
globalMap.put("md5",input_row.md5); //System calculated MD5
fileName = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String tokens[] = fileName.split(delim); //seperate by delimiter of "-"
StringBuffer sb = new StringBuffer(128); //create string buffer
for (int i = 0; i < tokens.length; i++) //iterate through filename
{
if(i ==1)
{
context.file_type = tokens; //Get file load name from filename
}
if (i == 7) //get MD5 String
{
globalMap.put("_md5", tokens.substring(0,32));
context.md5_message = (String)globalMap.get("_md5"); //assign file MD5 to context
}
}
context.basename_message = (String)globalMap.get("basename");
context.guid_message = context.basename_message.substring(25,59);
System.out.println("Assigned Contexts from received file");
System.out.println(context.guid_message); //GUID (IN FILENAME)
System.out.println(context.md5_message); //MD5 (IN FILENAME)
System.out.println(context.basename_message); //FILENAME
System.out.println(context.file_type); //TYPE OF LOAD

System.out.println("Actual Values");
System.out.println((String)globalMap.get("md5"));
System.out.println(((String)globalMap.get("tFileList_1_CURRENT_FILE")));
//(String)globalMap.get("md5") == context.md5_message
if ((String)globalMap.get("md5") == (String)context.md5_message)
{
System.out.println("ITS a MATCH");
}
else
{
System.out.println("Waaaah, waaaah , waaaahh");
}
================================================================================================================
when i compare , the 2 strings above:
if ((String)globalMap.get("md5") == (String)context.md5_message)
it never proves true:
I have pushed my results to screen :
================================================================================================================Assigned Contexts from received file
4f2c2204-9e2f-492a-9c0d-8cd6922a1e
805262c7bd389bc1d0a612f71facce6c //System.out.println(context.md5_message);

20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
EventLoad
Actual Values
805262c7bd389bc1d0a612f71facce6c //System.out.println((String)globalMap.get("md5"));
20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
Waaaah, waaaah , waaaahh
================================================================================================================
on my output the strings are the same ...
what am i missing ,

Accepted Solutions
Highlighted

Re: [resolved] string comparison

I have the below code :
================================================================================================================
String fileName;
String delim = "-";
globalMap.put("basename",input_row.basename); //system
globalMap.put("md5",input_row.md5); //System calculated MD5
fileName = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String tokens[] = fileName.split(delim); //seperate by delimiter of "-"
StringBuffer sb = new StringBuffer(128); //create string buffer
for (int i = 0; i < tokens.length; i++) //iterate through filename
{
if(i ==1)
{
context.file_type = tokens; //Get file load name from filename
}
if (i == 7) //get MD5 String
{
globalMap.put("_md5", tokens.substring(0,32));
context.md5_message = (String)globalMap.get("_md5"); //assign file MD5 to context
}
}
context.basename_message = (String)globalMap.get("basename");
context.guid_message = context.basename_message.substring(25,59);
System.out.println("Assigned Contexts from received file");
System.out.println(context.guid_message); //GUID (IN FILENAME)
System.out.println(context.md5_message); //MD5 (IN FILENAME)
System.out.println(context.basename_message); //FILENAME
System.out.println(context.file_type); //TYPE OF LOAD

System.out.println("Actual Values");
System.out.println((String)globalMap.get("md5"));
System.out.println(((String)globalMap.get("tFileList_1_CURRENT_FILE")));
//(String)globalMap.get("md5") == context.md5_message
if ((String)globalMap.get("md5") == (String)context.md5_message)
{
System.out.println("ITS a MATCH");
}
else
{
System.out.println("Waaaah, waaaah , waaaahh");
}
================================================================================================================
when i compare , the 2 strings above:
if ((String)globalMap.get("md5") == (String)context.md5_message)
it never proves true:
I have pushed my results to screen :
================================================================================================================Assigned Contexts from received file
4f2c2204-9e2f-492a-9c0d-8cd6922a1e
805262c7bd389bc1d0a612f71facce6c //System.out.println(context.md5_message);

20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
EventLoad
Actual Values
805262c7bd389bc1d0a612f71facce6c //System.out.println((String)globalMap.get("md5"));
20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
Waaaah, waaaah , waaaahh
================================================================================================================
on my output the strings are the same ...
what am i missing ,

I have use equals()

View solution in original post


All Replies
Highlighted

Re: [resolved] string comparison

I have the below code :
================================================================================================================
String fileName;
String delim = "-";
globalMap.put("basename",input_row.basename); //system
globalMap.put("md5",input_row.md5); //System calculated MD5
fileName = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String tokens[] = fileName.split(delim); //seperate by delimiter of "-"
StringBuffer sb = new StringBuffer(128); //create string buffer
for (int i = 0; i < tokens.length; i++) //iterate through filename
{
if(i ==1)
{
context.file_type = tokens; //Get file load name from filename
}
if (i == 7) //get MD5 String
{
globalMap.put("_md5", tokens.substring(0,32));
context.md5_message = (String)globalMap.get("_md5"); //assign file MD5 to context
}
}
context.basename_message = (String)globalMap.get("basename");
context.guid_message = context.basename_message.substring(25,59);
System.out.println("Assigned Contexts from received file");
System.out.println(context.guid_message); //GUID (IN FILENAME)
System.out.println(context.md5_message); //MD5 (IN FILENAME)
System.out.println(context.basename_message); //FILENAME
System.out.println(context.file_type); //TYPE OF LOAD

System.out.println("Actual Values");
System.out.println((String)globalMap.get("md5"));
System.out.println(((String)globalMap.get("tFileList_1_CURRENT_FILE")));
//(String)globalMap.get("md5") == context.md5_message
if ((String)globalMap.get("md5") == (String)context.md5_message)
{
System.out.println("ITS a MATCH");
}
else
{
System.out.println("Waaaah, waaaah , waaaahh");
}
================================================================================================================
when i compare , the 2 strings above:
if ((String)globalMap.get("md5") == (String)context.md5_message)
it never proves true:
I have pushed my results to screen :
================================================================================================================Assigned Contexts from received file
4f2c2204-9e2f-492a-9c0d-8cd6922a1e
805262c7bd389bc1d0a612f71facce6c //System.out.println(context.md5_message);

20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
EventLoad
Actual Values
805262c7bd389bc1d0a612f71facce6c //System.out.println((String)globalMap.get("md5"));
20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
Waaaah, waaaah , waaaahh
================================================================================================================
on my output the strings are the same ...
what am i missing ,

I have use equals()

View solution in original post

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog