Revising my code? (Java List class port)


As an amateur who learned coding with Java I came to Xojo a few months ago.
In Xojo I missed something like the List class in Java together with the possibility of using generic types. So I recently ported the Java List class to Xojo and used Variants/VarTypes to be able to create Lists of different data types and keep the data type consistent throughout a certain List.

Since I am not a pro (and not a native speaker, so I hope I get it right here) I would like to share my code, if someone might be interested to have a look at it and say a few words regarding the code being reasonable or not.

Is this possible in this forum (and how?) or are there other possibilities to get an expert opinion about my code? I would like to add that this is just a hobby without any commercial concerns…

Thanks a lot!

Upload the code to your website or to Dropbox or to GitHub.

Thanks for your reply!

You can download an example project > here .
The project contains the List class as well as a ListNode class, which the List class needs. (I would have liked to implement the ListNode class as an inner class of List, but I did not find a way to do that by now.) In addition to that it contains a few lines of code in the Open event of the Window control to illustrate the usage of the List class…

Thanks for sharing. In the brief bit I’ve looked so far…

Dim StringList As List = New List(5)

You should use an Enumeration here instead of an integer value (which is easy to forget).

Content As Variant

Have you considered Auto? It’s the newer version of Variant but it’s behavior is a bit different in places so maybe Variant works better for this.

If ListNode is to be only used by List then I’ve done this by having ‘List’ do double-duty as both. I needed a Font class which needed an array of a simple Character class. Since Font is the only thing interacting with Character I just moved it’s methods and properties to Font as Private and worked with it carefully.

The bit I’ve seen it looks like you implemented List as a Linked List but the public interface of List is more array like I think, with an iterator. It might be easier code to use an array, then focus on the public interface you want.

Variant is probably the closest equivalent to generic types.

Thanks for your replies! :slight_smile:

I didn’t know about that. I’ll have a look at it.

I liked the possibility of Java’s ArrayList class to access the list like an array, so I added this to my List class, although it’s fully usable as a Linked List, too.
I started to write the class in the first place because I missed the ability to use two-dimensional arrays without losing some functionality of arrays; in addition to that I needed a dynamic data structure (I don’t know if that is the correct term for the german word).
The longer-term goal is to implement and use Lists of Lists (as a kind of dynamic two-dimensional array). The current class is the grundwork, so to say.

EDIT: Enumeration is just what I was looking for when thinking about the Constructor parameter. Thanks! :slight_smile: