This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.

Landon Blake

Ranch Hand
+ Follow
since Oct 15, 2004
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 Landon Blake

It's been a long time since I've come to the ranch. :] It is good to be back.

I'm an experienced Java developer fooling around with Groovy. I've got an existing Swing/Java desktop program with an existing plug-in architecture. I'd like to make it possible to script the application using Groovy. To make this easier, I need to expose the "plug-in remote" object to Groovy scripts. I think I can do this by passing the scripts the plug-in remote object in a Binding object. However, all the examples I could find seem to pass only simple variables to scripts in the Binding object. Is there a way to pass a live Java object from my destkop program to the Groovy script?

Thanks for the help!

Landon
3 years ago
I would like to know if anyone here can suggest alternatives to the JGoodies Validation Framework for validation of user input collected with a Swing GUI. I found this post:

http://www.javalobby.org/java/forums/t20551.html

Is there anything else out there? I'm looking for something released under an open source license.

Thanks for the suggestions.

Landon
8 years ago
Call me a slimy salamander. I sure did miss it.

Thanks,

Landon
9 years ago
Thanks for the response. I acutally looked at the wrapper class for Long, but it doesn't appear to have a "toBits" method like Integer and Double. However, it does have a toBinaryString method. However, it doesn't look like Long has a method that creates a Long from a binary string representation. The decode method only works with decimal, hex, and octal. If I'm not missing something I'll have to whip up a utility class that contains the methods to move Long objects back and forth from a binary format.

Thanks for the help.

Landon
9 years ago
Is there a class in the standard library, or a class in an open source library that allows the client code to easy convert a primitive type like boolean, long, double, or integer to binary form and back again? I don't want to use the DataInputStream and DataOutputStream for this purpose, since I'm not writing to files and this seems like overkill.

I can write my own class to do this work, but why reinvent the wheel?

Thanks for the help.

Landon
9 years ago
Joe,

I did read the API doc, but I thought I might not be understanding the behavior correctly. You response makes sense. I think I am going to index with a RandomAccessFile after all.

Thanks.

Landon
10 years ago
If the BufferedReader.reset() method is called and no marks have been set, will the reader move to the start of the stream? (This isn't confirmed by the Javadoc. I'm guessing this isn't the case.)

If this isn't the case, what is the best way to reset a reader to the start of a stream, if this behavior is supported by the stream? Do I need to create a new Reader object to do this?

I'm trying to write a method that accesses the lines in a text file when passed the line number. I need to reset my Reader object to the start of the file if the line number passed to the method is before the current line number being read by the reader.

Note: I don't want to use a RandomAccessFile at this point. I hope to do this in a future implementation.

Thanks,

Landon
10 years ago
Thanks for the quick response Joe.

The article you linked to is an interesting one. I will read it over.

Thanks,

Landon
10 years ago
I'm working on a little project in which I need to set up random access to lines in a CSV text file. (I can't use a database for this particular project, I have to work with CSV files.)

I have two (2) simple questions:

[1] Is there an existing class or classes that can index the lines in a text file? No need to grow my own if there is something out there I can use...I did some online searching for terms like "java random access text file" or "java indexed text file" but didn't come up with much.

[2] The Javadoc for the RandomAccessFile.readLine method states that: "Each byte is converted into a character by taking the byte's value for the lower eight bits of the character and setting the high eight bits of the character to zero. This method does not, therefore, support the full Unicode character set." What does this mean in a practical sense? Does it mean that I will be limited to the ASCII character set? (I can probably live with this.)

Links:
readLine method
RandomAccessFile class

Thanks,

Landon

[ February 27, 2008: Message edited by: Landon Blake ]
[ February 27, 2008: Message edited by: Landon Blake ]
10 years ago
Ulf,

Thanks for the response. I'm glad that my question made sense. I think I'm going to end up using a GlyphVector. I'll get its bounds as a Rectangle2D and then extract the height in user units from that.

Thanks,

Landon
10 years ago
I'm having some trouble determining how font size (which is specified in points) relates to the user space coordinate system used to draw Java shapes using the Graphics2D object. If I create a font that is 10 points high, and a square that is 10 units by 10 units and draw them on the same JPanel using a Graphics2D object, how will their sizes compare?

Does this question make sense? I know that there are approximately 72 points to an inch. Does this mean that a Glyph that was drawn 10 points tall would be 720 pixels tall?

Thanks,

Landon
10 years ago
What is the easiest way to find elements with the same Value in a List? Is there a utility class that allows you to determine if a list contains duplicate "values"? How about the number of duplicate values?

Thanks,

Landon
10 years ago
Thanks Roger.

In this case, would you have the library method throw a checked or an unchecked exception if an invalid argument value is passed by the client code?

Landon
10 years ago
I have another short "Java Programming In General" question.

When is it appropriate to validate mathod arguments when using a Java
library? Should this be done by the client code that uses the library
BEFORE arguments are passed to the library code, or should it be done
AFTER the client code has made the method call, within the library
code?

For example: I have a method that will accept a String representing
an angle in Degrees-Minutes-Seconds format and returns the same angle
in Decimal Degrees format. Should I check for a valid String argument
within this method, or should I indicate that this responsibility
belongs to the client code?

Here is why I ask. I've been reading about the proper use of Java
Exceptions. Most of the material I've read seems to indicate that
Exceptions generated by improper use of an API (invalid method
arguments as an example) should throw unchecked Exceptions. This makes
sense if the client code is responsible for the validity of method
arguments. If the library code is responsible, it seems more
reasonable to throw checked Exceptions.

Thanks for any comments or advice.

Landon
10 years ago
I've been learning about the new enum keyword in Java 5. I'm curious what you can accomplish with the new enum keyword that you coudln't accmoplish before with regular Java objects.

For example, you create an Enum class that does the following:

- Contains a Map that associates String keys with Integer values.
- Contains a private int that contains the "current" value of the Enum in instances of the Enum class.
- Restricts outside access to the Map.
- Only allows keys and values to be set in the class when it is constructed.
- Throws an exception if someone attempts to set an invalid value as the value of an Enum instance.

I've read that enum keyword gives increased type safety in Java, at least compared to using variables in a class definition, but if you used a class like the one I just described I don't think this is the case. You couldn't ever set an incorrect value in the class described above, and methods could be written to accept instances of the class, not raw ints.

I know the guys (and gals) that design the Java programming language are a lot smarter than me. I must be missing some great advantage of the enum keyword. It just seems odd to add that amount of complexity to the language for something that could be acheived with regular classes.

Can someone explain the design logic/advantages of the enum keyword to me?

Thanks,

Landon
10 years ago