org.hd.d.pg2k.svrCore.location
Class LocationMap

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.location.LocationMap
All Implemented Interfaces:
java.io.Serializable

public final class LocationMap
extends java.lang.Object
implements java.io.Serializable

Holds a prefix-based lookup map from name to Location. Is immutable.

FIXME: needs proper serialisation support such as read/write/validation.

See Also:
Serialized Form

Field Summary
private static java.lang.String locAliasKeyPrefix
          Location alias key prefix for properties (containing trailing dot).
private static boolean LOCAREA_PREFIX_CASE_SENSITIVE
          Are location area prefixes case-sensitive?
private static java.lang.String locKeyPrefix
          Location key prefix for properties (containing trailing dot).
private  MemoryTools.SimpleLRUMapAutoSizeForHitRate<Name,Location.Base> lookupCache
          Private LRU lookup cache from full name or prefix to location; never null.
private  java.util.Map<Location.Base,Name> mapFromLocationToNamePrefix
          Immutable reverse map from Location to prefix (as Name); may remove some duplicates.
private  java.util.Map<Name,Location.Base> mapFromNamePrefixToLocation
          Immutable Map from Name prefix to Location.Base; never null.
static java.lang.String PNAME_REVERSE_LOOKUP_MINWORDS
          Property name for minimum words to match for a reverse lookup.
static java.lang.String PNAME_REVERSE_LOOKUP_SECTION
          Property name for section to do reverse lookups in.
private  int revLookupMinWords
          Minimum number of words matched for reverse matches, or non-positive if none.
private  Name revLookupSection
          Reverse section used for reverse matches, or null if none.
private static long serialVersionUID
          Serialisation UID.
 long timestamp
          Timestamp passed in constructor; never negative.
 
Constructor Summary
LocationMap()
          Empty, immutable, zero-timestamp, lookup map.
LocationMap(java.util.Properties p, long timestamp)
          Constructed from non-null Properties containing auxInfo data.
 
Method Summary
private static Location.Base _locLookup(java.util.Map<Name,Location.Base> nameToLoc, Name.ExhibitFull exhibitName, java.util.Set<java.lang.String> allAttrWords, Name revLookupSection, int revLookupMinWords, MemoryTools.SimpleLRUMapAutoSizeForHitRate<Name,Location.Base> cache)
          Lookup of Location by prefix/suffix in given Map; never null.
private static java.util.Map<Name,Location.Base> buildMap(java.util.Properties rawProperties)
          Build the basic map from prefix (as Name) to Location; never null.
 boolean equals(java.lang.Object obj)
          Two LocationMaps are equal if the underlying maps are.
 java.util.Map<Location.Base,Name> getMapFromLocationToNamePrefix()
          Get immutable reverse map from Location.Base to "virtual" prefix (as Name); never null.
 java.util.Map<Name,Location.Base> getMapFromNamePrefixToLocation()
          Get immutable map from "virtual" prefix to Location.Base (as Name); never null.
 int hashCode()
          Hash code is that of the underlying map and zero if empty.
 boolean isEmpty()
          Returns true if the map is completely empty, eg as built by the default constructor.
 Location.Base locLookup(Name.ExhibitFull exhibitName, java.util.Set<java.lang.String> allAttrWords)
          Lookup of Location by prefix; never null.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCAREA_PREFIX_CASE_SENSITIVE

private static final boolean LOCAREA_PREFIX_CASE_SENSITIVE
Are location area prefixes case-sensitive?

See Also:
Constant Field Values

locKeyPrefix

private static final java.lang.String locKeyPrefix
Location key prefix for properties (containing trailing dot).

See Also:
Constant Field Values

locAliasKeyPrefix

private static final java.lang.String locAliasKeyPrefix
Location alias key prefix for properties (containing trailing dot).

See Also:
Constant Field Values

timestamp

public final long timestamp
Timestamp passed in constructor; never negative. Guaranteed zero if the map is empty.


mapFromNamePrefixToLocation

