org.jitr
Class JitrUtils

java.lang.Object
  extended by org.jitr.JitrUtils

public final class JitrUtils
extends java.lang.Object

Provides various simple utility methods.

Author:
Josh Devins (info@joshdevins.net)

Method Summary
static java.util.Collection<java.lang.reflect.Field> getAnnotatedDeclaredFields(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
          Finds any declared fields in the given class with the given annotation.
static java.lang.reflect.Field getMostSpecificAnnotatedDeclaredField(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
          Finds an annotated field amongst a hierarchy of classes.
static int getRandomUnusedPort()
          Provides a quick way to get a random, unused port by opening a ServerSocket and getting the locally assigned port for the server socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAnnotatedDeclaredFields

public static java.util.Collection<java.lang.reflect.Field> getAnnotatedDeclaredFields(java.lang.Class<?> clazz,
                                                                                       java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Finds any declared fields in the given class with the given annotation.


getMostSpecificAnnotatedDeclaredField

public static java.lang.reflect.Field getMostSpecificAnnotatedDeclaredField(java.lang.Class<?> clazz,
                                                                            java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Finds an annotated field amongst a hierarchy of classes. Should multiple classes in the hierarchy have a field with the same annotation, the field from the most specific or lowest subclass is used.

Throws:
JitrException - When multiple annotated fields are found in any one class.

getRandomUnusedPort

public static int getRandomUnusedPort()
                               throws JitrException
Provides a quick way to get a random, unused port by opening a ServerSocket and getting the locally assigned port for the server socket.

Returns:
A random, unused port.
Throws:
JitrException - Thrown if any IOExceptions are thrown by the underlying calls to ServerSocket.


Copyright © 2009. All Rights Reserved.