public class Tuple extends Object implements Iterable<Object>
A simple Tuple object. Trades strict type safety for flexibility. If you want a type-safe tuple you have to define a specific Tuple class for a 1-tuple, for a 2-tuple, for a 3-tuple ... up to n-tuple. This does not really scale. Most likely your uses will fall into a small enough range you could make a class for each, but this gets most of the joy without having to write lots of classes for each size.
Constructor and Description |
---|
Tuple(boolean theSafe,
Object... theData)
Create a new Tuple
|
Tuple(List<?> theData)
Create a new Tuple
|
Tuple(Object... theData)
Create a new Tuple
|
Modifier and Type | Method and Description |
---|---|
<T> T |
get(int theIndex)
Return the Tuple value at the given index.
|
Iterator<Object> |
iterator() |
int |
length()
Return the length of this tuple.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public Tuple(List<?> theData)
theData
- the tuple datapublic Tuple(Object... theData)
theData
- the tuple datapublic Tuple(boolean theSafe, Object... theData)
theSafe
- true to enable safe mode, false otherwisetheData
- the tuple datapublic <T> T get(int theIndex)
Integer aInt = aTuple.get(2);
Or you can explicitly request the type:
return aTuple.<Boolean>get(0);
This is done by default in "safe" mode. Safe mode will catch the possible ClassCastException and return null
instead. You can disable safe mode to get theT
- the type the return value should betheIndex
- the indexed value of the tuple to retrieveClassCastException
- thrown if you ask for a tuple element with a given type and it cannot be casted to
that value (when safe mode is off).IndexOutOfBoundsException
- if you ask for a tuple element that does not existpublic int length()
Copyright © 2010-2016 Stardog Union. All Rights Reserved.