com.github.fge.jsonschema.core.tree.key
Class SchemaKey

java.lang.Object
  extended by com.github.fge.jsonschema.core.tree.key.SchemaKey
Direct Known Subclasses:
AnonymousSchemaKey, JsonRefSchemaKey

@ParametersAreNonnullByDefault
public abstract class SchemaKey
extends Object

Base class for a schema identifier, or "key"

This package offers two ways to load a schema: either directly (that is, from a JsonNode) or via a URI. The implementation considers that schemas loaded via the first mechanism are anonymous (that is, they have no associated URI).

Depending on which of the two ways above you use, a SchemaTree will be identified either by an AnonymousSchemaKey (using anonymousKey()) or a JsonRefSchemaKey (using forJsonRef(JsonRef)).


Field Summary
protected  JsonRef loadingRef
           
 
Constructor Summary
protected SchemaKey(JsonRef loadingRef)
           
 
Method Summary
static SchemaKey anonymousKey()
          Generate an anonymous key for a SchemaTree
abstract  boolean equals(Object obj)
           
static SchemaKey forJsonRef(JsonRef ref)
          Generate a key for a schema loaded from a JSON Reference
abstract  long getId()
          Get the identifier, as a long, for this schema -- DO NOT USE DIRECTLY
 JsonRef getLoadingRef()
          Get the loading URI (as a JSON Reference) for that key
abstract  int hashCode()
           
abstract  String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

loadingRef

protected final JsonRef loadingRef
Constructor Detail

SchemaKey

protected SchemaKey(JsonRef loadingRef)
Method Detail

anonymousKey

public static SchemaKey anonymousKey()
Generate an anonymous key for a SchemaTree

The key is uniquely identified by a long identifier; values are picked from an AtomicLong.

Note: this means that two identical JSON Schemas loaded anonymously at different points in time (or different threads) will not be considered equal.

Returns:
a unique key for this schema

forJsonRef

public static SchemaKey forJsonRef(@Untainted
                                   JsonRef ref)
Generate a key for a schema loaded from a JSON Reference

Parameters:
ref - the JSON Reference
Returns:
the unique key for this schema
See Also:
URIDownloader

getId

public abstract long getId()
Get the identifier, as a long, for this schema -- DO NOT USE DIRECTLY

Important: this method is here only for backwards compatibility reasons (see SchemaTree.getId()); you should not be using it as a reliable identifier, since for all non anonymous schema keys (ie, instances of JsonRefSchemaKey), this will return 0L.

Returns:
see description

getLoadingRef

public final JsonRef getLoadingRef()
Get the loading URI (as a JSON Reference) for that key

Important: this method only works reliably for non anonymous schemas; for anonymous schemas, it will always return JsonRef.emptyRef(). As such, you should not use it directly.

Returns:
the JSON Reference used to load the schema (see description)

hashCode

public abstract int hashCode()
Overrides:
hashCode in class Object

equals

public abstract boolean equals(@Nullable
                               Object obj)
Overrides:
equals in class Object

toString

@Nonnull
public abstract String toString()
Overrides:
toString in class Object