Changeset 5966


Ignore:
Timestamp:
02/26/10 08:17:36 (10 years ago)
Author:
callan
Message:

#466 Cleaned up a couple cases where TreeSet is a useful replacement for Arrays.sort()

Location:
branches/cleanup/components/bio-formats/src/loci/formats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/components/bio-formats/src/loci/formats/gui/AWTTiffTools.java

    r5962 r5966  
    3030import java.io.IOException; 
    3131import java.util.Arrays; 
     32import java.util.TreeSet; 
    3233 
    3334import loci.common.ByteArrayHandle; 
     
    208209    ifd.putIFDValue(IFD.STRIP_BYTE_COUNTS, stripByteCounts); 
    209210 
    210     Object[] keys = ifd.keySet().toArray(); 
    211     Arrays.sort(keys); // sort IFD tags in ascending order 
    212  
    213     int keyCount = keys.length; 
     211    TreeSet<Integer> keys = new TreeSet<Integer>(ifd.keySet()); 
     212 
     213    int keyCount = keys.size(); 
    214214    if (ifd.containsKey(new Integer(IFD.LITTLE_ENDIAN))) keyCount--; 
    215215    if (ifd.containsKey(new Integer(IFD.BIG_TIFF))) keyCount--; 
     
    242242    if (bigTiff) ifdBuf.writeLong(keyCount); 
    243243    else ifdBuf.writeShort(keyCount); 
    244     for (int k=0; k<keys.length; k++) { 
    245       Object key = keys[k]; 
    246       if (!(key instanceof Integer)) { 
    247         throw new FormatException("Malformed IFD tag (" + key + ")"); 
     244    for (Integer key : keys) { 
     245      if (key.equals(IFD.LITTLE_ENDIAN) || key.equals(IFD.BIG_TIFF)) { 
     246        continue; 
    248247      } 
    249       if (((Integer) key).intValue() == IFD.LITTLE_ENDIAN) continue; 
    250       if (((Integer) key).intValue() == IFD.BIG_TIFF) continue; 
    251248      Object value = ifd.get(key); 
    252249      String sk = IFD.getIFDTagName(((Integer) key).intValue()); 
  • branches/cleanup/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r5964 r5966  
    2626import java.io.IOException; 
    2727import java.util.Arrays; 
     28import java.util.TreeSet; 
    2829import java.util.Vector; 
    2930 
     
    317318      TiffConstants.BIG_TIFF_BYTES_PER_ENTRY : TiffConstants.BYTES_PER_ENTRY; 
    318319    int baseOffset = bigTiff ? 8 : 2; 
    319     int threshhold = bigTiff ? 8 : 4; 
    320320 
    321321    for (int i=0; i<numEntries; i++) { 
     
    361361  /** Fill in IFD entries that are stored at an arbitrary offset. */ 
    362362  public void fillInIFD(IFD ifd) throws IOException { 
    363     Vector<TiffIFDEntry> entries = new Vector<TiffIFDEntry>(); 
     363    TreeSet<TiffIFDEntry> entries = new TreeSet<TiffIFDEntry>(); 
    364364    for (Object key : ifd.keySet()) { 
    365365      if (ifd.get(key) instanceof TiffIFDEntry) { 
     
    368368    } 
    369369 
    370     TiffIFDEntry[] e = entries.toArray(new TiffIFDEntry[entries.size()]); 
    371     Arrays.sort(e); 
    372  
    373     for (TiffIFDEntry entry : e) { 
     370    for (TiffIFDEntry entry : entries) { 
    374371      ifd.put(new Integer(entry.getTag()), getIFDValue(entry)); 
    375372    } 
Note: See TracChangeset for help on using the changeset viewer.