Gary W. Lucas

Ranch Hand
+ Follow
since Jun 25, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
12
In last 30 days
0
Total given
0
Likes
Total received
20
Received in last 30 days
0
Total given
21
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gary W. Lucas

Thanks for the quick  reply.

Incidentally, your "Create an Uber Clone in 7 Days" book looks pretty interesting.   I plan on checking it out in the near future.

Gary
7 months ago
Do you have any advice on using your book as part of a training effort? My company is putting a fair bit of effort into bringing our new hires up to speed on programming in general and Java in particular.

I am sometimes surprised when ideas that I would consider just basic information, or even self evident, turn out to be something that newbies just don't fully understand. I figure that's just me making unreasonable assumptions.   Just yesterday, I had a discussion about the different between addressing files with a relative path versus an absolute path.  It would have been nice to be able to recommend some reading to back up my explanations (since clearly explaining basics is not an area in which I am particularly adept). Can you book be used as a way supporting concepts as well as practice?

Thanks.  And good luck on your promotion efforts.

Gary
7 months ago
Thanks.   With regard to isolating AWT, I think it makes sense.
11 months ago
Does anyone have recommendations on including AWT classes in a project that might someday be ported to Android?  Is that still a problem? The project does not include a UI, but it does use geometry operations and I am working on some imaging support.

I have an open source project that deals with numerical raster data.  Currently, it uses only three classes from java.awt:   AffineTransform, Rectangle2D, and Color.  In the future, I may add more graphic-related operations.  I am thinking that I might separate AWT related stuff into its own package and maintain the core classes as AWT free.  Is this necessary?

I have one issue in that it will be hard to get rid of the AffineTransform. I only use a subset of the operations from AffineTransform and could write my own class easily enough.  But just because you can do something, doesn’t necessarily make it a good idea.  So I would like to get insights from developers who may have experience with porting code to Android.

Thanks in advance for your help.

Gary

P.S. To read more about the project, please visit https://github.com/gwlucastrig/gridfour
11 months ago
You already have the tool you need in terms of the area computation.  I would move the computation into your constructor.   If the area is very close to zero, then you have a degenerate triangle.

Note that the area computation can be positive or negative depending on whether the three vertices specify the triangle boundary in clockwise or counterclockwise order.  So your test would have to include the absolute value method....   Perhaps you could do something like the following (the threshold value 1.0e-9is arbitrary):



1 year ago
Thanks.  CompleteableFuture does look promising.  I've needed that kind of functionality more than once.  I've always coded it "by hand".
1 year ago
Ben, Jason, and Martijn,

The Manning page cites concurrency as one of the topics you cover in your book.  I use multi-threading all the time, but I haven't really followed new developments since Java 1.5.  Is there any newer concurrency feature that you would recommend as especially interesting or useful?

Good luck on your new edition!  It looks like it has a lot of interesting material.  I am particularly looking forward to seeing what you have to say about the JVM in containers (something I am finding challenging).

Gary
1 year ago
As I recall from dusty memories, "to grok" means "to drink".

But, yes, it means to have established a fully internalized, visceral understanding of an idea or a person.  It's from Heinlein's "Stranger in a Strange Land".
1 year ago
As Campbell Ritchie points out, your code example could throw a null pointer exception if one of the strings in your test data set (i.e. "word") happened to be null.

    if(word.equals(target))


One common way to defend against that is to change the order of comparison statements

     if(target.equals(word))

In such a case you could test once at the top of the code to see if target was null and exit early if it is.  The String.equals() method is robust enough to handle a null argument.

That's why you'll often see code that tests for string constants given as

    if("some string".equals(word))  

rather than

  if(word.equals("some string"))


1 year ago
There are lots of ways to do this, but I tend to go with the Java TextLayout class.  The following code draws a number centered in a rectangle.
It uses the text layout to get the rectangular bounds from a TextLayout.  The bounds is based on the idea that the coordinate for the approximate left side of the character is zero and the baseline of the character is also zero.   So the value of the getY() method for the rectangle will be a negative value roughly equal to the height of the letter.

For aesthetic purposes, some characters are allowed to be rendered slightly below the baseline.  The curve for zero, for example goes slightly below the baseline.



One less than wonderful thing about this approach is that the center of a numeric digit might not be quite what you expect.  In the output image, note that the center of the numeral 1 for a sans serif font is not through the main vertical.


1 year ago
I am pleased to announce a new release of the Gridfour free open-source software library. Gridfour provides a set of Java software tools intended to assist in the storage and production of raster data.

The new release, version 1.0.2, adds new utilities and fleshes out a number of API elements. But the feature that may be of most interest to Java developers is that it implements a multi-threaded approach for performing data compression and decompression operations. In our tests with large geophysical data sets, the new multi-threaded options shaved off about 40 percent of the runtime for writing and reading persistent data sets.

If you would like to find out more about the Gridfour project, please visit our wiki pages or our  main repository on Github. The new multi-threaded implementations are described at our Multi-Threading wiki page and project Javadoc is available at the Core 1.0.2 API overview.

Finally, a word of thanks…  Over the years, I’ve gotten a lot of help and useful advice from folks at the Code Ranch. And a fair bit of what I learned here found its way into my work on the Gridfour project. So thank you for all of that.  I wish you well in all of your endeavors.

Gary
1 year ago
Thanks.  Worked like a charm.



1 year ago
I am trying to write an image that features characters like z-bar (z with a bar over it to indicate a mean value).  I've found the unicode value for a bar glyph, but the only way I can get it to combine with a letter is by plotting the two characters in the same location using multiple calls.  Is there a way to combine these into a single string?  Or, did I simply miss something like there being a standard glyph that combines these features?

Here's my sample code


And here's he result (the first line was generated using the "noJoy" text layout, the second line by drawing in the same place twice).

1 year ago
Thanks.  That worked like a charm.  I'm really glad I posted this question.

I'm running under Java 8, which doesn't support the Map.to() method you used. So I had to code it out explicitly.  I also decided to use a subscript of (i,j) rather than zero just to exercise the feature...  The letters i and j came out too close together, so I embedded the unicode characters for "half-wide spaces" \u2009.  



1 year ago
Thanks!   I was so focused on making attributes work that it didn't occur to me to look for an different character.

I adjusted the code to use the string  "x\u2080+2w".   I kept the font attribute to make the zero be a little smaller than the rest of the text.   And I also made the plus sign have a bold attribute so that it wasn't quite so thin.   It worked out pretty well.

Funny thing about the subscript characters in Unicode.  I visited the link you gave me.  They had numerals, plus and minute signs, and parentheses. But they didn't have commas.  That seems like such a strange thing to omit.  




1 year ago