p2ps.imp.discovery
Class MemoryDiscoveryCache

java.lang.Object
  extended byp2ps.imp.discovery.MemoryDiscoveryCache
All Implemented Interfaces:
DiscoveryCache

public class MemoryDiscoveryCache
extends java.lang.Object
implements DiscoveryCache

A memory cache of advertisements and queries. Methods are provided to query the cached advertisements and queries.

Version:
$Revision: 295 $
Author:
Ian Wang

Constructor Summary
MemoryDiscoveryCache()
           
 
Method Summary
 void cache(Advertisement advert)
          Adds an advertisement/query to the cache
 boolean contains(java.lang.String advertid)
           
 Advertisement get(java.lang.String advertid)
           
 int getAdvertisementCount()
           
 Advertisement[] getAdvertisementIds()
           
 Advertisement[] getAdvertisements()
           
 Advertisement[] getAdvertisements(Query query)
           
 Query[] getQueries()
           
 Query[] getQueries(Advertisement advert)
           
 int getQueryCount()
           
 Query[] getQueryIds()
           
static boolean isMatch(Query query, Advertisement advert)
           
 boolean isQuery(Advertisement advert)
           
 void remove(java.lang.String advertid)
          Removes an advertisement/query from the cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryDiscoveryCache

public MemoryDiscoveryCache()
Method Detail

isQuery

public boolean isQuery(Advertisement advert)
Specified by:
isQuery in interface DiscoveryCache
Returns:
true if the specified advert is a query

cache

public void cache(Advertisement advert)
Adds an advertisement/query to the cache

Specified by:
cache in interface DiscoveryCache

remove

public void remove(java.lang.String advertid)
Removes an advertisement/query from the cache

Specified by:
remove in interface DiscoveryCache

get

public Advertisement get(java.lang.String advertid)
Specified by:
get in interface DiscoveryCache
Returns:
the advertisement/query with the specified id

contains

public boolean contains(java.lang.String advertid)
Specified by:
contains in interface DiscoveryCache
Returns:
true if the cache contains an advert with the specified id

getAdvertisementIds

public Advertisement[] getAdvertisementIds()
Specified by:
getAdvertisementIds in interface DiscoveryCache
Returns:
an array of the all advertisement ids (including queries) in the cahce

getAdvertisements

public Advertisement[] getAdvertisements()
Specified by:
getAdvertisements in interface DiscoveryCache
Returns:
an array of the all advertisements (including queries) in the cache

getAdvertisementCount

public int getAdvertisementCount()
Specified by:
getAdvertisementCount in interface DiscoveryCache
Returns:
the number of advertisements in the cache

getQueryIds

public Query[] getQueryIds()
Specified by:
getQueryIds in interface DiscoveryCache
Returns:
an array of the query ids in the cache

getQueries

public Query[] getQueries()
Specified by:
getQueries in interface DiscoveryCache
Returns:
an array of the queries in the cache

getAdvertisements

public Advertisement[] getAdvertisements(Query query)
Specified by:
getAdvertisements in interface DiscoveryCache
Returns:
an array of the advertisements that match the specified query

getQueries

public Query[] getQueries(Advertisement advert)
Specified by:
getQueries in interface DiscoveryCache
Returns:
an array of the queries that would match the specified advertisement

getQueryCount

public int getQueryCount()
Specified by:
getQueryCount in interface DiscoveryCache
Returns:
the number of queries in the cache

isMatch

public static boolean isMatch(Query query,
                              Advertisement advert)
Returns:
true if the advert matches the query according to the P2PS query naming conventions.