net.sf.staccatocommons.lang.tuple
Class AbstractTuple

java.lang.Object
  extended by net.sf.staccatocommons.lang.tuple.AbstractTuple
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Pair, Quadruple, Triple

@Value
@Conditionally(value={net.sf.staccatocommons.restrictions.value.Immutable.class,java.io.Serializable.class})
public abstract class AbstractTuple
extends Object
implements Serializable

A AbstractTuple is a fixed size sequence of heterogeneous objects. They are ConditionallyImmutable and ConditionallySerializable . They are comparable, as long as they components are, too.

Tuples are aimed to be used in those situations where an object that just relates others together is needed. Such object does not encapsulate any business concept nor any specific behavior except of Object.toString(), Object.equals(Object), Object.hashCode() and Comparable#compareTo(Object, Object). Tuples are thus not intended to be used everywhere nor extended, but there are some concrete scenarios where they are useful:

Although it is possible to create tuples of arities from 2 to 4 invoking the appropriate constructor, the recommended way of instantiating tuples is using the family of class methods in Tuples named _. Although it looks odd at first glance, combining it with static imports produces quite clean code. For example, using again the divMod method:
  import static net.sf.staccatocommons.lang.tuple._;
  
  ...
  Tuple2<Integer, Integer> divMod(int x, int y)
   return _(x/y, x%y)
  ...
 
 

Author:
flbulgarelli
See Also:
Tuple2, Tuple3, Quadruple, Serialized Form

Nested Class Summary
protected static class AbstractTuple.TupleState<A>
           
 
Method Summary
abstract  Object[] toArray()
          Converts this tuple into an array
 List<Object> toList()
          Gets an unmodifiable list containing each components of this tuple as elements
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toArray

@NonNull
public abstract Object[] toArray()
Converts this tuple into an array

Returns:
an new Object[] containing each of the elements of this tuple

toList

@NonNull
public List<Object> toList()
Gets an unmodifiable list containing each components of this tuple as elements

Returns:
a non null, unmodifiable list


Copyright © 2010-2012 Staccatocommons. All Rights Reserved.