Skip to content

[Tutorial 2.3] The CCRE Collections Framework

Colby Skeggs edited this page Nov 11, 2015 · 2 revisions

WARNING: THIS DOCUMENTATION IS FOR CCRE v2, NOT CCRE v3!

See the readme on the main page for the correct documentation.

The CCRE Collections Framework

[Back to the previous tutorial]([Tutorial 2.2] Control Structures - ExpirationTimer, PauseTimer, MultipleSourceBooleanController, Ticker)

The rationale

On the cRIO, the Squawk Virtual Machine lacks many of the modern collections facilities that are available in Java SE 5 and newer.

This means that we either have to use sub-par collections classes throughout the CCRE, or we have to roll our own. We rolled our own.

The ccre.util package contains versions of the core Java SE collection classes written from scratch that are used by the CCRE's core packages. All of the classes provided by the CCRE for this are prefixed with a C.

Note that if you don't care about the cRIO, and only want your code to run on the RoboRIO, you don't need to worry about this and can just use normal Java collections.

Implemented classes:

CCollection
CList
CAbstractList
CArrayList
CArrayUtils
CHashMap
CLinkedList

Differences from Java SE collections

Because of how there's no way to allocate an instance of a specified type of array on the Squawk Virtual Machine, we couldn't implement the normal toArray(T[]) method. To compensate, we have a fillArray(Object[] target) method instead, which returns how many elements didn't fit in the away. (See the Javadoc for details.)

listIterator(), descendingIterator, subList(), clone(), ensureCapacity(), removeRange(), and trimtoSize() are also not supported because they add a noticeable amount of extra implementation.

CAbstractList is vaguely based on AbstractList, but don't expect anything to be the same about them besides the overall purpose.

CArrayList and CLinkedList support taking an array as an argument to the constructor, unlike the Java SE versions.

We merged Arrays and Collections into CArrayUtils, but this provides a very small subset of the overall functionality.

We have HashMap, but not Map or any other implementations.

CLinkedList also doesn't support all of the same accessors as LinkedList.

Future of the Collections framework

Next year, the 2015 software will support REAL Java SE collections, and we will be able to start phasing these custom collections out.

Next: [The Cluck Communication System - Basic Usage]([Tutorial 2.4] The Cluck Communication System - Basic Usage)