org.hd.d.pg2k.svrCore
Class ExhibitThumbnails

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.ExhibitThumbnails
All Implemented Interfaces:
java.io.ObjectInputValidation, java.io.Serializable

public final class ExhibitThumbnails
extends java.lang.Object
implements java.io.Serializable, java.io.ObjectInputValidation

Immutable, Serializable thumbnails/samples of an exhibit. This is designed to be transportable across a network if need be, and persistable to disc, and reasonably efficient when serialised.

This holds a standard and a small thumbnail (of a static image) or equivalent sample of an exhibit for other exhibit types, or an indication that such a sample is not needed because the original can be used, or an indication that such a sample could not be made (eg failed and should not be rebuilt).

Exhibit thumbnails/samples are strictly limited in size to minimise the space they consume in toto and the time that they take to send across the network to clients. The small thumbnails are meant to be small enough that they can be permanently held in memory at the servers and are lightning-fast to transfer to client (while not so small as to simple dwarfed by network overheads).

(All thumbnails/samples must be smaller than the original exhibit.)

Any sample is of the same MIME type as the original.

An example of when an exhibit could be used as its own thumbnail is when its size in bytes is less than the appropriate limit, and the (x,y) dimensions are no greater than the appropriate limits, then no thumbnail is required and the image can be used directly.

This is made to implement equals() and hashCode() so that comparisons for equality, eg in a Set, can be performed. Two objects are equal if their constituent thumbnails are equal. The hash is computed from those of the thumbnails.

See Also:
Serialized Form

Nested Class Summary
static class ExhibitThumbnails.Thumbnail
          Immutable, Serializable single thumbnail (standard or small).
 
Field Summary
 long created
          Creation timestamp (positive), or zero if none.
static int MAX_BYTES_EST
          Crude estimate of maximum bytes consumed in memory and on disc by thumbnails; ignores VM and serialisation details, etc.
static ExhibitThumbnails NO_THUMBNAILS
          Value indicating that no thumbnails could be made for an exhibit.
private static long serialVersionUID
          My initial version number.
private  ExhibitThumbnails.Thumbnail sml
          Small thumbnail; null means none can be constructed.
static short SML_ABS_MAX_BYTES
          Absolute maximum size of any small thumbnail/sample binary in bytes (4kB-1).
static int SML_STATIC_IMAGE_TN_LDIM_PX
          For a small static image thumbnail, its longest dimension in pixels.
private  ExhibitThumbnails.Thumbnail std
          Standard thumbnail; null means none can be constructed.
static short STD_ABS_MAX_BYTES
          Absolute maximum size of any standard thumbnail/sample binary in bytes (32kB-1).
static int STD_STATIC_IMAGE_TN_LDIM_PX
          For a standard static image thumbnail, its longest dimension in pixels.
 
Constructor Summary
private ExhibitThumbnails(ExhibitThumbnails.Thumbnail small, ExhibitThumbnails.Thumbnail standard)
          Construct from a pair of thumbnails.
 
Method Summary
static java.awt.Dimension computeThumbnailDimensions(java.awt.Dimension original, boolean std)
          Given the original dimensions of an image, compute the size of the standard/small thumbnail.
static ExhibitThumbnails createExhibitThumbnails(ExhibitThumbnails.Thumbnail small, ExhibitThumbnails.Thumbnail standard)
          Make a pair of thumbnails.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 ExhibitThumbnails.Thumbnail getSmall()
          Get small thumbnail; null means none can be constructed.
 ExhibitThumbnails.Thumbnail getStandard()
          Get standard thumbnail; null means none can be constructed.
 int hashCode()
          Returns a hash code value for the object.
static boolean isEmpty(ExhibitThumbnails tns)
          Returns true if its argument is null or contains no thumbnails.
private  void readObject(java.io.ObjectInputStream in)
          Deserialise.
protected  java.lang.Object readResolve()
          Eliminate duplicate empty objects after deserialisation.
 java.lang.String toString()
          Human-readable summary.
 void validateObject()
          Validate fields/state.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_THUMBNAILS

public static final ExhibitThumbnails NO_THUMBNAILS
Value indicating that no thumbnails could be made for an exhibit. This non-null value positively indicates that there are no thumbnails.

This value is a singleton.


sml

private final ExhibitThumbnails.Thumbnail sml
Small thumbnail; null means none can be constructed.


