com.healthmarketscience.common.util
Class Tuple1<ObjType0>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<Object>
          extended by com.healthmarketscience.common.util.Tuple1<ObjType0>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Object>, Collection<Object>, List<Object>, RandomAccess
Direct Known Subclasses:
Tuple2

public class Tuple1<ObjType0>
extends AbstractList<Object>
implements Serializable, List<Object>, RandomAccess, Cloneable

Simple class for holding a single typed object (useful for returning additional objects from a method call). For convenience, a Tuple can act like an unmodifiable List of Object of a fixed size (the number of elements in the tuple).

Author:
James Ahlborn
See Also:
Serialized Form

Nested Class Summary
protected static class Tuple1.Accessor
          Helper class to enable direct indexed access to the tuple values.
protected static class Tuple1.IterableIterator<Type>
          An Iterable whose iterator method returns itself.
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Tuple1()
          Initializes a new Tuple1 with a null object.
Tuple1(ObjType0 obj)
          Initializes a new Tuple1 with the provided object.
 
Method Summary
 Tuple1<ObjType0> clone()
          Makes a copy of this Tuple1.
static
<InObjType0>
Collection<InObjType0>
collection0(Collection<? extends Tuple1<InObjType0>> col)
          Returns a Collection adapter for element 0 of the Tuples of the given Collection.
static
<InObjType0>
Tuple1<InObjType0>
create(InObjType0 obj0)
          Creates a new Tuple1 with the provided object.
 boolean equals(Object o)
          Indicates whether the given Object is equal to this Tuple1.
 Object[] get()
          Gets the object value of this tuple as an Object array.
 Object get(int index)
          Get the value of this tuple identified by index, which must always be 0, since this tuple class stores exactly one object.
 ObjType0 get0()
          Get the object of this tuple.
 int hashCode()
          Returns a hash code for this Tuple1, based on the object it contains.
static
<InObjType0>
Iterable<InObjType0>
iterable0(Iterable<? extends Tuple1<InObjType0>> iable)
          Returns an Iterable adapter that returns an Iterator that iterates over element 0 of the tuples within the given Iterable/Iterator.
 void set(ObjType0 obj0)
          Sets the value of this tuple.
 void set0(ObjType0 obj)
          Sets the object of this tuple.
 int size()
          Get the size of this tuple, which is always 1.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, subList, toArray, toArray
 

Constructor Detail

Tuple1

public Tuple1()
Initializes a new Tuple1 with a null object.


Tuple1

public Tuple1(ObjType0 obj)
Initializes a new Tuple1 with the provided object. You may want to use create(InObjType0) instead, since it infers the type parameter based on its argument.

Parameters:
obj - the object to store in this Tuple1.
Method Detail

create

public static <InObjType0> Tuple1<InObjType0> create(InObjType0 obj0)
Creates a new Tuple1 with the provided object.

Parameters:
obj0 - the object to store in this Tuple1.
Returns:
a new Tuple1 with the provided object.

iterable0

public static <InObjType0> Iterable<InObjType0> iterable0(Iterable<? extends Tuple1<InObjType0>> iable)
Returns an Iterable adapter that returns an Iterator that iterates over element 0 of the tuples within the given Iterable/Iterator. The returned Iterator supports element removal if the given Iterable supports element removal.

Returns:
an Iterable adapter that returns an Iterator that iterates over element 0 of the Tuples within the given Iterable/Iterator.

collection0

public static <InObjType0> Collection<InObjType0> collection0(Collection<? extends Tuple1<InObjType0>> col)
Returns a Collection adapter for element 0 of the Tuples of the given Collection. The returned Collection supports element removal if the given Collection supports element removal, but does not support element addition.

Returns:
a Collection adapter for element 0 of the Tuples of the given Collection.

get0

public final ObjType0 get0()
Get the object of this tuple.

Returns:
the object of this tuple.

set0

public final void set0(ObjType0 obj)
Sets the object of this tuple.

Parameters:
obj - the object to store in this tuple.

get

public Object[] get()
Gets the object value of this tuple as an Object array.

Returns:
the object value of this tuple as an Object array.

get

public Object get(int index)
Get the value of this tuple identified by index, which must always be 0, since this tuple class stores exactly one object.

Specified by:
get in interface List<Object>
Specified by:
get in class AbstractList<Object>
Parameters:
index - the index of the object to retrieve. Must be 0.
Returns:
the object in this tuple with the given index.

set

public final void set(ObjType0 obj0)
Sets the value of this tuple.

Parameters:
obj0 - the value to store in this tuple.

size

public int size()
Get the size of this tuple, which is always 1.

Specified by:
size in interface Collection<Object>
Specified by:
size in interface List<Object>
Specified by:
size in class AbstractCollection<Object>
Returns:
1

clone

public Tuple1<ObjType0> clone()
Makes a copy of this Tuple1.

Overrides:
clone in class Object
Returns:
a copy of this Tuple1.

equals

public boolean equals(Object o)
Indicates whether the given Object is equal to this Tuple1.

Specified by:
equals in interface Collection<Object>
Specified by:
equals in interface List<Object>
Overrides:
equals in class AbstractList<Object>
Returns:
  • true if the given Object refers to this Tuple1.
  • true if the given Object is an instance of Tuple1 for which the contained object is equal to this Tuple1's object.
  • false otherwise.

  • hashCode

    public int hashCode()
    Returns a hash code for this Tuple1, based on the object it contains.

    Specified by:
    hashCode in interface Collection<Object>
    Specified by:
    hashCode in interface List<Object>
    Overrides:
    hashCode in class AbstractList<Object>
    Returns:
    a hash code for this Tuple1.


    Copyright © 2006-2016 Health Market Science. All Rights Reserved.