I'm having difficulty comparing Strings and Times (as in TimeStamp e.g. "hh:mm:ss"). Below are two snippets of the culprit code.
How the code is setup and expectation:
When a user queries a database (embedded SQLite), the database field data captured is dumped into an ObservableList<String> array for each field. This data is then populated to corresponding JavaFX TextFields and TextAreas. The intention is to allow the user to look at the data and make changes to any of the fields as necessary. When the user clicks an "Update" button, the Update method will check each TextField and TextArea and compare that data to the original stored in the array it was populated from. If that data is different, then the user field data is passed to a method that updates the corresponding field in the database. Now this approach seems to work with comparisons of TextFields when it is 'text only', but fails when trying to compare TextAreas or Time strings.
This works when it is a single line text string and not a TextArea or TimeStamp string:
Problem:
1) Strings (TextArea): I've tried a number of different ways of comparison and used suggestions from other sites or forums. A number of them vary to comparing length(), pass into Builders, etc nothing seems to be working. This issue is comparing TextArea fields. I'm resetting the StringBuilder (sb), dumping the user field into the 'sb' and then comparing to the original array source. Comparing as I do above doesn't work.
2) TimeStamp (TextField): At first, I was simply comparing as the first example above. It would not work though they were different. The same comparison.. user field vs original source. Here, only Videos and Audio require TimeStamps. And it is required input. However, a video sample may be at the beginning and not mid-stream, so "00:00:00" would be the start, but would also fail. So I tried using the DateTime, Date and SimpleDateFormat as recommended on a couple sites, but that fails too:
Code:
try {
if (this.CurrentSourceType.equals("Video") || this.CurrentSourceType.equals("Audio")) {
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
//this.tbxTimeStamp.setText(CheckTimeStamp(tbxTimeStamp.getText()));
Date sTime = sdf.parse(this.tbxSearchTimeStamp.getText());
Date dTime = sdf.parse(this.CurrentSelectionData.get(10));
if (sTime != dTime) {
search.UpdateField(CurrentNoteID, "Comment", "CommentID", "TimeStamp", tbxSearchTimeStamp.getText());
}
}
}catch(ParseException pe){
pe.printStackTrace();
}
Last edited by SVOhio; January 25th, 2019 at 08:44 AM.
Reason: Clarification
Ok, the TextArea comparison works now because I'm an idiot and was missing the "!" to indicate 'not equal'... so no issue there. However, a TimeStamp text string comparison still does not. Sorry for my stupidity there.
Code:
try {
if (this.CurrentSourceType.equals("Video") || this.CurrentSourceType.equals("Audio")) {
DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
//this.tbxTimeStamp.setText(CheckTimeStamp(tbxTimeStamp.getText()));
Date sTime = sdf.parse(this.tbxSearchTimeStamp.getText());
Date dTime = sdf.parse(this.CurrentSelectionData.get(10));
if (sTime != dTime) {
search.UpdateField(CurrentNoteID, "Comment", "CommentID", "TimeStamp", tbxSearchTimeStamp.getText());
}
}
}catch(ParseException pe){
pe.printStackTrace();
}
I may have solved my problem, though I'm not sure if it is the correct way. In essence, I pass my data objects as generic "Objects" into a return method called "ValuesAreDifferent(Object, Object)" and let it handle the conversion and comparing - defaulting conversions to a String. If the values are different, then it will pass a 'true' to indicate updating the database. This solved my TextArea and Time String issues.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.