org.hd.d.pg2k.svrCore
Class ExhibitStaticAttr

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.ExhibitStaticAttr
All Implemented Interfaces:
java.io.ObjectInputValidation, java.io.Serializable, java.lang.Comparable<ExhibitStaticAttr>

public final class ExhibitStaticAttr
extends java.lang.Object
implements java.lang.Comparable<ExhibitStaticAttr>, java.io.Serializable, java.io.ObjectInputValidation

Immutable, Serializable collection of the basic static attributes of an exhibit. This is designed to be fast to do comparisons against, and to be transportable across a network, persistable to disc, and easy to run filtering queries against.

This verifies that its contents make sense at construction and after deserialisation.

This is keyed on the exhibit underlying name, but should be easy to use with other comparators.

The timestamp can be used to compare that the version of the object held is up-to-date.

Some core values are made available as public final fields for speed of access.

Note: an older implementation used String for its filePath field; this is converted on deserialisation now.

See Also:
Serialized Form

Field Summary
private  Name.ExhibitFull filePath
          The full (relative) path/name of the exhibit; never null.
 long length
          The length of the exhibit in bytes; strictly positive.
private static long serialVersionUID
          Unique serialisation ID.
 long timestamp
          The Java-style timestamp (last-modified-time) of the exhibit (ms); strictly positive.
 
Constructor Summary
  ExhibitStaticAttr(java.lang.CharSequence filePath, long length, long timestamp)
          Construct new immutable instance.
private ExhibitStaticAttr(Name.ExhibitFull filePath)
          Used by makeNameOnlyKey() to make a name-only key efficiently.
  ExhibitStaticAttr(Name.ExhibitFull filePath, long length, long timestamp)
          Construct new immutable instance.
 
Method Summary
 int compareTo(ExhibitStaticAttr o)
          Comparison/ordering is on the exhibit name alone.
 boolean equals(java.lang.Object o)
          All comparison is done on the name only, NOT on all fields.
 java.lang.CharSequence getCharSequence()
          Get the file path (full exhibit name) as an immutable CharSequence; never null.
 Name.ExhibitFull getExhibitFullName()
          Get the full exhibit name; never null.
 java.lang.String getFilePath()
          Get the file path (full exhibit name) as a String; never null.
 java.lang.Comparable<?> getKey()
          Extract compound key that depends on all the fields; never null.
 int hashCode()
          All comparison is done on the name.
 boolean isIdentical(ExhibitStaticAttr other)
          Tests that instances are identical in all parameters.
static ExhibitStaticAttr makeNameOnlyKey(java.lang.CharSequence filePath)
          Generate a lookup key with just the name significant; never null.
static ExhibitStaticAttr makeNameOnlyKey(Name.ExhibitFull filePath)
          Generate a lookup key with just the name significant; never null.
private  void readObject(java.io.ObjectInputStream in)
          Deserialise.
 java.lang.String toString()
          Human-readable summary contains at least the name; never null.
 void validateObject()
          Validate fields/state.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

filePath

private final Name.ExhibitFull filePath
The full (relative) path/name of the exhibit; never null. Must be unique and acceptable to ExhibitName.

All run-time instances will have the same type, except possibly fleetingly during (de)serialisation.

The field type was CharSequence to allow reading in of old String-valued instances but is now converted at deserialistion time to Name.ExhibitFull if not already so.


length

public final long length
The length of the exhibit in bytes; strictly positive.


timestamp

public final long timestamp
The Java-style timestamp (last-modified-time) of the exhibit (ms); strictly positive. This must be valid Gallery timestamp which means not before the Gallery was created and not too far into the future allowing for clock skew...


serialVersionUID

private static final long serialVersionUID
Unique serialisation ID.

See Also:
Constant Field Values
Constructor Detail

ExhibitStaticAttr

public ExhibitStaticAttr(java.lang.CharSequence filePath,
                         long length,
                         long timestamp)
                  throws java.lang.IllegalArgumentException
Construct new immutable instance. Try to force sharing of the potentially large and numerous paths/names to avoid memory bloat, even though this costs some time.

Throws:
java.lang.IllegalArgumentException - in the case of a null or invalid filePath

ExhibitStaticAttr

public ExhibitStaticAttr(Name.ExhibitFull filePath,
                         long length,
                         long timestamp)
                  throws java.lang.IllegalArgumentException
Construct new immutable instance. Case where argument is of the preferred (Name.ExhibitFull) type.

Throws:
java.lang.IllegalArgumentException - in the case of a null or invalid filePath

ExhibitStaticAttr

private ExhibitStaticAttr(Name.ExhibitFull filePath)
Used by makeNameOnlyKey() to make a name-only key efficiently. Skips some checking but will still ensure that only a valid instance is created.

Parameters:
filePath - must be non-null
Method Detail

hashCode

public final int hashCode()
All comparison is done on the name. Relies on hash of underlying data type, assuming all run-time filePath instances will have same type.

Overrides:
hashCode in class java.lang.Object

equals

public final boolean equals(java.lang.Object o)
All comparison is done on the name only, NOT on all fields.

Overrides:
equals in class java.lang.Object

getFilePath

public java.lang.String getFilePath()
Get the file path (full exhibit name) as a String; never null. This operation may be expensive and slow; use getExhibitFullName() or getCharSequence() if an actual String is not required.


getExhibitFullName

public Name.ExhibitFull getExhibitFullName()
Get the full exhibit name; never null.


getCharSequence

public java.lang.CharSequence getCharSequence()
Get the file path (full exhibit name) as an immutable CharSequence; never null. This avoids any possible expensive value conversion for callers that don't care about the exact representation.


toString

public java.lang.String toString()
Human-readable summary contains at least the name; never null.

Overrides:
toString in class java.lang.Object

compareTo

public final int compareTo(ExhibitStaticAttr o)
Comparison/ordering is on the exhibit name alone.

Specified by:
compareTo in interface java.lang.Comparable<ExhibitStaticAttr>

isIdentical

public final boolean isIdentical(ExhibitStaticAttr other)
Tests that instances are identical in all parameters.


getKey

public java.lang.Comparable<?> getKey()
Extract compound key that depends on all the fields; never null. Suitable for hashed and sorted collections.


makeNameOnlyKey

public static ExhibitStaticAttr makeNameOnlyKey(Name.ExhibitFull filePath)
Generate a lookup key with just the name significant; never null.

Throws:
java.lang.IllegalArgumentException - in the case of a null filePath

makeNameOnlyKey

public static ExhibitStaticAttr makeNameOnlyKey(java.lang.CharSequence filePath)
Generate a lookup key with just the name significant; never null.

Throws:
java.lang.IllegalArgumentException - in the case of a null or invalid filePath

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Deserialise. Yucky use of reflection to set final field values: see http://jeremymanson.blogspot.com/2008/07/immutability-in-java-part-3.html

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

validateObject

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

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

DHD Multimedia Gallery V1.60.69

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