private final java.util.Map<Name,Location.Base> mapFromNamePrefixToLocation
Immutable Map from Name prefix to Location.Base; never null. Map from "virtual" exhibit name (prefix) to Location object so that we can reuse previously generated objects. The exhibit name key consists of the top-level section/directory and some leading portion of the name; no intermediate directories are stored.

A HashMap is preferred for speed.


revLookupSection

private final Name revLookupSection
Reverse section used for reverse matches, or null if none.


revLookupMinWords

private final int revLookupMinWords
Minimum number of words matched for reverse matches, or non-positive if none.


mapFromLocationToNamePrefix

private final transient java.util.Map<Location.Base,Name> mapFromLocationToNamePrefix
Immutable reverse map from Location to prefix (as Name); may remove some duplicates. Must be reconstructed after deserialisation.


PNAME_REVERSE_LOOKUP_SECTION

public static final java.lang.String PNAME_REVERSE_LOOKUP_SECTION
Property name for section to do reverse lookups in.

See Also:
Constant Field Values

PNAME_REVERSE_LOOKUP_MINWORDS

public static final java.lang.String PNAME_REVERSE_LOOKUP_MINWORDS
Property name for minimum words to match for a reverse lookup.

See Also:
Constant Field Values

lookupCache

private final transient MemoryTools.SimpleLRUMapAutoSizeForHitRate<Name,Location.Base> lookupCache
Private LRU lookup cache from full name or prefix to location; never null. Thread-safe and sized in proportion to the size of our main map, allowing for lots of negative lookups too.

Not part of the serialised state of the object.

Results are filed against keys that are both:


serialVersionUID

private static final long serialVersionUID
Serialisation UID.

See Also:
Constant Field Values
Constructor Detail

LocationMap

public LocationMap()
Empty, immutable, zero-timestamp, lookup map.


LocationMap

public LocationMap(java.util.Properties p,
                   long timestamp)
Constructed from non-null Properties containing auxInfo data.

Method Detail

equals

public boolean equals(java.lang.Object obj)
Two LocationMaps are equal if the underlying maps are.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Hash code is that of the underlying map and zero if empty.

Overrides:
hashCode in class java.lang.Object

getMapFromNamePrefixToLocation

public java.util.Map<Name,Location.Base> getMapFromNamePrefixToLocation()
Get immutable map from "virtual" prefix to Location.Base (as Name); never null. We return the internal immutable map.


getMapFromLocationToNamePrefix

public java.util.Map<Location.Base,Name> getMapFromLocationToNamePrefix()
Get immutable reverse map from Location.Base to "virtual" prefix (as Name); never null. We return the internal immutable map.

Note that Location values have to be intern()ed or must compare exactly for equality for this map to be of use.


buildMap

private static java.util.Map<Name,Location.Base> buildMap(java.util.Properties rawProperties)
Build the basic map from prefix (as Name) to Location; never null. The result may be mutable.

Parameters:
rawProperties - properties to extract the data from; never null

locLookup

public Location.Base locLookup(Name.ExhibitFull exhibitName,
                               java.util.Set<java.lang.String> allAttrWords)
Lookup of Location by prefix; never null. Returns Location.NONE if nothing found, never null.

Parameters:
exhibitName - name of exhibit to look up; not null
allAttrWords - attribute words; not null

_locLookup

private static Location.Base _locLookup(java.util.Map<Name,Location.Base> nameToLoc,
                                        Name.ExhibitFull exhibitName,
                                        java.util.Set<java.lang.String> allAttrWords,
                                        Name revLookupSection,
                                        int revLookupMinWords,
                                        MemoryTools.SimpleLRUMapAutoSizeForHitRate<Name,Location.Base> cache)
Lookup of Location by prefix/suffix in given Map; never null. Returns Location.NONE if nothing found, never null.

Parameters:
exhibitName - full name of exhibit to look up; not null
allAttrWords - set of all attribute words (if empty, canonical-key entries are not used); never null
cache - writable auto-sizing cache map from full or prefix of exhibit name to location

isEmpty

public boolean isEmpty()
Returns true if the map is completely empty, eg as built by the default constructor.


DHD Multimedia Gallery V1.57.21

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