org.openide.util
Class Union2<First,Second>

java.lang.Object
  extended by org.openide.util.Union2<First,Second>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public abstract class Union2<First,Second>
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A union type which can contain one of two kinds of objects. Object.equals(java.lang.Object) and Object.hashCode() treat this as a container, not identical to the contained object, but the identity is based on the contained object. The union is serialiable if its contained object is. Object.toString() delegates to the contained object.

Since:
org.openide.util 7.1
Author:
Jesse Glick
See Also:
Serialized Form

Constructor Summary
Union2()
           
 
Method Summary
abstract  Union2<First,Second> clone()
           
static
<First,Second>
Union2<First,Second>
createFirst(First first)
          Construct a union based on the first type.
static
<First,Second>
Union2<First,Second>
createSecond(Second second)
          Construct a union based on the second type.
abstract  First first()
          Retrieve the union member of the first type.
abstract  boolean hasFirst()
          Check if the union contains the first type.
abstract  boolean hasSecond()
          Check if the union contains the second type.
abstract  Second second()
          Retrieve the union member of the second type.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Union2

Union2()
Method Detail

first

public abstract First first()
                     throws java.lang.IllegalArgumentException
Retrieve the union member of the first type.

Returns:
the object of the first type
Throws:
java.lang.IllegalArgumentException - if the union really contains the second type

second

public abstract Second second()
                       throws java.lang.IllegalArgumentException
Retrieve the union member of the second type.

Returns:
the object of the second type
Throws:
java.lang.IllegalArgumentException - if the union really contains the first type

hasFirst

public abstract boolean hasFirst()
Check if the union contains the first type.

Returns:
true if it contains the first type, false if it contains the second type

hasSecond

public abstract boolean hasSecond()
Check if the union contains the second type.

Returns:
true if it contains the second type, false if it contains the first type

clone

public abstract Union2<First,Second> clone()
Overrides:
clone in class java.lang.Object

createFirst

public static <First,Second> Union2<First,Second> createFirst(First first)
Construct a union based on the first type.

Parameters:
first - an object of the first type
Returns:
a union containing that object

createSecond

public static <First,Second> Union2<First,Second> createSecond(Second second)
Construct a union based on the second type.

Parameters:
second - an object of the second type
Returns:
a union containing that object