std

private final ExhibitThumbnails.Thumbnail std
Standard thumbnail; null means none can be constructed.


created

public final long created
Creation timestamp (positive), or zero if none.


STD_ABS_MAX_BYTES

public static final short STD_ABS_MAX_BYTES
Absolute maximum size of any standard thumbnail/sample binary in bytes (32kB-1). Should be small enough to download reasonably quickly, but may be too large to cache in memory.

This value is small enough to store in a short.

See Also:
Constant Field Values

SML_ABS_MAX_BYTES

public static final short SML_ABS_MAX_BYTES
Absolute maximum size of any small thumbnail/sample binary in bytes (4kB-1). Should be very fast to download, even over a WAN connection, and small enough to cache all exhibits' small thumbnails in memory if required.

This value is small enough to store in a short.

See Also:
Constant Field Values

STD_STATIC_IMAGE_TN_LDIM_PX

public static final int STD_STATIC_IMAGE_TN_LDIM_PX
For a standard static image thumbnail, its longest dimension in pixels. Normally the longest dimension will be exactly this in pixels, but it may be smaller.

See Also:
Constant Field Values

SML_STATIC_IMAGE_TN_LDIM_PX

public static final int SML_STATIC_IMAGE_TN_LDIM_PX
For a small static image thumbnail, its longest dimension in pixels. Normally the longest dimension will be exactly this in pixels, but it may be smaller.

See Also:
Constant Field Values

MAX_BYTES_EST

public static final int MAX_BYTES_EST
Crude estimate of maximum bytes consumed in memory and on disc by thumbnails; ignores VM and serialisation details, etc.

See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
My initial version number.

See Also:
Constant Field Values
Constructor Detail

ExhibitThumbnails

private ExhibitThumbnails(ExhibitThumbnails.Thumbnail small,
                          ExhibitThumbnails.Thumbnail standard)
Construct from a pair of thumbnails. Either can be null or non-null, but if both are non-null small.size() must not be greater than standard.size().

The timestamp is always zero if both thumbnails are.

Method Detail

isEmpty

public static boolean isEmpty(ExhibitThumbnails tns)
Returns true if its argument is null or contains no thumbnails.


getSmall

public ExhibitThumbnails.Thumbnail getSmall()
Get small thumbnail; null means none can be constructed.


getStandard

public ExhibitThumbnails.Thumbnail getStandard()
Get standard thumbnail; null means none can be constructed.


hashCode

public int hashCode()
Returns a hash code value for the object. This is based on the hashes of the constituent thumbnails.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. For this the constituent thumbnails must be "equal", and it means that iff one of the thumbnails is missing in one of the objects then it must be missing in the other too.

Equality ignores the creation timestamp.

Overrides:
equals in class java.lang.Object

computeThumbnailDimensions

public static java.awt.Dimension computeThumbnailDimensions(java.awt.Dimension original,
                                                            boolean std)
Given the original dimensions of an image, compute the size of the standard/small thumbnail. The argument must be non-null and the width and height strictly positive.

If the longest dimension of the original image is no more than {STD|SML}_STATIC_IMAGE_TN_LDIM_PX pixels then the input dimensions will be returned unaltered, else the values are scaled so that the longest dimension is exactly {STD|SML}_STATIC_IMAGE_TN_LDIM_PX pixels.

Parameters:
std - if true, compute for standard, else compute for small

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Deserialise.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

readResolve

protected java.lang.Object readResolve()
Eliminate duplicate empty objects after deserialisation.


validateObject

public void validateObject()
                    throws java.io.InvalidObjectException
Validate fields/state. Called in the constructor and possibly after deserialising.

Barf if something bad is found. (Maybe allow some extra info in debug version.)

Specified by:
validateObject in interface java.io.ObjectInputValidation
Throws:
java.io.InvalidObjectException

createExhibitThumbnails

public static ExhibitThumbnails createExhibitThumbnails(ExhibitThumbnails.Thumbnail small,
                                                        ExhibitThumbnails.Thumbnail standard)
Make a pair of thumbnails. Either can be null or non-null, but if both are non-null small.size() must not be greater than standard.size(), and both must be within their respective size limits.


toString

public java.lang.String toString()
Human-readable summary.

Overrides:
toString in class java.lang.Object

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.