Changeset 6005 for branches/cleanup


Ignore:
Timestamp:
03/09/10 07:56:49 (10 years ago)
Author:
callan
Message:

#466 Moved common enumeration classes to loci.common.enumeration and added test cases and exception type for enumeration lookups by code that fail.

Location:
branches/cleanup/components
Files:
4 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/IFDType.java

    r5964 r6005  
    2727import java.util.Map; 
    2828 
    29 import loci.common.CodedEnum; 
     29import loci.common.enumeration.CodedEnum; 
     30import loci.common.enumeration.EnumException; 
    3031 
    3132/** 
     
    7879   * <code>null</code> if it does not exist. 
    7980   */ 
    80   public static IFDType get(int code) {  
    81     return lookup.get(code);  
     81  public static IFDType get(int code) { 
     82    IFDType toReturn = lookup.get(code); 
     83    if (toReturn == null) { 
     84      throw new EnumException("Unable to find IFDType with code: " + code); 
     85    } 
     86    return toReturn; 
    8287  } 
    8388 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/PhotoInterp.java

    r5970 r6005  
    2828import java.util.Map; 
    2929 
    30 import loci.common.CodedEnum; 
     30import loci.common.enumeration.CodedEnum; 
     31import loci.common.enumeration.EnumException; 
    3132 
    3233/** 
     
    100101   * <code>code</code> or <code>null</code> if it does not exist. 
    101102   */ 
    102   public static PhotoInterp get(int code) {  
    103     return lookup.get(code); 
    104     //throw new FormatException("Unknown PhotometricInterpretation (" + 
    105     //    photoInterp + ")"); 
     103  public static PhotoInterp get(int code) { 
     104    PhotoInterp toReturn = lookup.get(code); 
     105    if (toReturn == null) { 
     106      throw new EnumException("Unable to find PhotoInterp with code: " + code); 
     107    } 
     108    return toReturn; 
    106109  } 
    107110 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/TiffCompression.java

    r5990 r6005  
    2929import java.util.Map; 
    3030 
    31 import loci.common.CodedEnum; 
    3231import loci.common.DataTools; 
     32import loci.common.enumeration.CodedEnum; 
     33import loci.common.enumeration.EnumException; 
    3334import loci.formats.FormatException; 
    3435import loci.formats.codec.Codec; 
     
    139140   */ 
    140141  public static TiffCompression get(int code) { 
    141     return lookup.get(code); 
     142    TiffCompression toReturn = lookup.get(code); 
     143    if (toReturn == null) { 
     144      throw new EnumException( 
     145          "Unable to find TiffCompresssion with code: " + code); 
     146    } 
     147    return toReturn; 
    142148  } 
    143149 
  • branches/cleanup/components/bio-formats/test/loci/formats/utests/tiff/PhotoInterpTest.java

    r6003 r6005  
    2727import org.testng.annotations.Test; 
    2828 
     29import loci.common.enumeration.EnumException; 
    2930import loci.formats.tiff.PhotoInterp; 
    3031 
     
    4445    assertEquals(PhotoInterp.BLACK_IS_ZERO, pi); 
    4546  } 
     47   
     48  @Test(expectedExceptions={ EnumException.class }) 
     49  public void testUnknownCode() { 
     50    PhotoInterp.get(-1); 
     51  } 
    4652} 
  • branches/cleanup/components/common/src/loci/common/enumeration/CodedEnum.java

    r5957 r6005  
    2121Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    2222*/ 
    23 package loci.common; 
     23package loci.common.enumeration; 
    2424 
    2525/** 
     
    2727 * 
    2828 * <dl><dt><b>Source code:</b></dt> 
    29  * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/common/src/loci/common/CodedEnum.java">Trac</a>, 
    30  * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/common/src/loci/common/CodedEnum.java">SVN</a></dd></dl> 
     29 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/common/src/loci/common/enumeration/CodedEnum.java">Trac</a>, 
     30 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/common/src/loci/common/enumeration/CodedEnum.java">SVN</a></dd></dl> 
    3131 */ 
    3232public interface CodedEnum { 
Note: See TracChangeset for help on using the changeset viewer.