Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Daniel Palombo

Greenhorn
+ Follow
since Feb 28, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Palombo

Hello Tom Lee,
I'm not sitting tight in the saddle but I think this shouldn't be wrong:
The JVM (Java Virtuel Machine) is part of the JRE (Java Runtime Environment) (and so also of the JDK - Java Development Kit).
The JVM is the 'processor' which processes your program instructions (your compiled bytecode). The JRE offers all classes (like 'String' for example) needed to enable the JVM to run your program.

@all: Please correct, if I'am wrong
14 years ago
I've got it!

... and must admit that I'soooo 'asinine'

I didn't realise that time in java is relative to the 1.1.1970 !!! So what I did was adding a _day_ to another, resulting perhaps in a day in the fututre ... I really was !!!

I just have to add 5 seconds. That is adding 5000 millisekonds.
This does the trick:


Sometimes talking about a problem is like clening your glasses.
Thanx Ranch!
14 years ago
Hello Keith Lynn and Garrett Rowe,
strange that it doesn't compile or run wrong on your machines, because I sartet it on another machine and it compiled and run well (did a copy and paste from this site):


C:\Temp>java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

C:\Temp>javac timstampDemo.java

C:\Temp>java timstampDemo
23:01:04

C:\Temp>


It's a Windows XP SP2 and the locale is german ...

I'am afraid I was misunerstood:
Let's say I recorded a time since the start of an event, so just 59 seconds passed since the start.
Now I just want to add to this 59 seconds another 5 seconds. So wath I get are 64 seconds, but we don't speak of 64 seconds, we say "One minute and four seconds". That's it: 1:04 or in a given format of HH:mm:ss -> 00:01:04

That's what I want.
By the way, using the SimpleDateFormat class the result is the same, as you can see from my quote.

So, what do you think is wrong here, and - more important - how can I convince java to do what I want?
14 years ago
Hello all,
I wanted do do this:

Timestamp in hh:mm:ss
00:00:59 + 00:00:05 = 00:01:04

I made this code

And this is the output:

23:01:04




I don't want this!!! I don't understand this.
How can I reach my goal?
14 years ago
@fred rosenberger
Yes, thats exactly what I'am doing at the moment. It's obvious that this doubles a part of the code, and - worse - if I change something in the loop that affects a line, I have to remeber this also for the part that processes the last line outside of the loop: I think that is not so good.

I noticed, that if I say

I can avoid the ArrayIndexOutOfBoundsException though the problem with the last line still remains. But it is safer and more like the for (String line : allLines) {...} construction, but without the need of a jumppoint and the possibility to peek at any value in the array.
By the way, the very last line gets a default duration added to the start-timestamp, if it hasn't one.

