org.jaitools.imageutils
Class ImageSet<K>

java.lang.Object
  extended by org.jaitools.imageutils.ImageSet<K>
Type Parameters:
K -

public class ImageSet<K>
extends Object

Author:
michael

Nested Class Summary
static class ImageSet.Element
          An ImageSet element consisting of a RenderedImage and an associated outside value.
static class ImageSet.Iterator<K>
           
 
Constructor Summary
ImageSet()
          Creates a new, empty image set.
 
Method Summary
 void add(K key, RenderedImage image, Number outsideValue)
          Adds an image to this set to be associated with the given key.
 void clear()
          Removes all key:image pairs from this image set.
 boolean containsImage(RenderedImage image)
          Tests if this image set contains the given image.
 boolean containsKey(K key)
          Tests if this image set contains the given key.
static
<K> ImageSet<K>
copy(ImageSet<K> set)
          Creates a new image set which will contain the same keys, images and outside values as the input set.
 RenderedImage get(K key)
          Retrieves an image from this set.
 Rectangle getBounds(K key)
          Gets the bounds of the image associated with the given key.
 Rectangle getIntersectionBounds()
          Gets the common bounds of images in this set This is the intersection of the individual iamge bounds.
 ImageSet.Iterator<K> getIterator()
          Gets a new iterator based on the bounds of the first image added to this set or, if that has been removed, the image that has been in this set for the longest period.
 ImageSet.Iterator<K> getIterator(K referenceImageKey)
          Gets a new iterator based on the bounds of the image with the specified key value.
 ImageSet.Iterator<K> getIterator(Rectangle bounds)
          Gets a new iterator based on the bounds of the image with the specified key value.
 Number getOutsideValue(K key)
          Gets the value that an image set iterator will return for the image associated with the given key when it is positioned outside the bounds of that image.
 Rectangle getUnionBounds()
          Gets the enclosing bounds of all images in this set.
 boolean isEmpty()
          Tests if this image set is empty.
 Set<K> keySet()
          Retrieves a Set view of the keys in this image set.
 void putAll(ImageSet<? extends K> otherSet)
          Copies all key:image pairs from otherSet into this image set.
 RenderedImage remove(K key)
          Removes a key:image pair from this set.
 int size()
          Gets the number of key:image pairs in this set.
 Set<RenderedImage> values()
          Retrieves a Set view of the keys in this image set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageSet

public ImageSet()
Creates a new, empty image set.

Method Detail

copy

public static <K> ImageSet<K> copy(ImageSet<K> set)
Creates a new image set which will contain the same keys, images and outside values as the input set. If the input set is null or empty, an empty image set is created.

Type Parameters:
K - the key type
Parameters:
set - the image set to copy
Returns:
the new copy

add

public void add(K key,
                RenderedImage image,
                Number outsideValue)
Adds an image to this set to be associated with the given key.

Parameters:
key - the key
image - the image
outsideValue - the value to be returned by iterators when positions beyond the bounds of this image (may be null
Throws:
IllegalArgumentException - if either key or image is null

size

public int size()
Gets the number of key:image pairs in this set. Note that a single image may be mapped to more than one key.

Returns:
the number of key:image pairs

isEmpty

public boolean isEmpty()
Tests if this image set is empty.

Returns:
true if the set is empty

containsKey

public boolean containsKey(K key)
Tests if this image set contains the given key.

Parameters:
key - the key to search for
Returns:
true if the key is found; false otherwise
Throws:
IllegalArgumentException - if key is null

containsImage

public boolean containsImage(RenderedImage image)
Tests if this image set contains the given image. Note that the test is merely for reference equality.

Parameters:
image - the image to search for
Returns:
true is the image is in this set; false otherwise

get

public RenderedImage get(K key)
Retrieves an image from this set.

Parameters:
key - the key associated with the image.
Returns:
the image or null if the key could not be found

remove

public RenderedImage remove(K key)
Removes a key:image pair from this set.

Parameters:
key - the key
Returns:
the image associated with the key or null if the key could not be found

putAll

public void putAll(ImageSet<? extends K> otherSet)
Copies all key:image pairs from otherSet into this image set.

Parameters:
otherSet - the image set to take contents from
Throws:
IllegalArgumentException - if otherSet is null

clear

public void clear()
Removes all key:image pairs from this image set.


keySet

public Set<K> keySet()
Retrieves a Set view of the keys in this image set. Note that unlike Java collection classes, this method returns an unmodifiable view of the keys.

Returns:
keys contained in this image set

values

public Set<RenderedImage> values()
Retrieves a Set view of the keys in this image set. Note that unlike Java collection classes, this method returns an unmodifiable view of the keys.

Returns:
keys contained in this image set

getIterator

public ImageSet.Iterator<K> getIterator()
Gets a new iterator based on the bounds of the first image added to this set or, if that has been removed, the image that has been in this set for the longest period.

Returns:
the new iterator
Throws:
IllegalArgumentException - if this image set is empty

getIterator

public ImageSet.Iterator<K> getIterator(K referenceImageKey)
Gets a new iterator based on the bounds of the image with the specified key value.

Parameters:
referenceImageKey - the key of the image to use as the reference for the iterator
Returns:
the new iterator
Throws:
IllegalArgumentException - if this image set is empty or if no image corresponds to the key value

getIterator

public ImageSet.Iterator<K> getIterator(Rectangle bounds)
Gets a new iterator based on the bounds of the image with the specified key value.

Parameters:
bounds - iterator bounds
Returns:
the new iterator
Throws:
IllegalArgumentException - if this image set is empty or if no image corresponds to the key value

getBounds

public Rectangle getBounds(K key)
Gets the bounds of the image associated with the given key.

Parameters:
key - the image key
Returns:
image bounds as a new Rectangle or null if the key could not be found

getUnionBounds

public Rectangle getUnionBounds()
Gets the enclosing bounds of all images in this set. This is the union of the individual image bounds. If the set is empty an empty Rectangle will be returned.

Returns:
enclosing bounds for this image set

getIntersectionBounds

public Rectangle getIntersectionBounds()
Gets the common bounds of images in this set This is the intersection of the individual iamge bounds. An empty Rectangle will be returned if ths set is empty, or if there is no area over which all images overlap.

Returns:
common bounds for this image set

getOutsideValue

public Number getOutsideValue(K key)
Gets the value that an image set iterator will return for the image associated with the given key when it is positioned outside the bounds of that image.

Parameters:
key - the key
Returns:
the value returned for out-of-bounds value requests (may be null)


Copyright © 2009-2013. All Rights Reserved.