net
Class LatestURL

java.lang.Object
  extended by net.LatestURL
All Implemented Interfaces:
Initializable
Direct Known Subclasses:
DateIncludingURL

public class LatestURL
extends Object
implements Initializable

A class that reads a remote directory from an URL and returns the latest file reference that fits the filter. For single acces, one can use the statis last(java.net.URL) methods, for repetetive access, it is advisable to construct a new object and call the update() method.


Nested Class Summary
static class LatestURL.Dump
          Dump an url-content to system-out.
protected static class LatestURL.URLTime
          A class that enhances an url for the modification time.
 
Field Summary
private  FileFilter accept
          The file filter.
private  URL base
          The base URL.
private  Collection<URL> cache
          The collection of all refences matching the filter retrieved lately.
private  LatestURL.URLTime latest
          The youngest URL from the current cache.
 
Constructor Summary
LatestURL(URL dir)
          Constructs an new latest url object.
LatestURL(URL dir, FileFilter filter)
          Constructs an new latest url object.
 
Method Summary
protected  LatestURL.URLTime deduceYoungest(Collection<URL> cc)
          The base class only uses the modification time of the url.
private static Set<URL> getFilteredReferences(URL dir, FileFilter pass)
          Returns all references from the base url in a set.
 URL getLatest()
          Returns the last url-reference strored in the latest field.
protected static long getModificationTime(URL ref)
          Opens a connection to the specified URL and returns the time-stamp of the modification time.
private static LatestURL.URLTime getYoungest(Collection<URL> filtered)
          Takes a collection of filtered references and returns the newest one.
 void init()
          This stupid splitting is just becaus super must always be first.
static URL last(URL dir)
          Retrieves all references, passes them through the filter and returns the url with the most actual date from the remaining list.
static URL last(URL dir, FileFilter pass)
          Retrieves all references, passes them through the filter and returns the url with the most actual date from the remaining list.
 String toString()
          Returns the string representation of the latest url.
 URL update()
          Updates the reference cache and checks if we have to re-do evaluation of the youngest neighbour.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

base

private URL base
The base URL.


accept

private FileFilter accept
The file filter.


cache

private Collection<URL> cache
The collection of all refences matching the filter retrieved lately.


latest

private LatestURL.URLTime latest
The youngest URL from the current cache.

Constructor Detail

LatestURL

public LatestURL(URL dir)
Constructs an new latest url object. On construct, we retrieve the filtered references found and store them in a cache. Further calls to update() first check, if new references had been added to or removed from the base url and acts only on the changes.


LatestURL

public LatestURL(URL dir,
                 FileFilter filter)
Constructs an new latest url object. On construct, we retrieve the filtered references found and store them in a cache. Further calls to update() first check, if new references had been added to or removed from the base url and acts only on the changes.

Method Detail

init

public void init()
This stupid splitting is just becaus super must always be first.

Specified by:
init in interface Initializable

last

public static URL last(URL dir)
Retrieves all references, passes them through the filter and returns the url with the most actual date from the remaining list.


update

public URL update()
Updates the reference cache and checks if we have to re-do evaluation of the youngest neighbour. The youngest URL found is returned.


getLatest

public URL getLatest()
Returns the last url-reference strored in the latest field.


toString

public String toString()
Returns the string representation of the latest url.

Overrides:
toString in class Object

last

public static URL last(URL dir,
                       FileFilter pass)
Retrieves all references, passes them through the filter and returns the url with the most actual date from the remaining list.


getFilteredReferences

private static Set<URL> getFilteredReferences(URL dir,
                                              FileFilter pass)
Returns all references from the base url in a set.


deduceYoungest

protected LatestURL.URLTime deduceYoungest(Collection<URL> cc)
The base class only uses the modification time of the url.


getYoungest

private static LatestURL.URLTime getYoungest(Collection<URL> filtered)
Takes a collection of filtered references and returns the newest one. This requires that a connection is made to each reference to retrieve the modification time, which can be slow.


getModificationTime

protected static long getModificationTime(URL ref)
                                   throws IOException
Opens a connection to the specified URL and returns the time-stamp of the modification time.

Throws:
IOException