xpertss.json.schema.processors.validation.SchemaContextEquivalence Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-schema Show documentation
Show all versions of json-schema Show documentation
A Java implementation of the JSON Schema specification.
The newest version!
package xpertss.json.schema.processors.validation;
import xpertss.json.schema.processors.data.SchemaContext;
import com.google.common.base.Equivalence;
/**
* Equivalence for schema contexts
*
* This is used by {@link ValidationChain} and {@link ValidationProcessor} to
* cache computation results. Two schema contexts are considered equivalent if:
*
*
*
* - schema trees are considered equivalent,
* - and the type of the instance is the same.
*
*
*/
public final class SchemaContextEquivalence extends Equivalence {
private static final Equivalence INSTANCE = new SchemaContextEquivalence();
public static Equivalence getInstance()
{
return INSTANCE;
}
@Override
protected boolean doEquivalent(SchemaContext a, SchemaContext b)
{
return a.getSchema().equals(b.getSchema())
&& a.getInstanceType() == b.getInstanceType();
}
@Override
protected int doHash(SchemaContext t)
{
return t.getSchema().hashCode() ^ t.getInstanceType().hashCode();
}
}