com.google.gdata.model
Class MetadataContext

java.lang.Object
  extended by com.google.gdata.model.MetadataContext
All Implemented Interfaces:
java.lang.Comparable<MetadataContext>

public final class MetadataContext
extends java.lang.Object
implements java.lang.Comparable<MetadataContext>

A context that metadata is operating under. Currently this contains the alt format, projection and version of the current request. Immutable.

This class also contains static initializers for the transforms required by each of our alt formats, which guarantees they will be loaded. We may want to put them somewhere else, but we need to move the constants for the contexts along with them.


Field Summary
static MetadataContext ATOM
          The ATOM metadata context.
static MetadataContext RSS
          The RSS metadata context.
 
Method Summary
 int compareTo(MetadataContext other)
          Compare two context objects to order them.
 boolean equals(java.lang.Object obj)
          Checks that the other object is a metadata context with the same alt type and version.
static MetadataContext forAlt(AltFormat format)
          Creates a new immutable metadata context with just an alt format.
static MetadataContext forContext(AltFormat format, java.lang.String projection, Version version)
          Creates a new immutable metadata context.
static MetadataContext forProjection(java.lang.String projection)
          Creates a new immutable metadata context with just projection.
static MetadataContext forVersion(Version version)
          Constructs a new immutable metadata context with just version.
 AltFormat getAltFormat()
          The alt format the context represents.
 java.lang.String getProjection()
          The projection the context represents.
 Version getVersion()
          The version the context represents.
 int hashCode()
          The hashCode for a context is just the hashcode of its parts.
 boolean matches(MetadataContext other)
          Returns true if this context is a match for the given context.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ATOM

public static final MetadataContext ATOM
The ATOM metadata context.


RSS

public static final MetadataContext RSS
The RSS metadata context.

Method Detail

forAlt

public static MetadataContext forAlt(AltFormat format)
Creates a new immutable metadata context with just an alt format. The format must not be null or this will throw a null pointer exception.

Parameters:
format - the alt format for the context, not null.
Returns:
a metadata context for the alt format.

forProjection

public static MetadataContext forProjection(java.lang.String projection)
Creates a new immutable metadata context with just projection. If the projection is null this will return null, which is the default context.

Parameters:
projection - the projection of the context.
Returns:
an immutable metadata context with the given projection, or null if the projection was null.

forVersion

public static MetadataContext forVersion(Version version)
Constructs a new immutable metadata context with just version. If version is null this will return null, which is the default context.

Parameters:
version - the version of the context.
Returns:
an immutable metadata context with the given version, or null if the version was null.

forContext

public static MetadataContext forContext(AltFormat format,
                                         java.lang.String projection,
                                         Version version)
Creates a new immutable metadata context. If version, projection and alt type are all null this method will return null, which is the default context.

Parameters:
format - the alt format of the context.
projection - the projection for the context.
version - the version of the context.
Returns:
an immutable metadata context with the given alt type, projection and version, or null if all parameters are null.

matches

public boolean matches(MetadataContext other)
Returns true if this context is a match for the given context. A context is a match for another context if it is a subset of that context. Null properties are ignored, but any properties that are set must match the same property on the other context.


getAltFormat

public AltFormat getAltFormat()
The alt format the context represents.

Returns:
the alt format or null if the context doesn't have an alt format.

getProjection

public java.lang.String getProjection()
The projection the context represents.

Returns:
the projection or null if the context doesn't have a projection.

getVersion

public Version getVersion()
The version the context represents.

Returns:
the version or null if no version exists in this context.

compareTo

public int compareTo(MetadataContext other)
Compare two context objects to order them. A null value for any field is treated as a low value. Otherwise we use the normal string comparison. If the given context object is null a NullPointerException will be thrown.

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

hashCode

public int hashCode()
The hashCode for a context is just the hashcode of its parts.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Checks that the other object is a metadata context with the same alt type and version.

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object