Java

Find Matching Ints Using Regex

If you are following along you may have noticed that I have been compiling a long list of soutions to my Find Duplicate Ints problem. I was talking to one of my co-workers, who is not a developer but used to do some Perl hacking, and he suggested that it could be done with regular expressions. Lo and behold, with the help of another of my more regular-expression-ized co-workers we found this to be true:

public int findDuplicate(final int[] array){
    final Pattern p = Pattern.compile(".*?(\\d+. ).*?\\1.*");
No votes yet

Rendering Calendars

I am poking around with an idea I had to generate desktop background images with little calendars embedded in them and I realized that there is no really easy (existing) method of rendering your standard square text calendar display. I decided to play around with it a bit.

The basic algorithm to generate the weeks and their associated days is nothing too complicated:

  1. Figure out what day of the week the first day of the month falls on
No votes yet

Quick String Padding

I stumbled on a quick little way to create string padding of various lengths:

private static String padding(final int size, final char val){
    final char[] pad = new char[size];
    Arrays.fill(pad, val);
    return new String(pad);
}
No votes yet

Recursive Solution to Finding Ints Question

Back in my posting of “Interview Question: Find 2 Matching Ints” I showed a few different solutions to the problem. A candidate we had recently suggested solving it via recursion; I decided to whip up a little recursive solution for my collection:

public static int find(int[] array){
    return scan(new HashSet<Integer>(),array,0);
}

private static int scan(Set<Integer> values, int[] array, int idx){
    if(idx == array.length){
        throw new IllegalArgumentException("No match exists");
No votes yet

Spring: Deserialized Object Factory

I recently had the idea that it would be interesting to have a Spring factory bean that would load a serialized object as its object contribution. I have no idea at this point what it would be useful for; it was just something that popped into my head. My example below describes a license key system that is not based on anything real so please don’t expect this to be a good license key implementation… it’s just an example of the deserialized bean factory idea.

No votes yet

Fun With Robot: Screen Wrapping

I was poking through the JavaDocs last night and came across a few classes that I had never played with before, java.awt.Robot and java.awt.MouseInfo so I decided to have a little fun. Have you ever wanted your mouse to be able to wrap around the edge of the screen? No, well me neither, but I thought it would be fun to implement:

public class WrapIt {

    public static void main(String[] args){
        final Robot robot = new Robot();
        final Rectangle screen = new Rectangle(new Point(0,0),Toolkit.getDefaultToolkit().getScreenSize());
No votes yet

Interesting Way to Hide Behind Interfaces

While working on one of my projects I stumbled on an interesting way to code to interfaces even when the “factory” class is in a different package than the interface and implementation. Say you have an interface, IBar in a package called app.manager:

package app.manager;

public interface IBar {
    String getValue();
}

and an implementation of the interface in the same package, called Bar:

package app.manager;

public class Bar implements IBar {

    private String value;
No votes yet

Perforce Frills Screenshot

I spent some time working on my EclipseFrills Perforce plug-in last night. I have the “dump changelist to string” function working and I have the “shelve changes” function working for the most part. Now I need to have a way to see the shelved changes and then to “un-shelve” them.

No votes yet

First Negative Thing I Have Said About Spring

I love the SpringFramework. I have been using it for a few years now and it is one of the most useful and rich projects for both utility and functionality that I have come across, and I rarely… well, never have anything bad to say about it until now.

No votes yet

Bubble Sort

I did some more comparative programming around Bubble Sort recently which I decided to post here, to both save it for myself and share with others. This time rather than posting multiple entries (one for each language) I have decided to throw them all in the same pot.

No votes yet