Stan James' approach remembering the timestamp sounds interesting. Could you exemplify this approach, Stan? As you see above, the manipulation (and with it the parsing of the line) occurs in a separate method. So the loop itself doesn't know anything about timestamps at this moment. It would be a good idea to not to be forced to parse a line more than neccessary (and I'm doing this in the manipulateLine method).
It's in my opinion also a question of 'responsibilities': the manipulation method is responsible to know what to do with the content, not the method calling it, which in contrast only should be aware of "to subsequent lines go together".


We had a question a while ago about reading a file backwards. I still think a reverse buffered reader would be fun.


What are the advantages of this? Could you point out some informational places?

@Martin Mathis
Ashamed I must admit that I haven't understood what you mean. I thought that's what I'am doing: reading (two lines), linking (?, processing them interdependent), go back storing and continuing reading the next one.

Thank you (all) very much for your interest ...
Daniel Palombo
@fred rosenberger
Yes, thats exactly what I'am doing at the moment. It's obvious that this doubles a part of the code, and - worse - if I change something in the loop that affects a line, I have to remeber this also for the part that processes the last line outside of the loop: I think that is not so good.

I noticed, that if I say

I can avoid the ArrayIndexOutOfBoundsException though the problem with the last line still remains. But it is safer and more like the for (String line : allLines) {...} construction, but without the need of a jumppoint and the possibility to peek at any value in the array.
By the way, the very last line gets a default duration added to the start-timestamp, if it hasn't one.

Stan James' approach remembering the timestamp sounds interesting. Could you exemplify this approach, Stan? As you see above, the manipulation (and with it the parsing of the line) occurs in a separate method. So the loop itself doesn't know anything about timestamps at this moment. It would be a good idea to not to be forced to parse a line more than neccessary (and I'm doing this in the manipulateLine method).
It's in my opinion also a question of 'responsibilities': the manipulation method is responsible to know what to do with the content, not the method calling it, which in contrast only should be aware of "to subsequent lines go together".


We had a question a while ago about reading a file backwards. I still think a reverse buffered reader would be fun.


What are the advantages of this? Could you point out some informational places?

@Martin Mathis
Ashamed I must admit that I haven't understood what you mean. I thought that's what I'am doing: reading (two lines), linking (?, processing them interdependent), go back storing and continuing reading the next one.

Thank you (all) very much for your interest ...
Daniel Palombo
14 years ago
Hello to all,
as the subject tells you, I want to manipulate some text of wich lines have interdependent informations.

Example: my textfile consists of lines that show a line-number, a start-timestamp, usually no end-timestamp and a text (it's something like a subtitel script).
1 s000000 "Blabla Inc. proudly presents:"
2 s000008 "a blabla-film production with"
3 s000015 e000020 "...blabla ..."

The third line is a correct line, so line 1 and 2 must be manipulatet. The algorithm should say something like "take a line and, if it has no end-timestamp, take the next line and set its start-timestamp as end-timestamp of the last line".

So my aproach is to put all lines into an array and walk through with a for-loop.

==> ArrayIndexOutOfBoundsException
This can't work, because at the end of the array I reference to the index i+1, which dosn't exist.

So my second aproach was this:


This works, but the very last line of the array is ommitted from processing (which always works on lastLine, not on nextLine, which in the end holds the very last line of the text so the for-loop exits without shifting it to lastLine).

I think that this could be a very common problem (that could be expanded from a two-line to a three- or more-lineProblem), but I haven't found a smart solution yet.

Is there a standard-solution for problems like this, or has anyone an idea how to solve this?

I'd like to apreciate your help!
Thanks a lot!
Daniel Palombo
14 years ago
Hello Conrad,
you are right, you can just give .setText a String, as the documentation says:

void setText(String t)
Sets the text of this TextComponent to the specified text.


setText() is a method inherited from JTextComponent. There is method that's for you

void read(Reader in, Object desc)
Initializes from a stream.



I was just working on this too, so here is a snippet of my code:

In my case, I had Textfiles with special characters (for instance: catalan and romanian characters), so I needed Unicode/ UTF-8 encoding. The important class to process the encoding information is InputStreamReader. If you don't need it like this, you are done with:


That's it! Have a nice day
14 years ago
@Randall Kippen
Your code example is just wat brings me nearer to paradise !!!

@Brian Cole
I think I have to deepen my knowledge about this topic ... Thank you for the good link

Thanx again
14 years ago
Yeepyyy!
It works!

I begin to feel comfortable here

There is one thing that disturbs me a little bit: It's me (or the hard coded program) that has to know, in which charset the filecontent is. It wood be nicer if I could 'automagically' figure out the charset of the file and provide this to the InputStremReader ... (because I don' really know if it's in uinicode, Big Endian, Little Endian etc.)

Thank you very much for your help! Really!!

14 years ago
Hello Ranchers,
I have a big problem with a little JTextArea.

When setting a text like this in a JTextArea, all looks fine:



But when I try to load this text from a file I get nonsense (square characters).

You may ask: How do you get this text to a file? I copy & paste it from the JTextArea. Then (in Windows XP) I generate a new textdocument with the default notepad. The unicode characters show here fine as well. At the moment I want to save it, I get the choise to save it in ANSI, Unicode, Unicode Big Endian or UTF-8. I choose Unicode.

To load the text to my JTextArea I do this:


Hmm, that's too simple I guess.
So, what might the magical lines be to get this rigth???

Thank you for your help!
Daniel Palombo
14 years ago