com.atlassian.bamboo.util
Class Narrow

java.lang.Object
  extended by com.atlassian.bamboo.util.Narrow

public class Narrow
extends java.lang.Object

Utility for narrowing object instances to Class types See to(Object, Class)

Since:
2.7

Method Summary
static
<X,T extends X>
T
downTo(X o, java.lang.Class<T> aClass)
          Should be used for casting down the hierarchy of classes.
static
<X,T extends X>
java.lang.Iterable<T>
iterableDownTo(java.lang.Iterable<X> iterable, java.lang.Class<T> aClass)
          Filters given Iterable returning only these objects which could be narrowed to given type.
static
<T> java.lang.Iterable<T>
iterableTo(java.lang.Iterable<?> iterable, java.lang.Class<T> aClass)
          Filters given Iterable returning only these objects which could be narrowed to given type
static
<T> T
reinterpret(java.lang.Object o, java.lang.Class<T> aClass)
          Narrows the given Object to the type of the Class.
static
<T> T
to(java.lang.Object o, java.lang.Class<T> aClass)
          Narrows the given Object to the type of the Class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reinterpret

@Nullable
public static <T> T reinterpret(@Nullable
                                         java.lang.Object o,
                                         @NotNull
                                         java.lang.Class<T> aClass)
Narrows the given Object to the type of the Class. Using $downTo(Object, Class) is always preferred over using this method. If object cannot be narrowed to the given type this method returns null This is a non-throwing form of Class.cast(Object)

Type Parameters:
T - the type to be narrowed to
Parameters:
o - the object to be narrowed. This object can be a null reference
aClass - the class to narrow to
Returns:
narrowed object

to

@Nullable
public static <T> T to(@Nullable
                                java.lang.Object o,
                                @NotNull
                                java.lang.Class<T> aClass)
Narrows the given Object to the type of the Class. Using $downTo(Object, Class) is always preferred over using this method. If object cannot be narrowed to the given type this method returns null This is a non-throwing form of Class.cast(Object)

Type Parameters:
T - the type to be narrowed to
Parameters:
o - the object to be narrowed. This object can be a null reference
aClass - the class to narrow to
Returns:
narrowed object

downTo

@Nullable
public static <X,T extends X> T downTo(@Nullable
                                                X o,
                                                @NotNull
                                                java.lang.Class<T> aClass)
Should be used for casting down the hierarchy of classes. See to(Object, Class).


iterableTo

public static <T> java.lang.Iterable<T> iterableTo(@NotNull
                                                   java.lang.Iterable<?> iterable,
                                                   @NotNull
                                                   java.lang.Class<T> aClass)
Filters given Iterable returning only these objects which could be narrowed to given type

Type Parameters:
T -
Parameters:
iterable - input iterable containing elements to filter
aClass - class used to narrow elements of iterable
Returns:
filtered iterable with non-null elements narrowed to aClass

iterableDownTo

public static <X,T extends X> java.lang.Iterable<T> iterableDownTo(@NotNull
                                                                   java.lang.Iterable<X> iterable,
                                                                   @NotNull
                                                                   java.lang.Class<T> aClass)
Filters given Iterable returning only these objects which could be narrowed to given type. This version is more typesafe that iterableTo(Iterable, Class) and should be used when casting down the class structure. (e.g. List -> Iterable)

Parameters:
iterable - input iterable containing elements to filter
aClass - class used to narrow elements of iterable
Returns:
filtered iterable with non-null elements narrowed to aClass


Copyright © 2013 Atlassian Software Systems Pty Ltd. All Rights Reserved.